diff --git a/lib/marked.js b/lib/marked.js index b29fda99..dd6ca881 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -920,6 +920,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 */ @@ -947,7 +973,9 @@ 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); + // 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 = ''; @@ -1004,7 +1032,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, @@ -1307,6 +1335,7 @@ marked.Parser = Parser; marked.parser = Parser.parse; marked.Renderer = Renderer; +marked.TextRenderer = TextRenderer; marked.Lexer = Lexer; marked.lexer = Lexer.lex; diff --git a/test/new/headings-id.html b/test/new/headings-id.html new file mode 100644 index 00000000..6f0ae49e --- /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 00000000..fa8a4d82 --- /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 diff --git a/test/new/links_reference_style.html b/test/new/links_reference_style.html index 2ec1b41f..e12da3f2 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