data-science 2024-05-05

When creating a Quarto book from Clay notebooks I noticed that some of my level 3 headings were not appearing in the table of contents. The ones that were not appearing are being created with kind/hiccup. I believe the reason is because https://github.com/scicloj/clay/blob/44cf5a746d2cfcac90496838b5b82b60ce4c8b84/src/scicloj/clay/v2/prepare.clj#L56. Outside a Quarto book it ends up as <div style="margin:15px;"><h3>An H3 In kind/hiccup</h3></div>. The headings created from ; ### Three Hashes As Clj Comment or (kind/md "### Three Hashes In kind/md") end up as HTML with an extra nested DIV, like this: <div style="margin:15px;"><div><h3 id="three-hashes-in-kind/md">Three Hashes In kind/md</h3></div></div>. These can be seen in the table of contents when a Quarto book is built. I believe the extra DIV comes from the https://github.com/nextjournal/markdown parsing. Example:

(nextjournal.markdown.transform/->hiccup
    (nextjournal.markdown/parse "### Three Hashes"))
=> [:div [:h3 {:id "three-hashes"} "Three Hashes"]]
Additionally, inside a Quarto book, the heading created with kind/hiccup does not seem to cause an HTML section. Headings created from Clojure comments or kind/md are wrapped in section tags. My guess is that Quarto is using the sections to help create the table of contents, maybe. My attempts to manually wrap my heading with a section have failed to have that heading appear in the table of contents. Does anyone have any experience with this and know how to get headings created with kind/hiccup to appear in a Quarto book's table of contents? Also, let me know if my description is unclear.

@daslu, wow, thank you for following up on this! I was pretty sure I had :toc-depth 4 and :toc-expand true in my clay.edn file. Attached is a minimal example that, hopefully, demonstrates what I am seeing. When I eval this form,

(clay/make!
  {:show             false
   :run-quarto       false
   :format           [:quarto :html]
   :book             {:title "Notebooks"}
   :base-source-path "notebooks"
   :base-target-path "docs"
   :subdirs-to-sync  ["notebooks"]
   :source-path      [
     "test.clj"
                      ]
   })
in my REPL, then run quarto render --to html from a terminal in the docs/ directory I get an HTML page that looks like the attached quarto-toc.png in my browser. My Quarto version is:
$ quarto --version
1.5.10

Using :toc-expand 4 in clay.edn results in the same HTML. This is true regardless of whether :toc-depth 4 is also in clay.edn or not.

It is so helpful to have such bug reports. I'll look, thanks.

And you are right, the problem does appear in Quarto's behaviour with the .qmd file that you shared earlier, even with toc-expand: 4, etc. I did not look carefully.

I'll open https://github.com/quarto-dev/quarto-cli/issues (or would you prefer to be the one opening it?). Then, if the problem is now preventing you from doing something that you need, let us look for a workaround.

It is not preventing me from doing anything. I thought I might be doing something wrong and wanted to learn how to do it right.

I do not mind opening the issue. I don't want to burden you further. Thank you for your help in investigating!

Many thanks again for your insightful help.

Thanks for narrowing it down, I see. This used to be a bug, which is fixed in Quarto pre-release 1.5.10. https://github.com/quarto-dev/quarto-cli/releases/tag/v1.5.10 I recommend using this version. (More recent pre-releases may also work for you, but they seem to create another problem that I still do not understand, and you may or may not experience.)

I am seeing the same (hiccup H3 not in TOC) behavior with 1.5.10

$ quarto --version
1.5.10

Thanks. Anyway it is good that you've updated, to avoid other =html --related problems. I'll try to open a Quarto issue later today/tomorrow and see what the Quarto devs say.

Hi @jason1903, sorry it took me some time to get back to this thread. Trying to reproduce the problem now, I see that Quarto's table of contents is kind of folded by default, not showing all levels. Scrolling the page to the relevant section seems to unfold the relevant sections and showing them in the table of contents. For example, you may try scrolling through https://scicloj.github.io/tablecloth/ and see what happens. In a page that is so small it appears fully over the screen, there is no scrollbar, so it seems impossible to get this effect, at least in my browser. You may expand more levels by default using, e.g., toc-expand: 4. In Clay, you can add this to your config using {:quarto {:format {:html {:toc-expand 4}}}} in your clay.edn file. Does it work for you?

Thanks for the tip about looking in the .qmd file. If it helps, the headings in the .qmd file look like this:

# One Hash

## Two Hashes

### Three Hashes As Clj Comment

### Three Hashes In `kind/md`

{=html} <div><h3>An H3 In kind/hiccup</h3></div>
The one that does not show in the TOC is the last one, inside the code fencing.

The answers at https://github.com/quarto-dev/quarto-cli/issues/9738 are saying the problem is with how the .qmd file is generated. Quarto (really Pandoc) only build entries for the table of contents from Markdown headings (`#`, ###, etc...). Since kind/hiccup produces HTML it will never be able to create Quarto TOC entries.

Thank you so much, @jason1903. Very enlightening discussion!

Hi @jason1903. Thanks for reporting and investigating. I see it happens in my environment too. I use Quarto version 1.5.10 pre-release (since it fixes some other bugs). Trying the this qmd document:

---
format:
  html:
    toc: true
---

# A

## AB

### ABC
I get the following page, where ABC does not appear in the table of contents.

By the way, when you investigates such situations in Clay, it may help to look into the .qmd file generated alongside your .HTML file. This is the intermediate Quarto document generated by Clay and processed by Quarto.

👍 1

Opened an issue in Clay: https://github.com/scicloj/clay/issues/100 After learning a bit more, we may open an issue in Quarto.