From 9eae3ce489d7477b9fec8f2a4d9b2c357fb15402 Mon Sep 17 00:00:00 2001 From: Joshua Gleitze Date: Sun, 1 May 2016 20:30:11 +0200 Subject: [PATCH] Added the option to disable rules. Disabling rules may for example be wished to use another plugin that uses the same syntax. --- lib/renderer.js | 4 + test/fixtures/outputs/disable-multiple.html | 142 +++++++++++++++ test/fixtures/outputs/disable-single.html | 183 ++++++++++++++++++++ test/index.js | 34 ++++ 4 files changed, 363 insertions(+) create mode 100644 test/fixtures/outputs/disable-multiple.html create mode 100644 test/fixtures/outputs/disable-single.html diff --git a/lib/renderer.js b/lib/renderer.js index fc9da04..ec4dc15 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -22,5 +22,9 @@ module.exports = function (data, options) { parser = parser.use(require('./anchors'), opt.anchors); } + if (opt.disable) { + parser.disable(opt.disable); + } + return parser.render(data.text); }; diff --git a/test/fixtures/outputs/disable-multiple.html b/test/fixtures/outputs/disable-multiple.html new file mode 100644 index 0000000..b87abf6 --- /dev/null +++ b/test/fixtures/outputs/disable-multiple.html @@ -0,0 +1,142 @@ +

h1 Heading em português

+

h2 Heading :P

+

h3 Heading

+

h4 Heading

+
h5 Heading
+
h6 Heading
+

Horizontal Rule

+
+

Horizontal Rule

+
+

Horizontal Rule

+
+

Typographic replacements

+

Enable typographer option to see result.

+

(c) (C) (r) (R) (tm) (TM) (p) (P) +-

+

test.. test... test..... test?..... test!....

+

!!!!!! ???? ,, -- ---

+

"Smartypants, double quotes" and 'single quotes'

+

Emphasis

+

This is bold text

+

This is bold text

+

This is italic text

+

This is italic text

+

~~Strikethrough~~

+

Blockquotes

+

> Blockquotes can also be nested... +>> ...by using additional greater-than signs right next to each other... +> > > ...or with spaces between arrows.

+

Lists

+

Unordered

+ +

Ordered

+
    +
  1. Lorem ipsum dolor sit amet
  2. +
  3. Consectetur adipiscing elit
  4. +
  5. Integer molestie lorem at massa
  6. +
+

Code

+

Inline code

+

Indented code

+
// Some comments
+line 1 of code
+line 2 of code
+line 3 of code
+
+

Block code "fences"

+
Sample text here...
+
+

Syntax highlighting

+
var foo = function (bar) {
+  return bar++;
+};
+
+console.log(foo(5));
+
+

Tables

+

| Option | Description | +| ------ | ----------- | +| data | path to data files to supply the data that will be passed into templates. | +| engine | engine to be used for processing templates. Handlebars is the default. | +| ext | extension to be used for dest files. |

+

Right aligned columns

+

| Option | Description | +| ------:| -----------:| +| data | path to data files to supply the data that will be passed into templates. | +| engine | engine to be used for processing templates. Handlebars is the default. | +| ext | extension to be used for dest files. |

+

Links

+

link text

+

Autoconverted link https://github.com/nodeca/pica (enable linkify to see)

+

Images

+

Minion +Stormtroopocat

+

Alt text

+

Plugins

+

The killer feature of markdown-it is very effective support of +syntax plugins.

+

Emojies

+

> Classic markup: :wink: :crush: :cry: :tear: :laughing: :yum: +> +> Shortcuts (emoticons): :-) :-( 8-) ;)

+

see how to change output with twemoji.

+

Subscipt / Superscirpt

+ +

<ins>

+

++Inserted text++

+

<mark>

+

==Marked text==

+

Footnotes

+

Footnote 1 link[^first].

+

Footnote 2 link[^second].

+

Inline footnote^[Text of inline footnote] definition.

+

Duplicated footnote reference[^second].

+

[^first]: Footnote can have markup

+
and multiple paragraphs.
+
+

[^second]: Footnote text.

+

Definition lists

+

Term 1

+

: Definition 1 +with lazy continuation.

+

Term 2 with inline markup

+

: Definition 2

+
    { some code, part of Definition 2 }
+
+Third paragraph of definition 2.
+
+

Compact style:

+

Term 1 +~ Definition 1

+

Term 2 +~ Definition 2a +~ Definition 2b

+

Abbreviations

+

This is HTML abbreviation example.

+

It converts "HTML", but keep intact partial entries like "xxxHTMLyyy" and so on.

+

*[HTML]: Hyper Text Markup Language

+

Custom containers

+

::: warning +here be dragons +:::

