Conversation
Add an id attribute to every HTML heading (h1-h6), enabled with the MD_FLAG_HEADINGIDS extension flag. The id is derived from the heading text: ASCII letters are lowercased, digits are kept, and every run of other characters is replaced with a single dash (trailing dash trimmed). Only the first 64 bytes of heading text contribute to the id; the full heading is still rendered. Deduplication is left to the caller. Implementation lives entirely in the HTML renderer (md4c-html.c): while a heading is open, rendered content is diverted into a growable buffer and the heading text is mirrored into a fixed-size slug buffer. On leave, the opening tag (with id), buffered content and closing tag are emitted in order. No changes to the parser (md4c.c) or the public detail structs. Adds a --fheading-ids option to md2html. Co-authored-by: rnkn <rnkn@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a LLM-generated patch.
This adds an id attribute to h1-h6 elements, enabled with the MD_FLAG_HEADINGIDS extension. The id is derived from the heading text: ASCII letters are lowercased, digits are kept, and every other character is replaced with a dash. Only the first 64 bytes of heading text contribute to the id. Deduplication is left to the caller.
Implementation lives in md4c-html.c: while a heading is open, rendered content is diverted into a growable buffer and the heading text is mirrored into a fixed-size buffer. On leave, the opening tag (with id), buffered content and closing tag are emitted in order. No changes to md4c.c.
Adds a --fheading-ids option to md2html.
I had a few go arounds with the ideal implementation and this seemed the only viable option. The introduction of a buffer means md4c would no longer be stack-only, so there's that. It introduces a dependency on
stdlib.hand bloatsMD_HTML_tagstruct considerably.It works during my testing but given this is LLM-generated code and my understanding of C is limited I can perfectly understand if you reject it outright. Maybe it could be worth some ideas.