From f7be7f964041fdd3a32b83862a64b80fda87b730 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 11 Apr 2012 01:57:17 -0500 Subject: [PATCH] fix potential problems with highlighter callback and escapes. --- README.md | 6 +++--- lib/marked.js | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a2a97d5e..c10495ae 100644 --- a/README.md +++ b/README.md @@ -81,9 +81,9 @@ marked.setOptions({ pedantic: false, sanitize: true, // callback for code highlighter - highlight: function(code, language) { - if (language === 'js') { - code = highlight(code); + highlight: function(code, lang) { + if (lang === 'js') { + return javascriptHighlighter(code); } return code; } diff --git a/lib/marked.js b/lib/marked.js index 02d725ed..d39aad37 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -531,10 +531,15 @@ var tok = function() { + '>\n'; } case 'code': { + if (options.highlight) { + token.code = options.highlight(token.text, token.lang); + if (token.code != null && token.code !== token.text) { + token.escaped = true; + token.text = token.code; + } + } if (!token.escaped) { - token.text = options.highlight - ? options.highlight(token.text, token.lang) - : escape(token.text, true); + token.text = escape(token.text, true); } return '