-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add support for line numbers #29
Comments
Hey! There’s an example with starry-night: https://github.com/wooorm/starry-night#example-adding-line-numbers. |
Thank you for posting these examples! I don't know if only one example will do it for me right now. Here is my current setup with Unified import remarkParse from 'remark-parse'
import remarkGfm from 'remark-gfm'
import { type Plugin, unified } from 'unified'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
import rehypeHighlight from 'rehype-highlight'
export default async function markdownToHtml(markdown: string) {
const result = await unified()
.use(remarkParse as Plugin)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeHighlight)
.use(rehypeStringify)
.process(markdown)
return String(result)
} Would you suggest using the stand alone function to call on the parsed html or integrate into the Unified call? Sorry for the newb questions. |
No problem!
That shouldn’t be needed?
starry-night is a little lower. It only does the AST. It isn’t on the level of plugins. So, you’d need to write a rehype plugin that runs after this plugin. Then it would look for code blocks that were transformed, and add this gutter. The code for how to add the gutter should be very similar to that example in starry-night, but now operator on that node instead of an entire AST. Feel free to ask more Qs! |
An approach I took from pure JS was just inserting a column flex with span elements for each line, make |
I've created a You can reach to Important You need to use See some examples for
May I request that the author would add |
yes, sure, that’s good! Could go in “related” (https://github.com/rehypejs/rehype-highlight#related). And maybe somewhere else too? |
Thanks @wooorm . Line numbering and line highlighting is another most demanded feature align with code highlighting. For this reason, I want to get Line Numbering and Line HighlightingIf it is suitable, I can create a PR, do I ? |
yeah an example is also fine :) I don’t think you need to delve too deep, in the example. Something short and basic seems like enough to me? People can always read more about line numbering in your readme? |
I've created the PR #32 |
Initial checklist
Problem
Currently there is no easy way to add line numbers for the parsed code as each individual element is a span. the usual way in css to add line nubers is to add a before on the span such as
Solution
Add a wrapper span with special class to more easily add line numbers to code blocks.
Alternatives
If there is a current solution that I'm missing please inform me.
The text was updated successfully, but these errors were encountered: