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 @@ +
(which doesn't really make any difference, here)
+ +code
[bar]
However, it can directly follow other block elements, such as headings
-bar