Skip to content
Browse files

fix potential problems with highlighter callback and escapes.

  • Loading branch information...
1 parent b814a0a commit f7be7f964041fdd3a32b83862a64b80fda87b730 @chjj committed Apr 11, 2012
Showing with 11 additions and 6 deletions.
  1. +3 −3 README.md
  2. +8 −3 lib/marked.js
View
6 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;
}
View
11 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 '<pre><code'
+ (token.lang

0 comments on commit f7be7f9

Please sign in to comment.
Something went wrong with that request. Please try again.