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

Automatically generate ids for headers #364

Open
elliottslaughter opened this issue Oct 3, 2020 · 3 comments
Open

Automatically generate ids for headers #364

elliottslaughter opened this issue Oct 3, 2020 · 3 comments

Comments

@elliottslaughter
Copy link

I know that this issue was not yet resolved in the spec, but it could potentially be done in an implementation-specific way that does not violate the spec. This is a very useful feature and has been requested both on the forum and elsewhere (see e.g.: github#186).

Would it be in scope to add such an extension to cmark? Is this better sent to a forked implementation like cmark-gfm?

@jgm
Copy link
Member

jgm commented Oct 5, 2020

I'm not dead-set against adding extensions here; after all, we have smart quotes.

@iarthair
Copy link

This is not a show-stopper in my use case, but I feel it would be useful to allow elements to have id's since both HTML and XML allow any element to have an id.

Rather than generating these automatically, how about adding APIs to cmark_node to get or explicitly set an id and modifying the respective rendering code to add id="name" attributes to affected nodes? For example:

  • const char *cmark_node_get_id(cmark_node *node);
  • int cmark_node_set_id(cmark_node *node, const char *id);

Then it would be simple for an application to traverse the parse tree prior to rendering, say, to generate a table of contents, looking for interesting nodes to reference, not necessarily headings. Furthermore using this approach, the ids can be generated by and meaningful to the appplication.

@iarthair
Copy link

I have forked a proof of concept at https://github.com/iarthair/cmark on the branch node-id-api.

I'll post a simple program that uses it later, my test case was a hack to a larger application. I have an equivalent patch for cmark-gfm which I'll deal with in due course.

There's a few issues to sort, mainly it's only done for HTML and the id attribute is written out in the "wrong" function.

Perhaps this is the way to go?

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

No branches or pull requests

3 participants