Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with parsing nested Blocks #816

Open
BeneHenke opened this issue Sep 5, 2024 · 7 comments
Open

Help with parsing nested Blocks #816

BeneHenke opened this issue Sep 5, 2024 · 7 comments
Labels

Comments

@BeneHenke
Copy link

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.

@xoofx xoofx added the question label Sep 7, 2024
@xoofx
Copy link
Owner

xoofx commented 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.

@BeneHenke
Copy link
Author

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.

@xoofx
Copy link
Owner

xoofx commented 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)

@BeneHenke
Copy link
Author

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.

@xoofx
Copy link
Owner

xoofx commented 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 ##)

@BeneHenke
Copy link
Author

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
Copy link
Author

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants