Détail du package

@gerhobbelt/markdown-it-hashtag

svbergerem5MIT0.4.0-1

hashtag for markdown-it markdown parser.

markdown-it-plugin, markdown-it, markdown, hashtag

readme

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

changelog

0.4.0

  • Use markdown-it 5

0.3.1

  • When words recur only render those that are hashtags and have the correct preceding characters

0.3.0

  • Use markdown-it 4

0.2.3

  • When words recur only render those that are hashtags

0.2.2

  • Move the class attribute to the end
  • Escape html in the tag
  • Bump markdown-it

0.2.1

  • Update files in /dist

0.2.0

  • Rewrite to prevent hashtags being rendered inside of link texts
  • Add more specs

0.1.0

  • Initial release