From 65146598775c3e6096624a3ead6ddd1ecf70c5fb Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Mon, 28 Jul 2014 13:17:42 +0200 Subject: [PATCH 1/5] strip unused argument (introduced in 2636f85) --- lib/marked.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/marked.js b/lib/marked.js index 8fc72b3a3a..ace6a7f857 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -936,7 +936,7 @@ Parser.parse = function(src, options) { */ Parser.prototype.parse = function(src) { - this.inline = new InlineLexer(src.links, this.options, this.renderer); + this.inline = new InlineLexer(src.links, this.options); this.tokens = src.reverse(); var out = ''; From 59c7a0114b5e47506a7f3b8ce43fd72ee3f724c2 Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Mon, 28 Jul 2014 13:22:09 +0200 Subject: [PATCH 2/5] pass only the textual part as the 'raw' argument for heading renderer --- lib/marked.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/marked.js b/lib/marked.js index ace6a7f857..2134db510c 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -909,6 +909,32 @@ Renderer.prototype.text = function(text) { return text; }; +/** + * TextRenderer + * returns only the textual part of the token + */ + +function TextRenderer() {} + +// no need for block level renderers + +TextRenderer.prototype.strong = +TextRenderer.prototype.em = +TextRenderer.prototype.codespan = +TextRenderer.prototype.del = +TextRenderer.prototype.text = function (text) { + return text; +} + +TextRenderer.prototype.link = +TextRenderer.prototype.image = function(href, title, text) { + return '' + text; +} + +TextRenderer.prototype.br = function() { + return ''; +} + /** * Parsing & Compiling */ @@ -937,6 +963,8 @@ Parser.parse = function(src, options) { Parser.prototype.parse = function(src) { this.inline = new InlineLexer(src.links, this.options); + // use an InlineLexer with a TextRenderer to extract pure text + this.inlineText = new InlineLexer(src.links, merge({}, this.options, {renderer: new TextRenderer})); this.tokens = src.reverse(); var out = ''; @@ -993,7 +1021,7 @@ Parser.prototype.tok = function() { return this.renderer.heading( this.inline.output(this.token.text), this.token.depth, - this.token.text); + unescape(this.inlineText.output(this.token.text))); } case 'code': { return this.renderer.code(this.token.text, From c6dae44f5dc4120b78ca83cfab18e0e4f80292e6 Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Mon, 28 Jul 2014 13:45:56 +0200 Subject: [PATCH 3/5] export TextRenderer for convenience --- lib/marked.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/marked.js b/lib/marked.js index 2134db510c..a901e6126a 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -1326,6 +1326,7 @@ marked.Parser = Parser; marked.parser = Parser.parse; marked.Renderer = Renderer; +marked.TextRenderer = TextRenderer; marked.Lexer = Lexer; marked.lexer = Lexer.lex; From 508068ddd08e16c681541f1732619e6433e92bd5 Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Mon, 15 Jan 2018 03:21:13 +0100 Subject: [PATCH 4/5] fix test accordingly --- test/new/links_reference_style.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/new/links_reference_style.html b/test/new/links_reference_style.html index 2ec1b41f21..e12da3f20a 100644 --- a/test/new/links_reference_style.html +++ b/test/new/links_reference_style.html @@ -48,7 +48,7 @@

[bar]

However, it can directly follow other block elements, such as headings

-

Foo

+

Foo

bar

From b5e3b88e8d80c3ba5428342a5a24ca7aeba943a8 Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Mon, 15 Jan 2018 03:30:43 +0100 Subject: [PATCH 5/5] add tests for clean heading IDs --- test/new/headings-id.html | 13 +++++++++++++ test/new/headings-id.md | 14 ++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 test/new/headings-id.html create mode 100644 test/new/headings-id.md diff --git a/test/new/headings-id.html b/test/new/headings-id.html new file mode 100644 index 0000000000..6f0ae49e32 --- /dev/null +++ b/test/new/headings-id.html @@ -0,0 +1,13 @@ + + +

Heading with some italic text

+ +

Or some strong

+ +

(which doesn't really make any difference, here)

+ +

Or even code

+ +

What about strikethrough

+ + \ No newline at end of file diff --git a/test/new/headings-id.md b/test/new/headings-id.md new file mode 100644 index 0000000000..fa8a4d82ca --- /dev/null +++ b/test/new/headings-id.md @@ -0,0 +1,14 @@ +### Heading with a [link](http://github.com/) + +### Heading with some _italic text_ + +### Or some **strong** +(which doesn't really make any difference, here) + +### Or even `code` + +### What about ~~strikethrough~~ + +## And a ref [link][destination] + +[destination]: /some/url "link to nowhere" \ No newline at end of file