Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from mattly/proxy-parser
Browse files Browse the repository at this point in the history
Provide a proxy to functions on the parser
  • Loading branch information
mayo committed Dec 9, 2015
2 parents 044913d + c928a11 commit 43c6a6a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.js]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.editorconfig
15 changes: 15 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ function plugin(preset, options){

plugin.parser = markdown;

/* proxy parser methods to return plugin for inline use */

['use', 'set', 'enable', 'disable'].forEach(function(fn){
plugin[fn] = function(){
var args = Array.prototype.slice.call(arguments);
markdown[fn].apply(markdown, args);
return plugin;
}
});

plugin.withParser = function(fn){
fn(markdown);
return plugin;
}

return plugin;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "metalsmith-markdownit",
"description": "A Metalsmith plugin to convert markdown files.",
"repository": "git://github.com/mayo/metalsmith-markdownit.git",
"version": "0.1.3",
"version": "0.2.0",
"license": "MIT",
"main": "lib/index.js",
"dependencies": {
Expand Down
25 changes: 21 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ describe('metalsmith-markdown', function(){

it('should give access to markdown parser', function(done){
var md = markdown('zero');

md.parser.enable('emphasis');

Metalsmith('test/fixtures/parser')
Expand All @@ -59,13 +58,31 @@ describe('metalsmith-markdown', function(){
});
});

it('should be able to use a plugin', function(done){
var md = markdown('default');
it('should expose the markdown parser via proxy', function(done){
Metalsmith('test/fixtures/parser')
.use(markdown('zero').enable('emphasis'))
.build(function(err){
if (err) return done(err);
equal('test/fixtures/parser/expected', 'test/fixtures/parser/build');
done();
});
});

it('should use plugins via the direct parser', function(done){
var md = markdown('default');
md.parser.use(require('markdown-it-abbr'));

Metalsmith('test/fixtures/plugin')
.use(md)
.build(function(err){
if (err) return done(err);
equal('test/fixtures/plugin/expected', 'test/fixtures/plugin/build');
done()
});
});

it('should be able to use a plugin', function(done){
Metalsmith('test/fixtures/plugin')
.use(markdown('default').use(require('markdown-it-abbr')))
.build(function(err){
if (err) return done(err);
equal('test/fixtures/plugin/expected', 'test/fixtures/plugin/build');
Expand Down

0 comments on commit 43c6a6a

Please sign in to comment.