libasciidoc
libasciidoc copied to clipboard
Natural internal cross reference gets changed to lowercase outside of the template
I am building a custom backend based of the sgml
group. Basically a custom copy of the xhtml one. I was able to build a document setting:
:idprefix:
:idseparator: -
See <<My natural Link>>
== My natural Link
With those attributes set, I was expecting my cross reference to be something like #My-natural-Link
but it got automatically lower cased.
The casing information is lost by the time you get to the template rendering. From the example above, you can't ensure that upcasing the first letter is enough.
Is there a way to not automatically lowercase the reference in the code and leave it to the template? You probably would have to add a ToLower
funcMap for the template to be able to do it.
Asciidoctor doesn't have an extra attribute to control casing of the section IDs so it is probably not worth introducing one if you leave to the template but that would do it too. https://docs.asciidoctor.org/asciidoc/latest/sections/id-prefix-and-separator/
The code that lowercases the ID is here: https://github.com/bytesparadise/libasciidoc/blob/e12e66011b03f24f05e04013767a867127be2bdb/pkg/types/non_alphanumerics_replacement.go#L68
Removing that strings.ToLower fixes things for me but breaks a few tests obviously. Let me know how you would like to proceed. I could draft a PR based on that.
@DavidGamba first, sorry for the late response!
I intentionally used the strings.ToLower
func in order to mimic what Asciidoctor does when rendering the content (ie, generate href
value with lowercase. In other words, the example you provided above results in with both Asciidoctor and libasciidoc (except for the empty line in the central <div>
but that's a detail):
<div class="paragraph">
<p>See <a href="#my-natural-link">My natural Link</a></p>
</div>
<div class="sect1">
<h2 id="my-natural-link">My natural Link</h2>
<div class="sectionbody">
</div>
</div>
@xcoulon thanks for getting back to me.
Yes, your implementation is correct for HTML content were the ID for the refs need to be lowercased. In my case, since I am building a non HTML backend based on the sgml base then having the IDs become lowercase is actually breaking my links.
Since the HTML requires the links to be lowercased I was hoping we could move the lowercase function all the way to the template instead of at the code line I pointed to. This would still render the final code for HTML as lowercase but it would also allow me to reuse everything else as I have been already and not lowercase those links in my template.
What do you think?
Hello @DavidGamba
Oh, I see what you mean now. I think I missed the point where you mentioned your custom backend! 🤦♂️
I'm not sure if it's going to break anything related the cross references validation if we move the lower-casing into the templates, but it's worth trying. Would you like to open a PR for this?