TableOfContents with passthrough extension: empty list item

Minimal working example

A markdown page with one single section:

## \(\TeX\)

PAGE.TableOfContents from this page looks like:

<nav id=\"TableOfContents\">
  <ul>
    <li>
      <a href=\"#tex\">(\\TeX)</a>
    </li>
  </ul>
</nav>

The single list item has the content (\\TeX), this is correct according to the commonmark spec for backslash escapes.

Now I enable the goldmark passthrough extension in my config file:

markup:
  goldmark:
    extensions:
      passthrough:
        enable: true
        delimiters:
          inline: [['\(', '\)']]

Now the PAGE.TableOfContents from this page now looks like this:

<nav id=\"TableOfContents\">
  <ul>
    <li>
      <a href=\"#tex\"></a>
    </li>
  </ul>
</nav>

Actual:

There is no inner content for the single list item.

Expected:

The inner content of the single list item should be \(\\TeX\).

Any help how to make this work is appreciated.

No Solution but maybe helps for someone to analyze

with passthrough

{{ debug.Dump .Fragments.Headings }}
{
  "tex": {
    "ID": "tex",
    "Level": 2,
    "Title": "",
    "Headings": null
  }
}
RenderHook: render-heading.html
<h{{ .Level }} id="{{ .Anchor }}" {{- with .Attributes.class }} class="{{ . }}" {{- end }}>
   {{ warnf "HEAD: %s" .Text }}
   {{ warnf "PLAIN: %s" .PlainText }}
  TEXT: {{ .Text -}}
  <hr/>
  PLAINTEXT: {{ .PlainText -}}
  {{- .Text -}}
</h{{ .Level }}>
WARN  HEAD: \(\TeX\)
WARN  PLAIN:                               <-- empty

without passthrough

{
  "tex": {
    "ID": "tex",
    "Level": 2,
    "Title": "(\\TeX)",
    "Headings": null
  }
}
WARN  HEAD: (\TeX)
WARN  PLAIN: \(\TeX\)

See https://github.com/gohugoio/hugo/issues/12491.

Until this is addressed, continue to double-escape your expressions when placing them in a heading when using .Page.TableOfContents .

git clone --single-branch -b hugo-forum-topic-53532 https://github.com/jmooring/hugo-testing hugo-forum-topic-53532
cd hugo-forum-topic-53532
hugo server

Thanks for the advice. Double-escaping solved the issue, indeed.

1 Like

I just realized that this advice cures the problem only when doing client side rendering of formulae with KaTeX. When doing server side rendering with transform.ToMath, a double-escaped expression is not rendered, but is printed as-is. Any way to work around this know issue when using transform.ToMath?

I don’t know of any way around this. I’ve updated the issue accordingly:
https://github.com/gohugoio/hugo/issues/12491#issuecomment-2661535599

I also tried using tocbot.js instead. It failed, but differently.

I was curious how GitHub handles this…

markup:

# Test TOC

## S1: $\sqrt{3x-1}+(1+x)^2$

## S2: [link](/a/b/)

## S3: some **bold** text

rendered (including their TOC):

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.