jgarber / redcloth

RedCloth is a Ruby library for converting Textile into HTML.
Other
443 stars 113 forks source link

Feature: Automatically add an ID to headings (for dynamic TOC/ anchors) #85

Open mohits opened 8 months ago

mohits commented 8 months ago

Hi, I am using a theme with Jekyll that automatically uses JS to create a table of contents (TOC) to have anchors within the page. This requires that each heading have an ID.

RedCloth can add an ID to a heading if you provide one. I'm trying to see if this could be done automatically for all headings. On my PC, I have made a small change that makes it work - it adds an ID automatically if there isn't one provided.

(1) Would there be interest to merge this upstream? (2) I want to see if I can put this behind a configuration so that the default works the same unless you specify auto_heading_ids but right now, I have not got far enough into the code to be sure that it works. It would be great if you point me to something.

If there is interest, then I can try to make this available and add a spec for the ability.

heliocola commented 8 months ago

@mohits : thanks for opening this. See below my answers:

(1) Would there be interest to merge this upstream?

I am yet not a heavy user of this gem like you and others that have opened issues and PR in the past several years, but if you think this will add value I am open to work with you.

(2) I want to see if I can put this behind a configuration...

I think that is a good idea to keep backward compatibility, but again I am not very familiar with the gem.

I also want to tackle #49 and #19, so maybe the configuration will help us have a better migration path for that as well.

I will focus on some cleanups I want to do, since the last release, release a new version, work to merge #83 , and I think that will give you some time to get your machine up & running! So,

mohits commented 8 months ago

Thanks @heliocola for all your work on this.

I managed to figure out what is needed to support it behind a configuration (and the downstream changes in the jekyll-textile-converter gem that integrates RedCloth with Jekyll), so I can definitely get this done. I will slowly work on getting the spec and other things prepared for a PR while also getting my VM up and running to get back to what I had started.

I think I now know how to add config flags into RedCloth and can see if that can be extended to #49 and #19,