npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

remark-altprot

v1.1.0

Published

A remark alternate protocols plugin.

Downloads

28

Readme

remark-altprot

A remark alternate protocols plugin.

remark plugin to identify alternate protocol links in paragraphs and convert them to links.

Install

npm install remark-altprot

Use

Check out test.js for more samples

So you have some Markdown in example.md

# Here's some great links

This link hyper://6946d4631ea3dade5d26367b96afdf8e93be638349c536e0bd446393c78a61a4/ blah blah.  Also a data link dat://6946d4631ea3dade5d26367b96afdf8e93be638349c536e0bd446393c78a61a4

Oh and have you been to cabal public? cabal://1eef9ad64e284691b7c6f6310e39204b5f92765e36102046caaa6a7ff8c02d74/ Download the app!

And the script

var remark = require('remark')
var markdown = require('remark-parse')
var altProt = require('remark-altprot')
var html = require('rehype-stringify')
var remark2rehype = require('remark-rehype')
var vfile = require('to-vfile')

 remark().use(markdown).use(altProt).use(remark2rehype).use(html).process(vfile.readSync('example.md'), function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

In the example we are generating html which will return this result:

<h1>Here's some great links</h1>
<p>This link <a href="hyper://6946d4631ea3dade5d26367b96afdf8e93be638349c536e0bd446393c78a61a4/">hyper://6946d4631ea3dade5d26367b96afdf8e93be638349c536e0bd446393c78a61a4/</a> blah blah.  Also a data link <a href="dat://6946d4631ea3dade5d26367b96afdf8e93be638349c536e0bd446393c78a61a4">dat://6946d4631ea3dade5d26367b96afdf8e93be638349c536e0bd446393c78a61a4</a></p>
<p>Oh and have you been to cabal public? <a href="cabal://1eef9ad64e284691b7c6f6310e39204b5f92765e36102046caaa6a7ff8c02d74/">cabal://1eef9ad64e284691b7c6f6310e39204b5f92765e36102046caaa6a7ff8c02d74/</a> Download the app!</p>    

Use with remark-react

There's a trick to using this with remark-react because it uses github sanitize to ensure that generated html is safe. You have to add the protocols you want supported in react to the sanitize feature of remark-react and please, don't set it to false!

Here's all you need to do:

var merge = require('deepmerge')
var gh = require('hast-util-sanitize/lib/github')

const altProtSanitize = {
  sanitize: merge(gh, { protocols: { href: ['hyper', 'dat', 'cabal', 'hypergraph', 'hypermerge'] } })
}

remark().use(altProt).use(remarkReact, altProtSanitize).use(remarkEmoji).processSync(message.content).result

All your doing here is using the hast-util-sanitize github sanitization rules which is also default for remark-react and adding additional protocols to the rules by merging the additional protocols into the rule-set. Finally pass those updated rules as an option in the .use() remarkReact call!