-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Conversation
👍 |
I hope this will be merged soon. |
@lifeisfoo Until then you can temporarily add this dependency to your {
"dependencies": {
"marked": "chester1000/marked",
"...": "..."
}
} remember to |
👍 This helped me make sure the styles are correct when using marked and highlightjs. |
Thanks for the feature 👍 This is exactly what I needed. Though I think it would be nice to also support an array of string method in order to permit several classes definition. |
Since simply passing If more people will be pro-Array, though, I can edit my PR to include it. |
It could indeed be done as you said, my proposal was just for convenience. |
This is what I needed! var marked = require('marked');
var hljs = require('highlight.js');
var renderer = new marked.Renderer();
renderer.code = function(code, language){
return '<pre><code class="hljs ' + language + '">' +
hljs.highlight(language, code).value +
'</code></pre>';
};
console.log(marked(codeStr, { renderer: renderer })); |
@chikathreesix I actually ended up with the same solution 👍 Far more flexible |
Cool 👍 |
+1 |
+1 for sure. |
I set |
Updated my repo to the latest codebase. Still can't get why it can't be merged. |
Bump. @chjj? |
Please merge! |
Currently the class is not added by marked nor by highlight.js itself, and the rendered code will lack attributes such as background colour and others that are defined by highlight.js styles on that particular class. This workaround is based on markedjs/marked#418 (comment).
Please merge! |
Please merge! |
Please :) |
it could help a lot of people... instead, we use workaround .. |
@chjj Please merge this. |
@chjj please merge ;) |
Closing due to merge conflicts and not in line with recent changes to docs. |
When the language is undefined, ```
console.log('hahaha')
``` Will be rendered as: <pre><code><span class="hljs-built_in">console</span>.log(<span class="hljs-string">'hahaha'</span>)</code></pre> The code block will be missing the 'hljs' class. const marked = require('marked')
const hljs = require('highlight.js')
const renderer = new marked.Renderer()
const doRenderCode = (code, lang) => lang ? hljs.highlight(lang, code, true).value : hljs.highlightAuto(code).value
renderer.code = (code, lang) => `<pre><code class="hljs ${lang || ''}">${doRenderCode(code, lang)}</code></pre>`
const markedOptions = {
Renderer
// langPrefix: 'hljs ',
// highlight: (code, lang) => lang ? hljs.highlight(lang, code, true).value : hljs.highlightAuto(code).value
}
console.log(marked(markdownStr, markedOptions)) Input markdown string: ```
console.log('hahaha')
```
```js
console.log('hahaha')
``` Will be rendered as: <pre><code class="hljs "><span class="hljs-built_in">console</span>.log(<span class="hljs-string">'hahaha'</span>)</code></pre>
<pre><code class="hljs js"><span class="hljs-built_in">console</span>.log(<span class="hljs-string">'hahaha'</span>)</code></pre> |
This is one of the possible solutions. Any thoughts?