[PR #68] Make ContainerBlock's children public #801

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

Original Pull Request: https://github.com/xoofx/markdig/pull/68

State: closed
Merged: No


I need to render anchor links for every header in the page. Since headers are not guaranteed to be unique in the id/name value I include also the name of the parent header.

For example:
## heading 1
### heading 1.1

should result in
<h3><a name="heading-1-heading-1-1" ...>heading 1.1</a><h3>

In order to handle that requirement I've created an extension for custom header (CustomHeadingBlockRenderer : HtmlObjectRenderer<HeadingBlock>), but I don't see a way to access information about preceding header at a higher level (so in this example for h3 header I need to access the previous h2 header).

Seems that if I could access the children of the ContainerBlock my issue would be solved:

protected override void Write(HtmlRenderer renderer, HeadingBlock obj)
{
    var parentHeader = obj.Parent.children; 
     ...
}

Also, if there's a better way to handle that requirement, suggestions will be more than welcome!

**Original Pull Request:** https://github.com/xoofx/markdig/pull/68 **State:** closed **Merged:** No --- I need to render anchor links for every header in the page. Since headers are not guaranteed to be unique in the id/name value I include also the name of the parent header. For example: `## heading 1` `### heading 1.1` should result in ```<h3><a name="heading-1-heading-1-1" ...>heading 1.1</a><h3>``` In order to handle that requirement I've created an extension for custom header (`CustomHeadingBlockRenderer : HtmlObjectRenderer<HeadingBlock>`), but I don't see a way to access information about preceding header at a higher level (so in this example for `h3` header I need to access the previous `h2` header). Seems that if I could access the children of the `ContainerBlock` my issue would be solved: ``` protected override void Write(HtmlRenderer renderer, HeadingBlock obj) { var parentHeader = obj.Parent.children; ... } ``` Also, if there's a better way to handle that requirement, suggestions will be more than welcome!
claunia added the pull-request label 2026-01-29 14:45:42 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#801