Can source line numbers appear in the rendered output? #633

Closed
opened 2026-01-29 14:41:35 +00:00 by claunia · 3 comments
Owner

Originally created by @deanebarker on GitHub (Oct 6, 2023).

Is there any support or extension in MarkDig for corresponding output elements with the line number from the source? This would allow finding the correct line in the source from the output (i.e. -- synchronizing scrolling of source or output elements when doing side-by-side editing).

For example:

# Heading

This is some text.

Theoretical output:

<h1 data-line-number="1">Heading</h1>
<p data-line-number="3">This is some text.</p>

That's just an illustration -- I'm curious if there's anything in the library or extensions that does something similar to the example.

Originally created by @deanebarker on GitHub (Oct 6, 2023). Is there any support or extension in MarkDig for corresponding output elements with the line number from the source? This would allow finding the correct line in the source from the output (i.e. -- synchronizing scrolling of source or output elements when doing side-by-side editing). For example: ``` # Heading This is some text. ``` Theoretical output: ``` <h1 data-line-number="1">Heading</h1> <p data-line-number="3">This is some text.</p> ``` That's just an illustration -- I'm curious if there's anything in the library or extensions that does something similar to the example.
claunia added the question label 2026-01-29 14:41:35 +00:00
Author
Owner

@xoofx commented on GitHub (Oct 6, 2023):

There is the pipeline.UsePragmaLines() extension

This is what the Markdown Editor for Visual Studio is using for example here

@xoofx commented on GitHub (Oct 6, 2023): There is the [`pipeline.UsePragmaLines()` extension](https://github.com/xoofx/markdig/blob/master/src/Markdig/Extensions/PragmaLines/PragmaLineExtension.cs) This is what the Markdown Editor for Visual Studio is using for example [here](https://github.com/madskristensen/MarkdownEditor/blob/a4484fbbd92c3b691cb3d3408832462e2f6edde8/src/MarkdownEditor.Shared/Parsing/MarkdownFactory.cs#L24)
Author
Owner

@deanebarker commented on GitHub (Oct 6, 2023):

Perfect. I suspected that it existed, but I couldn't find it (TIL: what "pragma" means). Thank you.

@deanebarker commented on GitHub (Oct 6, 2023): Perfect. I suspected that it existed, but I couldn't find it (TIL: what "pragma" means). Thank you.
Author
Owner

@deanebarker commented on GitHub (Oct 6, 2023):

For anyone following this, here's what UsePragmaLines() returns for the example above (clearly, it's 0-based):

<h1 id="pragma-line-0">Heading</h1>
<p id="pragma-line-2">This is some text.</p>
@deanebarker commented on GitHub (Oct 6, 2023): For anyone following this, here's what `UsePragmaLines()` returns for the example above (clearly, it's 0-based): ``` <h1 id="pragma-line-0">Heading</h1> <p id="pragma-line-2">This is some text.</p> ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#633