markdown-it-hashtag

0.4.0 • Public • Published

markdown-it-hashtag

Build Status Coverage Status npm version

hashtag (#tag) plugin for markdown-it markdown parser.

#hashtag => <a href="/tags/hashtag" class="tag">#hashtag</a>

Install

node.js, bower:

npm install markdown-it-hashtag --save
bower install markdown-it-hashtag --save

Use

Basic

var md = require('markdown-it')()
            .use(require('markdown-it-hashtag'));
 
md.render('#hashtag'); // => '<p><a href="/tags/hashtag" class="tag">#hashtag</a></p>'

Differences in browser. If you load the script directly into the page, without package system, module will add itself globally as window.markdownitHashtag.

Advanced

You can specify the RegExp for hashtags and specify the allowed preceding content. You can also modify the output of the renderer. Here is an example with default values:

var md = require('markdown-it')()
            .use(require('markdown-it-hashtag'),{
              // pattern for hashtags with normal string escape rules
              hashtagRegExp: '\\w+',
              // pattern for allowed preceding content
              preceding:     '^|\\s'
            });
 
md.renderer.rules.hashtag_open  = function(tokens, idx) {
  var tagName = tokens[idx].content.toLowerCase(); 
  return '<a href="/tags/' + tagName + '" class="tag">';
}
 
md.renderer.rules.hashtag_text  = function(tokens, idx) {
  return '#' + tokens[idx].content;
}
 
md.renderer.rules.hashtag_close = function { return '</a>'; }
 
md.render('#hashtag')// => '<p><a href="/tags/hashtag" class="tag">#hashtag</a></p>'

License

MIT

Package Sidebar

Install

npm i markdown-it-hashtag

Weekly Downloads

349

Version

0.4.0

License

MIT

Last publish

Collaborators

  • svbergerem