Skip to content

Commit

Permalink
Merge pull request #28 from mshick/master
Browse files Browse the repository at this point in the history
support passing options to markdown-it plugins
  • Loading branch information
Celso Miranda committed Dec 13, 2015
2 parents dadb32b + c740511 commit d5b61e2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ module.exports = function (data, options) {

if (opt.plugins) {
parser = opt.plugins.reduce(function (parser, pugs) {
return parser.use(require(pugs));
if (pugs instanceof Object && pugs.name) {
return parser.use(require(pugs.name), pugs.options);
} else {
return parser.use(require(pugs));
}
}, parser);
}

Expand Down
27 changes: 27 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,33 @@ describe('Hexo Renderer Markdown-it', function () {
result.should.equal(parsed_plugins);
});

it('should render a plugin defined as an object', function () {
var parsed_plugins = fs.readFileSync('./test/fixtures/outputs/plugins.html', 'utf8');
var ctx = {
config: {
markdown: {
render: {
html: false,
xhtmlOut: false,
breaks: false,
langPrefix: 'language-',
linkify: false,
typographer: false,
quotes: '«»“”'
},
plugins: ['markdown-it-footnote', 'markdown-it-sub', 'markdown-it-sup', 'markdown-it-ins', { name: 'markdown-it-abbr' }]
}
}
};
var source = fs.readFileSync('./test/fixtures/markdownit.md', 'utf8');
var parse = render.bind(ctx);
var result = parse({
text: source
});
ctx = {};
result.should.equal(parsed_plugins);
});

it('should render anchor-headers if they are defined', function () {
var anchors_with_permalinks = fs.readFileSync('./test/fixtures/outputs/anchors.html', 'utf8');
var ctx = {
Expand Down

0 comments on commit d5b61e2

Please sign in to comment.