From 3cb38528e99fbe00e88bf3fd6fdb08e186fb7069 Mon Sep 17 00:00:00 2001 From: Matthew Lyon Date: Mon, 2 Nov 2015 19:31:48 -0800 Subject: [PATCH 1/4] Provide a proxy to functions on the parser See the changes to the tests for a quick explanation as to why. --- lib/index.js | 15 +++++++++++++++ test/index.js | 12 ++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/index.js b/lib/index.js index fb1016b..a08c447 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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; } diff --git a/test/index.js b/test/index.js index b0e5c0a..c960d89 100644 --- a/test/index.js +++ b/test/index.js @@ -46,12 +46,8 @@ 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') - .use(md) + .use(markdown('zero').enable('emphasis')) .build(function(err){ if (err) return done(err); equal('test/fixtures/parser/expected', 'test/fixtures/parser/build'); @@ -60,12 +56,8 @@ describe('metalsmith-markdown', function(){ }); it('should be able to use a plugin', function(done){ - var md = markdown('default'); - - md.parser.use(require('markdown-it-abbr')); - Metalsmith('test/fixtures/plugin') - .use(md) + .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'); From c5a52c68e0e47d00f4a8e78bd082b68e44928424 Mon Sep 17 00:00:00 2001 From: Matthew Lyon Date: Mon, 7 Dec 2015 23:07:33 -0800 Subject: [PATCH 2/4] Re-add old test cases --- test/index.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/index.js b/test/index.js index c960d89..e1978d0 100644 --- a/test/index.js +++ b/test/index.js @@ -46,6 +46,19 @@ 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') + .use(md) + .build(function(err){ + if (err) return done(err); + equal('test/fixtures/parser/expected', 'test/fixtures/parser/build'); + done(); + }); + }); + + it('should expose the markdown parser via proxy', function(done){ Metalsmith('test/fixtures/parser') .use(markdown('zero').enable('emphasis')) .build(function(err){ @@ -55,6 +68,18 @@ describe('metalsmith-markdown', function(){ }); }); + 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'))) From 1e3c70b936065e29fa188fbefb3b18f87e9480f4 Mon Sep 17 00:00:00 2001 From: Matthew Lyon Date: Mon, 7 Dec 2015 23:12:01 -0800 Subject: [PATCH 3/4] Add .editorconfig file, npmignore it. --- .editorconfig | 3 +++ .npmignore | 1 + 2 files changed, 4 insertions(+) create mode 100644 .editorconfig create mode 100644 .npmignore diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..99117d6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +[*.js] +indent_style = space +indent_size = 2 \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..7f4b696 --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +.editorconfig From c928a111e31abe766255ee70398d8f32a75ee3a8 Mon Sep 17 00:00:00 2001 From: Matthew Lyon Date: Mon, 7 Dec 2015 23:12:21 -0800 Subject: [PATCH 4/4] Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6e35a2b..428df95 100644 --- a/package.json +++ b/package.json @@ -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": {