Skip to content
Inline tokens iterator for markdown-it markdown parser
JavaScript Makefile
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist Browser files rebuild May 5, 2015
test First commit Dec 29, 2014
.eslintignore First commit Dec 29, 2014
.eslintrc First commit Dec 29, 2014
.gitignore First commit Dec 29, 2014
.npmignore First commit Dec 29, 2014
.travis.yml travis-ci: update node version Nov 3, 2017
CHANGELOG.md 0.1.1 released May 5, 2015
LICENSE
Makefile First commit Dec 29, 2014
README.md Updated examples for markdown-it 4.+ Mar 12, 2015
bower.json First commit Dec 29, 2014
index.js index.js: typo Nov 2, 2017
package.json 0.1.1 released May 5, 2015

README.md

markdown-it-for-inline

Build Status NPM version Coverage Status

Inline tokens iterator for markdown-it markdown parser.

This plugin allows to apply function to certain types of inline tokens. Speed will be not fastest of possible, but you can do quick prototyping of certain rule types.

Usage

Install

node.js, browser:

npm install markdown-it-for-inline --save
bower install markdown-it-for-inline --save

Use

var iterator = require('markdown-it-for-inline');

// plugin params are:
//
// - rule name (should be unique)
// - token type to apply
// - function
//
var md = require('markdown-it')()
            .use(iterator, 'foo_replace', 'text', function (tokens, idx) {
              tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar');
            });

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

Example 2. Cut link prefixes

var iterator = require('markdown-it-for-inline');

var md = require('markdown-it')({ linkify: true })
            .use(iterator, 'url_beautify', 'link_open', function (tokens, idx) {
              // Make sure link contains only text
              if ((tokens[idx + 2].type !== 'link_close') ||
                  (tokens[idx + 1].type !== 'text')) {
                return;
              }
              // Do replacement
              tokens[idx + 1].content = tokens[idx + 1].content
                                          .replace(/^https?:\/\//, '')
                                          .replace(/^www./, '');
            });

Example 3. Make links open in new window

var iterator = require('markdown-it-for-inline');

var md = require('markdown-it')({ linkify: true })
            .use(iterator, 'url_new_win', 'link_open', function (tokens, idx) {
              tokens[idx].attrPush([ 'target', '_blank' ]);
            });

License

MIT

You can’t perform that action at this time.