diff --git a/test/fixtures/outputs/disable-single.html b/test/fixtures/outputs/disable-single.html new file mode 100644 index 0000000..8472d03 --- /dev/null +++ b/test/fixtures/outputs/disable-single.html @@ -0,0 +1,183 @@ +

h1 Heading em português

+

h2 Heading :P

+

h3 Heading

+

h4 Heading

+
h5 Heading
+
h6 Heading
+

Horizontal Rule

+
+

Horizontal Rule

+
+

Horizontal Rule

+
+

Typographic replacements

+

Enable typographer option to see result.

+

(c) (C) (r) (R) (tm) (TM) (p) (P) +-

+

test.. test... test..... test?..... test!....

+

!!!!!! ???? ,, -- ---

+

"Smartypants, double quotes" and 'single quotes'

+

Emphasis

+

This is bold text

+

This is bold text

+

This is italic text

+

This is italic text

+

~~Strikethrough~~

+

Blockquotes

+
+

Blockquotes can also be nested...

+
+

...by using additional greater-than signs right next to each other...

+
+

...or with spaces between arrows.

+
+
+
+

Lists

+

Unordered

+ +

Ordered

+
    +
  1. Lorem ipsum dolor sit amet
  2. +
  3. Consectetur adipiscing elit
  4. +
  5. Integer molestie lorem at massa
  6. +
+

Code

+

Inline code

+

Indented code

+
// Some comments
+line 1 of code
+line 2 of code
+line 3 of code
+
+

Block code "fences"

+
Sample text here...
+
+

Syntax highlighting

+
var foo = function (bar) {
+  return bar++;
+};
+
+console.log(foo(5));
+
+

Tables

+ + + + + + + + + + + + + + + + + + + + + +
OptionDescription
datapath to data files to supply the data that will be passed into templates.
engineengine to be used for processing templates. Handlebars is the default.
extextension to be used for dest files.
+

Right aligned columns

+ + + + + + + + + + + + + + + + + + + + + +
OptionDescription
datapath to data files to supply the data that will be passed into templates.
engineengine to be used for processing templates. Handlebars is the default.
extextension to be used for dest files.
+

Links

+

link text

+

Autoconverted link https://github.com/nodeca/pica (enable linkify to see)

+

Images

+

Minion +Stormtroopocat

+

Alt text

+

Plugins

+

The killer feature of markdown-it is very effective support of +syntax plugins.

+

Emojies

+
+

Classic markup: :wink: :crush: :cry: :tear: :laughing: :yum:

+

Shortcuts (emoticons): :-) :-( 8-) ;)

+
+

see how to change output with twemoji.

+

Subscipt / Superscirpt

+ +

<ins>

+

++Inserted text++

+

<mark>

+

==Marked text==

+

Footnotes

+

Footnote 1 link[^first].

+

Footnote 2 link[^second].

+

Inline footnote^[Text of inline footnote] definition.

+

Duplicated footnote reference[^second].

+

[^first]: Footnote can have markup

+
and multiple paragraphs.
+
+

[^second]: Footnote text.

+

Definition lists

+

Term 1

+

: Definition 1 +with lazy continuation.

+

Term 2 with inline markup

+

: Definition 2

+
    { some code, part of Definition 2 }
+
+Third paragraph of definition 2.
+
+

Compact style:

+

Term 1 +~ Definition 1

+

Term 2 +~ Definition 2a +~ Definition 2b

+

Abbreviations

+

This is HTML abbreviation example.

+

It converts "HTML", but keep intact partial entries like "xxxHTMLyyy" and so on.

+

*[HTML]: Hyper Text Markup Language

+

Custom containers

+

::: warning +here be dragons +:::

diff --git a/test/index.js b/test/index.js index 5ac21c5..bfd27af 100644 --- a/test/index.js +++ b/test/index.js @@ -188,4 +188,38 @@ describe('Hexo Renderer Markdown-it', function () { result.should.equal(anchors_with_permalinks); }); + + it('should allow to disable a rule', function () { + var parsed_disabled = fs.readFileSync('./test/fixtures/outputs/disable-single.html', 'utf8'); + var ctx = { + config: { + markdown: { + disable: 'strikethrough' + } + } + }; + var parse = render.bind(ctx); + var result = parse({ + text: source + }); + ctx = {}; + result.should.equal(parsed_disabled); + }); + + it('should allow to disable multiple rules', function () { + var parsed_disabled = fs.readFileSync('./test/fixtures/outputs/disable-multiple.html', 'utf8'); + var ctx = { + config: { + markdown: { + disable: ['strikethrough', 'table', 'blockquote'] + } + } + }; + var parse = render.bind(ctx); + var result = parse({ + text: source + }); + ctx = {}; + result.should.equal(parsed_disabled); + }); });