You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
return`<pre><code class="hljs ${language}">${hljs.highlight(code,{ language }).value}</code></pre>`;
};
}
Hi! I was wondering why code highlighting was implemented as an override to the code function of the marked renderer, versus utilizing the highlighted option in marked?
I believe setting the options such that
highlight: function(code,lang){consthljs=require('highlight.js');constlanguage=hljs.getLanguage(lang) ? lang : 'plaintext';returnhljs.highlight(code,{ language }).value;},langPrefix: 'hljs '
would have the same result.
My current goal is to override the code renderer, and I do so by creating a new class that extends marked.Renderer and defining a new code method within there. The current implementation of the marked integration, however, ends up overriding my custom class. The alternative method
constrenderer=newmarked.Rendere0;renderer.code=(code,infostring,escaped)=>{/* do stuff */}
does not allow me to easily fall back to the default handler.
If this change is OK I can submit a PR.
The text was updated successfully, but these errors were encountered:
Hey, thanks for bringing this up... I was not aware of the highlight option, maybe that wasn't around yet when I implemented this? I started out with marked@0.3 😅
This should also allow to simplify the code base, but yeah I'm also planning to change the whole implementation around marked because there's now the use method to allow extensions, which I want to expose properly (will have to be a new major version though I think)... currently don't really have much time to work on this though. So thanks for the PR already, will have a look tomorrow.
md-to-pdf/src/lib/get-marked-with-highlighter.ts
Lines 8 to 15 in e70ea15
Hi! I was wondering why code highlighting was implemented as an override to the
code
function of the marked renderer, versus utilizing thehighlighted
option in marked?I believe setting the options such that
would have the same result.
My current goal is to override the
code
renderer, and I do so by creating a new class that extendsmarked.Renderer
and defining a newcode
method within there. The current implementation of the marked integration, however, ends up overriding my custom class. The alternative methoddoes not allow me to easily fall back to the default handler.
If this change is OK I can submit a PR.
The text was updated successfully, but these errors were encountered: