Allow Inline to access its parent LeafBlock #393

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

Originally created by @yufeih on GitHub (Aug 4, 2020).

In the Block --> Inline hierarchical design of markdig, it is easy to traverse the markdown object tree from top to bottom, but it doesn't seem possible to reverse lookup the path of any markdown object all the way up to the root node. (Correct me if I am wrong).

For one, bugs like #460 leads to incorrect Parent value, also Inline does not seem to have a way to trace back to the containing LeafBlock.

The ask is to provide a contract to reliability trace back the path to root for any given MarkdownObject, be it Block or Inline. The contract should work reliably after the markdown AST has been constructed. (In DocumentProcessed callback and renderers), depending on how parsers are designed, it would be great to have it also work inside custom parsers.

docfx have built a couple of markdig extensions to support file inclusion, markdown section versioning. Having the ability to reliably trace back to root makes it easy to answer questions like what file a markdown object belongs to, what version is a markdown object, etc.

Originally created by @yufeih on GitHub (Aug 4, 2020). In the `Block` --> `Inline` hierarchical design of markdig, it is easy to traverse the markdown object tree from top to bottom, but it doesn't seem possible to reverse lookup the path of any markdown object all the way up to the root node. (Correct me if I am wrong). For one, bugs like #460 leads to incorrect `Parent` value, also `Inline` does not seem to have a way to trace back to the containing `LeafBlock`. The ask is to provide a contract to reliability trace back the path to root for any given `MarkdownObject`, be it `Block` or `Inline`. The contract should work reliably after the markdown AST has been constructed. (In `DocumentProcessed` callback and renderers), depending on how parsers are designed, it would be great to have it also work inside custom parsers. [docfx](https://github.com/dotnet/docfx) have built a couple of markdig extensions to support file inclusion, markdown section versioning. Having the ability to reliably trace back to root makes it easy to answer questions like what file a markdown object belongs to, what version is a markdown object, etc.
claunia added the enhancementPR Welcome! labels 2026-01-29 14:35:38 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#393