-
-
Notifications
You must be signed in to change notification settings - Fork 20
Add information about line numbering
and line highlighting
into documentation
#32
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
Conversation
This comment has been minimized.
This comment has been minimized.
Hi again Talat, thanks for your patience, I was a bit busy. I took your take as inspiration and wrote a short example in the existing example section! Thank you. Also: looks like the email you Or, perhaps, you accidentally added literal quotes locally in Git itself? 🤔 Finally, for your plugin: |
You're right! I just realized that the commit author was set as I corrected the commit name across all my projects and force-pushed the changes, rewriting the entire Git history—which took some time. I used the Thank you warning me. 👍 |
You suggested that I add support for highlighting/numbering code lines using HTML attributes as well. I got it, and will try to do it. For clarification, ```js {1,3} showLineNumbers
console.log("Highlight this line");
console.log("Don't highlight this");
console.log("Highlight this too");
``` And, your suggestion is that <pre><code class="language-js" data-highlight-lines="1,3" data-show-line-numbers>
console.log("Highlight this line");
console.log("Don't highlight this");
console.log("Highlight this too");
</code></pre> |
Awesome, cool! 👍 |
Hi @wooorm, I've updated the <pre><code class="language-typescript show-line-numbers" data-highlight-lines="2-4">
// content of the code
</code></pre> But, the problem I discovered is that the hast-util-raw (in order to use html in markdown) is removing I will open a PR for updating the example related with |
The A user can then also themselves, before using |
Exactly, now,
And it also supports
Something like that (before import type { Plugin } from "unified";
import type { Root } from "hast";
import { visit, type VisitorResult } from "unist-util-visit";
/**
*
* copy code.data.meta into code.properties.metastring
*
* use it before rehype-raw since it destroys the code.data.meta
*
*/
const pluginCodeMeta: Plugin<void[], Root> = () => {
return (tree: Root): undefined => {
visit(tree, "element", function (code, index, parent): VisitorResult {
if (!parent || index === undefined || code.tagName !== "code") {
return;
}
if (parent.type !== "element" || parent.tagName !== "pre") {
return;
}
code.properties.metastring = code.data?.meta;
});
};
}; |
Initial checklist
Description of changes
It is about for adding information about line numbering and line highlighting into documentation, which is done via rehype plugin
rehype-highlight-code-lines
. An example has been provided as well.Fixes #29