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

Table of contents cannot track headers with Raw Block #161

Open
gha88 opened this issue Dec 28, 2023 · 5 comments
Open

Table of contents cannot track headers with Raw Block #161

gha88 opened this issue Dec 28, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@gha88
Copy link

gha88 commented Dec 28, 2023

As expected table of contents is rendered only before printing the document.
When rendering it is populated searching fow Heders block in document.
The problem is that using Raw block some headers can be set inside.
In my opinion the headers content should be track anyway even if inside the raw content.
The problem is that the content in Raw block should be parsed somehow.

@jrg94
Copy link
Member

jrg94 commented Dec 28, 2023

Yeah, that makes a lot of sense. At the moment, the raw blocks aren't parsed. This is something I wanted to implement for a while (see #53 and #1). However, I don't know how seen that would possibly be without some help.

@jrg94 jrg94 added the enhancement New feature or request label Dec 28, 2023
@gha88
Copy link
Author

gha88 commented Dec 28, 2023

How would you like to implement it?
Are you thinking to embed an external parsing library (creating a dependency) or to create a minimal internal parser?

Would you parse to fix this issue only or do you have some other issues or cases to parse on?

Maybe I could help you but it depends on the effort

@jrg94
Copy link
Member

jrg94 commented Jan 1, 2024

Ideally, I would like to avoid adding external libraries altogether. That said, I've recently dabbled with templates in the library, and I think it would be possible to implement a 3rd-party template with external dependencies. In other words, someone could make their own library that could be imported separately as an extension of SnakeMD. I've written a little about how that would work here.

Alternatively, we could write a parser in SnakeMD to parse markdown into Elements. The original idea for that was to be able to parse raw blocks, so we could import existing markdown files (e.g., headers, footers, etc.). I think it would have a lot of use cases regardless.

A wild third option would be to create an alternative implementation of the Table of Contents objects, which just scans the rendered document for headings on each line (#, ##, ...). There could even be an optional parameter for this on the existing table of contents, which turns on a parsing mode.

@gha88
Copy link
Author

gha88 commented Jan 7, 2024

In my specific case, to solve the problem, I'm going to develop a custom renderer from mistletoe library that I'm already using in the project.

The idea is to inject the SnakeMd document in the custom renderer.
Make a custom renderer in this way should be far less difficult than create it from zero.

I think the raw block in snake md is good as is because for example you can use it to avoid some headers from the table of contents (the opposite of my problem).

I don't know if you could be interested in someway about this custom renderer. Maybe it can be considered as a plugin or something similar.

In that case let me know.

@jrg94
Copy link
Member

jrg94 commented Jan 11, 2024

I'd be interested just to see what you're doing! I'm not sure how much collaboration we can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants