Add precise source location for inline elements #3

Closed
opened 2026-01-29 14:18:32 +00:00 by claunia · 1 comment
Owner

Originally created by @xoofx on GitHub (May 25, 2016).

The current implementation doesn't track accurate source code position for inline elements (link, emphasis...etc.) but only for block parser elements (paragraph, blockquotes...etc.).

In order to optimize the execution, the code is a bit destructive when going through inline parsing (can remove spaces...etc.) but if an IDE wanted to use Markdig for precise syntax highlighting, it would require to be conservative.

Care would have to be taken to make this optional (e.g PreciseSourceLocation)

Work in progress in the precise_location branch

Originally created by @xoofx on GitHub (May 25, 2016). The current implementation doesn't track accurate source code position for inline elements (link, emphasis...etc.) but only for block parser elements (paragraph, blockquotes...etc.). In order to optimize the execution, the code is a bit destructive when going through inline parsing (can remove spaces...etc.) but if an IDE wanted to use Markdig for precise syntax highlighting, it would require to be conservative. Care would have to be taken to make this optional (e.g PreciseSourceLocation) Work in progress in the [precise_location](https://github.com/lunet-io/markdig/tree/precise_position) branch
claunia added the enhancement label 2026-01-29 14:18:33 +00:00
Author
Owner

@xoofx commented on GitHub (Jun 15, 2016):

Precise source location can now be activated with MarkdownPipelineBuilder.UsePreciseSourceLocation()

Then each AST MarkdownObject have the following properties:

  • Line (zero-based)
  • Column (zero-based)
  • SourceStartPosition: the character position where this item start, location relative to the start of the text buffer
  • SourceEndPosition: the character position where this item ends, location from the start of the text buffer

See TestSourcePosition.cs for the tests.

There are a few known issues:

  • grid tables are not yet supported
  • tabs in a document are not well supported (and may report invalid position)
@xoofx commented on GitHub (Jun 15, 2016): Precise source location can now be activated with `MarkdownPipelineBuilder.UsePreciseSourceLocation()` Then each AST [`MarkdownObject`](https://github.com/lunet-io/markdig/blob/master/src/Markdig/Syntax/MarkdownObject.cs) have the following properties: - Line (zero-based) - Column (zero-based) - SourceStartPosition: the character position where this item start, location relative to the start of the text buffer - SourceEndPosition: the character position where this item ends, location from the start of the text buffer See [TestSourcePosition.cs](https://github.com/lunet-io/markdig/blob/master/src/Markdig.Tests/TestSourcePosition.cs) for the tests. There are a few known issues: - grid tables are not yet supported - tabs in a document are not well supported (and may report invalid position)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#3