Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some highlighters require class on a wrapping element to render properly #418

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ the second argument.

## Options

### highlightClass

Type: `string`

Class to be set on wrapping `<pre>` element. Some highlighters require class on a wrapping
element to properly render background.

### highlight

Type: `function`
Expand Down Expand Up @@ -114,6 +121,7 @@ marked(markdownString, function (err, content) {

// Synchronous highlighting with highlight.js
marked.setOptions({
highlightClass: 'hljs',
highlight: function (code) {
return require('highlight.js').highlightAuto(code).value;
}
Expand Down
15 changes: 5 additions & 10 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,16 +763,11 @@ Renderer.prototype.code = function(code, lang, escaped) {
}
}

if (!lang) {
return '<pre><code>'
+ (escaped ? code : escape(code, true))
+ '\n</code></pre>';
}

return '<pre><code class="'
+ this.options.langPrefix
+ escape(lang, true)
+ '">'
return '<pre'
+ (this.options.highlightClass ? ' class="' + escape(this.options.highlightClass, true) + '"' : '')
+ '><code'
+ (lang ? ' class="' + this.options.langPrefix + escape(lang, true) + '"': '')
+ '>'
+ (escaped ? code : escape(code, true))
+ '\n</code></pre>\n';
};
Expand Down