Help with parsing nested Blocks #696

Open
opened 2026-01-29 14:43:09 +00:00 by claunia · 7 comments
Owner

Originally created by @BeneHenke on GitHub (Sep 5, 2024).

Hello,

I'm trying to create an extension that divides my text into sections between every heading. For this I want to find the extend of each section block and then continue to parse the section, appending all the parsed blocks to my section. Is there a block that does something similar already I could look at for guidance? So far I have only had success with manually appending blocks to Containerblocks.

Originally created by @BeneHenke on GitHub (Sep 5, 2024). Hello, I'm trying to create an extension that divides my text into sections between every heading. For this I want to find the extend of each section block and then continue to parse the section, appending all the parsed blocks to my section. Is there a block that does something similar already I could look at for guidance? So far I have only had success with manually appending blocks to Containerblocks.
claunia added the question label 2026-01-29 14:43:10 +00:00
Author
Owner

@xoofx commented on GitHub (Sep 7, 2024):

You should go over the top-level blocks returned by the MarkdownDocument instance and chunk them from there. You can create your own SectionBlock that derives from ContainerBlock.
Otherwise, I'm not sure to understand your issue.

@xoofx commented on GitHub (Sep 7, 2024): You should go over the top-level blocks returned by the `MarkdownDocument` instance and chunk them from there. You can create your own `SectionBlock` that derives from `ContainerBlock`. Otherwise, I'm not sure to understand your issue.
Author
Owner

@BeneHenke commented on GitHub (Sep 7, 2024):

Thanks for the answer. If i understand your solution right, that is how I do it right now. I was just wondering if I could insert them while parsing the document by putting their renderer first and then telling the parser to parse the span of my section block and inserting everthing to the section instead of the main document.

@BeneHenke commented on GitHub (Sep 7, 2024): Thanks for the answer. If i understand your solution right, that is how I do it right now. I was just wondering if I could insert them while parsing the document by putting their renderer first and then telling the parser to parse the span of my section block and inserting everthing to the section instead of the main document.
Author
Owner

@xoofx commented on GitHub (Sep 7, 2024):

I was just wondering if I could insert them while parsing the document by putting their renderer first and then telling the parser to parse the span of my section block and inserting everthing to the section instead of the main document.

I'm not sure to understand this question as well, sorry 😅

I'm confused by "parsing the document by putting their renderer first", there is no such thing as a rendering involved during the parsing.

If you would like to process the blocks on the fly, this is not possible. You have to parse the document, rework the blocks, and then you can render the updated document (after adding a renderer for the SectionBlock to the render pipeline)

@xoofx commented on GitHub (Sep 7, 2024): > I was just wondering if I could insert them while parsing the document by putting their renderer first and then telling the parser to parse the span of my section block and inserting everthing to the section instead of the main document. I'm not sure to understand this question as well, sorry 😅 I'm confused by "parsing the document by putting their renderer first", there is no such thing as a rendering involved during the parsing. If you would like to process the blocks on the fly, this is not possible. You have to parse the document, rework the blocks, and then you can render the updated document (after adding a renderer for the `SectionBlock` to the render pipeline)
Author
Owner

@BeneHenke commented on GitHub (Sep 7, 2024):

I'm sorry I meant to write put the section parser first, then find the sections and then parse the sections for other blocks. I basically woke op from the GitHub notification so my brain was not quite there 😅 . Btw thank you for your amazing library.

@BeneHenke commented on GitHub (Sep 7, 2024): I'm sorry I meant to write put the section parser first, then find the sections and then parse the sections for other blocks. I basically woke op from the GitHub notification so my brain was not quite there :sweat_smile: . Btw thank you for your amazing library.
Author
Owner

@xoofx commented on GitHub (Sep 7, 2024):

I'm sorry I meant to write put the section parser first, then find the sections and then parse the sections for other blocks. I basically woke op from the GitHub notification so my brain was not quite there 😅 . Btw thank you for your amazing library.

How is defined a section in markdown in your text? (I thought you were recovering sections from e.g markdown Headings e.g ##)

@xoofx commented on GitHub (Sep 7, 2024): > I'm sorry I meant to write put the section parser first, then find the sections and then parse the sections for other blocks. I basically woke op from the GitHub notification so my brain was not quite there 😅 . Btw thank you for your amazing library. How is defined a section in markdown in your text? (I thought you were recovering sections from e.g markdown Headings e.g `##`)
Author
Owner

@BeneHenke commented on GitHub (Sep 7, 2024):

I basically made my own heading block as it needed to support the syntax without the space after the # and some other custom syntax. So my thought was to use my current Custom heading block parser to find the beginning of each section and then inserting a heading into my section by default. Then I would search for the next heading of the same or a higher level and end the section there.

@BeneHenke commented on GitHub (Sep 7, 2024): I basically made my own heading block as it needed to support the syntax without the space after the # and some other custom syntax. So my thought was to use my current Custom heading block parser to find the beginning of each section and then inserting a heading into my section by default. Then I would search for the next heading of the same or a higher level and end the section there.
Author
Owner

@BeneHenke commented on GitHub (Sep 10, 2024):

The problem with this is that I dont know if I can make my parser, parse the content of the section blocks and attach it to the section it is parsing.

@BeneHenke commented on GitHub (Sep 10, 2024): The problem with this is that I dont know if I can make my parser, parse the content of the section blocks and attach it to the section it is parsing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#696