metanorma / coradoc

Coradoc is the Core AsciiDoc Parser used by Metanorma
MIT License
1 stars 2 forks source link

Re-number anchors? #83

Open ronaldtse opened 5 years ago

ronaldtse commented 5 years ago

User:

HTML IDs for the document sections appear to be inconsistent.

We can enable an option for "renumbering anchors" so that they make more sense than the Word way?

opoudjis commented 5 years ago

I will need a lot more information than this.

ronaldtse commented 5 years ago

Today the gem adopts the Word anchors in AsciiDoc, which are not very descriptive and sometimes very random. It might be easier to use the "section name" or the "clause number" for anchor names?

opoudjis commented 4 years ago

So, to do this:

We will introduce a new config option to the gem, like -e, with "renumber sections"

If this option is on, we will ignore the existing ids of all headings, and replace them with a new id for each heading, hierarchically assigned and numbered. So, we would assign the id section_4_1_2 for the second subsubsection of the first subsection of the fourth section.

We will also need to change all existing crossreferences to those anchors to the new ids.

And because we cannot guarantee anything about format of section titles, there can be no attempt to introduce appendix numbering: this has to be strictly numeric increments.

This is not an in-place modification. It is either preprocessing the HTML, or postprocessing the asciidoc. And because in both instances the ids are attached to milestones (headings) and not sections per se, the hierarchical processing will be messy.

I'd suggest it as postprocessing. So convert:

= Title
X

[[id1]]
== A

[[id2]]
=== B
<<id3,text>>

[[id3]
==== C

[[id4]]
=== D

would be changed to

= Title
X

[[section_1]]
== A

[[section_1_1]]
=== B
<<section_1_1_1,text>>

[[section_1_1_1]]
==== C

[[section_1_2]]
=== D
ronaldtse commented 4 years ago

Since the proposed solution suggests textual replacements, it will be hard to maintain.

We're going to take the approach of HTML -> BasicDoc -> Adoc. So going to demote this ticket until we have BasicDoc -> Adoc.