zola
zola copied to clipboard
Inline code (from backticks) should be preserved in TOC title
Bug Report
Environment
Zola version: 0.16.1
Behavior
A section with the title `.into::<T>()`
should result in <code>.into::<T>()</code>
being generated for the TOC title. Currently, it generates .into::()
. I believe the <T>
is stripped because user-provided HTML is stripped (which has issues on its own). However, I would like the <code>
to be preserved outright. It affects formatting — it should be monospace while regular text is not. This is deliberate and desired behavior.
Actually, it looks like the <T>
missing is just a result of the way I was debugging it (dumping it inside <pre><code>
). However, the main point still stands: <code>
should be output for inline blocks in this situation.
The TOC only keeps the text because otherwise you end up in weird situations: imagine you have a link instead of code
. Most TOCs do link out to the section so you end up with links where the body is another link. It's also sometimes used in JS so it's easier to not have HTML in them.
Removing the links inside of that is, of course, appropriate and expected given the context. Removing <code>
potentially changes the way something can be interpreted, and definitely alters the display. So far as I can tell there's no way to preserve this even if I wanted to. It's trivial for a user to pass it through | striptags
if they want to get rid of them, but impossible to get them back when actually desired.
Maybe striptags
could be altered to accept an optional list of tags to strip, leaving everything else in tact? Just throwing out an idea...no idea how feasible it would be.
Or maybe in addition to .title
it could include a .formattedTitle
or a similar property? In some contexts it's desired to preserve the formatting, e.g., italics.
@Keats ^^ would you be open to this? It should be pretty simple to do — I'll put a PR together if you're down.
As I think about this some, having a raw_title
field would be the most sensible I think. Then it can be handled however the user wants, including rendering and stripping.
That's fine I think