zola icon indicating copy to clipboard operation
zola copied to clipboard

Inline code (from backticks) should be preserved in TOC title

Open jhpratt opened this issue 1 year ago • 3 comments

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.

jhpratt avatar Sep 03 '22 23:09 jhpratt

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.

jhpratt avatar Sep 04 '22 06:09 jhpratt

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.

Keats avatar Sep 04 '22 11:09 Keats

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.

jhpratt avatar Sep 04 '22 13:09 jhpratt

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.

radekmie avatar Sep 27 '22 12:09 radekmie

@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.

jhpratt avatar Oct 05 '22 00:10 jhpratt

That's fine I think

Keats avatar Oct 10 '22 09:10 Keats