hashtag (
#tag
) plugin for markdown-it markdown parser.
#hashtag
=> <a href="/tags/hashtag" class="tag">#hashtag</a>
node.js, bower:
npm install markdown-it-hashtag --save
bower install markdown-it-hashtag --save
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
.
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>'