-
Notifications
You must be signed in to change notification settings - Fork 22
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
DOM-Based Plugins won't work (notably line-numbers
)
#1
Comments
Unfortunately, I guess you’re right. Most Prism plugins manipulate the DOM and can thus not be used outside the browser without further hassle. There are some plugins that work though, like If you want to use |
Hi, Aside this point, this plugin remain useful; prism isn't just "plain dead simple" to add to markdown-it, and this does the job very well. |
@EmmanuelBeziat I added a note and a link to this issue to the README. Glad to hear that this plugin is nevertheless useful to you! |
Do you have a link to your website where you implement that at all @jGleitz? I can get the counter bit working, but I'm having a little trouble figuring out how to create a |
@sbrl for my purposes, this simple regex replace did the trick (from code.pug): const LINEREGEX = /\n(?!$)([\t ]*)(<[^>]*?class="[^>]*?comment[^>]*?>)?/g;
function wrapInLineSpans(code, idprefix) {
let linespan = () => `<span class="line">`;
if (typeof idprefix === 'string') {
let lineindex = 1;
linespan = () => `<span class="line" id="${lineid(idprefix, lineindex++)}">`;
}
return linespan() + code.replace(LINEREGEX, (match, nextLineStart, optionalComment) =>
`</span>\n${optionalComment || ""}${linespan()}${nextLineStart}`);
} If Of course, this regex is bound to break on some input. However, it worked well for all code excerpts I had. |
line-numbers
)line-numbers
)
from prismjs.com: https://prismjs.com/plugins/line-numbers/ I insert <body class='line-numbers' ...>
</body> I actually have another question about
Insert <pre data-line="{10,12-22}" class="language-javascript line-numbers" tabindex="0"> Are there any markdown-it plugins that can do similar things?extract {...} from for example:(I use const md = require('markdown-it')();
const prism = require('markdown-it-xxxxplugin');
md.use(prism, {callback: xxxxCallbackFunction});
md.render(content) |
This probably means that you have
I think you could try |
I've solved the line numbers like this (might not be perfect, but enough for my needs):
|
@andreas-mausch That works great for line numbering! Any idea how I could use this to statically highlight a particular line of code? I'm currently using The best I can think of is to have one ```js {data-line-highlight="42"}
const foo = 'bar';
``` Edit: Hmm, this would only work for single-line highlights, not for multiline. |
The
line-numbers
plugin (and all the other plugins I have checked so far) won't work.This is due to a statement in every of them:
which prevents anything from being registered. Further, most of them use the document and browser-only methods.
I guess the only way to make them work would be to rewrite all of them to make them work...
The text was updated successfully, but these errors were encountered: