Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Use semantic HTML <nav> element to wrap table of contents #614

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -1056,14 +1056,14 @@ contents according to the current heading."
(push "has-section-numbers" toc-classes))
(when local
(push "local" toc-classes))
(concat (format "<div class=\"%s\">\n" (string-join (reverse toc-classes) " "))
(concat (format "<nav class=\"%s\">\n" (string-join (reverse toc-classes) " "))
(unless (org-hugo--plist-get-true-p info :hugo-goldmark)
"<div></div>\n") ;This is a nasty workaround till Hugo/Blackfriday support
"<nav></nav>\n") ;This is a nasty workaround till Hugo/Blackfriday support
toc-heading ;wrapping Markdown in HTML div's.
"\n"
toc-items ;https://github.com/kaushalmodi/ox-hugo/issues/93
"\n\n"
"</div>\n"
"</nav>\n"
;; Special comment that can be use to filter out the TOC
;; from .Summary in Hugo templates.
;;
Expand Down
4 changes: 2 additions & 2 deletions test/site/content/dir-locals-test/dir-locals-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ draft: false
creator: "Dummy creator string"
---

<div class="ox-hugo-toc toc has-section-numbers">
<nav class="ox-hugo-toc toc has-section-numbers">

<div class="heading">Table of Contents</div>

- <span class="section-num">1</span> [Variables set in <kbd>.dir-locals.el</kbd>](#variables-set-in-dot-dir-locals-dot-el)
- <span class="section-num">2</span> [Test text](#test-text)

</div>
</nav>
<!--endtoc-->


Expand Down
4 changes: 2 additions & 2 deletions test/site/content/posts/link-to-headings-by-name.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tags = ["links", "internal-links", "toc", "headings", "export-option"]
draft = false
+++

<div class="ox-hugo-toc toc has-section-numbers">
<nav class="ox-hugo-toc toc has-section-numbers">

<div class="heading">Table of Contents</div>

Expand All @@ -16,7 +16,7 @@ draft = false
- [Zeta 103 which has **some** _markup_](#zeta-103-which-has-some-markup)
- [Links (no descriptions) to headings with section numbers](#links--no-descriptions--to-headings-with-section-numbers)

</div>
</nav>
<!--endtoc-->


Expand Down
4 changes: 2 additions & 2 deletions test/site/content/posts/no-toc-in-summary-with-more.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ tags = ["export-option", "toc", "summary", "endtoc", "more"]
draft = false
+++

<div class="ox-hugo-toc toc">
<nav class="ox-hugo-toc toc">

<div class="heading">Table of Contents</div>

- [`ox-hugo`'s Solution](#ox-hugo-s-solution)
- [Snippet](#snippet)

</div>
</nav>
<!--endtoc-->

By default, Hugo will dump everything at the beginning of a post into
Expand Down
4 changes: 2 additions & 2 deletions test/site/content/posts/no-toc-in-summary-without-more.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ tags = ["export-option", "toc", "summary", "endtoc"]
draft = false
+++

<div class="ox-hugo-toc toc">
<nav class="ox-hugo-toc toc">

<div class="heading">Table of Contents</div>

- [`ox-hugo`'s Solution](#ox-hugo-s-solution)
- [Snippet](#snippet)

</div>
</nav>
<!--endtoc-->

By default, Hugo will dump everything at the beginning of a post into
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ tags = ["export-option", "toc"]
draft = false
+++

<div class="ox-hugo-toc toc has-section-numbers">
<nav class="ox-hugo-toc toc has-section-numbers">

<div class="heading">Table of Contents</div>

- <span class="section-num">1</span> [Post sub-heading 1](#post-sub-heading-1)
- <span class="section-num">2</span> [Post sub-heading 2](#post-sub-heading-2)
- <span class="section-num">3</span> [Post sub-heading 3](#post-sub-heading-3)

</div>
</nav>
<!--endtoc-->


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tags = ["export-option", "toc"]
draft = false
+++

<div class="ox-hugo-toc toc">
<nav class="ox-hugo-toc toc">

<div class="heading">Table of Contents</div>

Expand All @@ -18,7 +18,7 @@ draft = false
- [Post sub-heading 3](#post-sub-heading-3)
- [Post sub-heading 3.1](#post-sub-heading-3-dot-1)

</div>
</nav>
<!--endtoc-->


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tags = ["export-option", "toc"]
draft = false
+++

<div class="ox-hugo-toc toc has-section-numbers">
<nav class="ox-hugo-toc toc has-section-numbers">

<div class="heading">Table of Contents</div>

Expand All @@ -18,7 +18,7 @@ draft = false
- <span class="section-num">3</span> [Post sub-heading 3](#post-sub-heading-3)
- <span class="section-num">3.1</span> [Post sub-heading 3.1](#post-sub-heading-3-dot-1)

</div>
</nav>
<!--endtoc-->


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tags = ["export-option", "toc"]
draft = false
+++

<div class="ox-hugo-toc toc">
<nav class="ox-hugo-toc toc">

<div class="heading">Table of Contents</div>

Expand All @@ -22,7 +22,7 @@ draft = false
- [Post sub-heading 3](#post-sub-heading-3)
- [Post sub-heading 3.1](#post-sub-heading-3-dot-1)

</div>
</nav>
<!--endtoc-->


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tags = ["export-option", "toc"]
draft = false
+++

<div class="ox-hugo-toc toc has-section-numbers">
<nav class="ox-hugo-toc toc has-section-numbers">

<div class="heading">Table of Contents</div>

Expand All @@ -22,7 +22,7 @@ draft = false
- <span class="section-num">3</span> [Post sub-heading 3](#post-sub-heading-3)
- <span class="section-num">3.1</span> [Post sub-heading 3.1](#post-sub-heading-3-dot-1)

</div>
</nav>
<!--endtoc-->


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tags = ["export-option", "toc"]
draft = false
+++

<div class="ox-hugo-toc toc has-section-numbers">
<nav class="ox-hugo-toc toc has-section-numbers">

<div class="heading">Table of Contents</div>

Expand All @@ -22,7 +22,7 @@ draft = false
- <span class="section-num">3</span> [Post sub-heading 3](#post-sub-heading-3)
- <span class="section-num">3.1</span> [Post sub-heading 3.1](#post-sub-heading-3-dot-1)

</div>
</nav>
<!--endtoc-->


Expand Down
4 changes: 2 additions & 2 deletions test/site/content/posts/post-with-toc-keyword-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tags = ["keyword", "toc"]
draft = false
+++

<div class="ox-hugo-toc toc">
<nav class="ox-hugo-toc toc">

<div class="heading">Table of Contents</div>

Expand All @@ -18,7 +18,7 @@ draft = false
- [Post sub-heading 3](#post-sub-heading-3)
- [Post sub-heading 3.1](#post-sub-heading-3-dot-1)

</div>
</nav>
<!--endtoc-->


Expand Down
4 changes: 2 additions & 2 deletions test/site/content/posts/post-with-toc-keyword-6.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tags = ["keyword", "toc"]
draft = false
+++

<div class="ox-hugo-toc toc">
<nav class="ox-hugo-toc toc">

<div class="heading">Table of Contents</div>

Expand All @@ -22,7 +22,7 @@ draft = false
- [Post sub-heading 3](#post-sub-heading-3)
- [Post sub-heading 3.1](#post-sub-heading-3-dot-1)

</div>
</nav>
<!--endtoc-->


Expand Down
20 changes: 10 additions & 10 deletions test/site/content/posts/toc-local.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ draft = false

Below, TOC is exported with only level-1 headings in this post.

<div class="ox-hugo-toc toc">
<nav class="ox-hugo-toc toc">

<div class="heading">Table of Contents</div>

- [Post sub-heading 1](#post-sub-heading-1)
- [Post sub-heading 2](#post-sub-heading-2)
- [Post sub-heading 3](#post-sub-heading-3)

</div>
</nav>
<!--endtoc-->

Below exported TOC should look the same as above even when it's
generated using the `local` param as it is at the root level of this
post.

<div class="ox-hugo-toc toc local">
<nav class="ox-hugo-toc toc local">

- [Post sub-heading 1](#post-sub-heading-1)
- [Post sub-heading 2](#post-sub-heading-2)
- [Post sub-heading 3](#post-sub-heading-3)

</div>
</nav>
<!--endtoc-->


Expand All @@ -41,13 +41,13 @@ post.
Below, TOC is exported with only level-1 headings **relative to** this
"Post sub-heading 1" section.

<div class="ox-hugo-toc toc local">
<nav class="ox-hugo-toc toc local">

- [Post sub-heading 1.1](#post-sub-heading-1-dot-1)
- [Post sub-heading 1.2](#post-sub-heading-1-dot-2)
- [Post sub-heading 1.3](#post-sub-heading-1-dot-3)

</div>
</nav>
<!--endtoc-->


Expand All @@ -74,15 +74,15 @@ Below, TOC is exported with only level-1 headings **relative to** this
Below, TOC is exported with only up to level-2 headings **relative to**
this "Post sub-heading 2.2" section.

<div class="ox-hugo-toc toc local">
<nav class="ox-hugo-toc toc local">

- [Post sub-heading 2.2.1](#post-sub-heading-2-dot-2-dot-1)
- [Post sub-heading 2.2.2](#post-sub-heading-2-dot-2-dot-2)
- [Post sub-heading 2.2.3](#post-sub-heading-2-dot-2-dot-3)
- [Post sub-heading 2.2.3.1](#post-sub-heading-2-dot-2-dot-3-dot-1)
- [Post sub-heading 2.2.3.2](#post-sub-heading-2-dot-2-dot-3-dot-2)

</div>
</nav>
<!--endtoc-->


Expand All @@ -97,12 +97,12 @@ this "Post sub-heading 2.2" section.
Below, TOC is exported with only level-1 headings **relative to** this
"Post sub-heading 2.2.3" section.

<div class="ox-hugo-toc toc local">
<nav class="ox-hugo-toc toc local">

- [Post sub-heading 2.2.3.1](#post-sub-heading-2-dot-2-dot-3-dot-1)
- [Post sub-heading 2.2.3.2](#post-sub-heading-2-dot-2-dot-3-dot-2)

</div>
</nav>
<!--endtoc-->


Expand Down
8 changes: 4 additions & 4 deletions test/site/content/posts/toc-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ draft = false

### landing page {#landing-page}

<div class="ox-hugo-toc toc">
<nav class="ox-hugo-toc toc">

<div class="heading">Table of Contents</div>

- [landing page](#landing-page)
- [first subsection in Reading](#first-subsection-in-reading)

</div>
</nav>
<!--endtoc-->


Expand All @@ -43,12 +43,12 @@ draft = false

### Another section {#another-section}

<div class="ox-hugo-toc toc">
<nav class="ox-hugo-toc toc">

<div class="heading">Table of Contents</div>

- [Heading A](#heading-a)
- [Heading B](#heading-b)

</div>
</nav>
<!--endtoc-->
4 changes: 2 additions & 2 deletions test/site/content/posts/toc-with-todo-disabled.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ tags = ["export-option", "toc", "todo", "disable"]
draft = false
+++

<div class="ox-hugo-toc toc">
<nav class="ox-hugo-toc toc">

<div class="heading">Table of Contents</div>

- [No TODO state](#no-todo-state)
- [Something to do](#something-to-do)
- [Something done](#something-done)

</div>
</nav>
<!--endtoc-->

<style>
Expand Down
4 changes: 2 additions & 2 deletions test/site/content/posts/toc-with-todo-enabled.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ tags = ["export-option", "toc", "todo", "enable"]
draft = false
+++

<div class="ox-hugo-toc toc">
<nav class="ox-hugo-toc toc">

<div class="heading">Table of Contents</div>

- [No TODO state](#no-todo-state)
- [<span class="org-todo todo TODO">TODO</span> Something to do](#something-to-do)
- [<span class="org-todo done DONE">DONE</span> Something done](#something-done)

</div>
</nav>
<!--endtoc-->

<style>
Expand Down
4 changes: 2 additions & 2 deletions test/site/content/real-examples/nn-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Disclaimer

---

<div class="ox-hugo-toc toc">
<nav class="ox-hugo-toc toc">

<div class="heading">Table of Contents</div>

Expand All @@ -35,7 +35,7 @@ Disclaimer
- [代价函数:交叉熵](#代价函数-交叉熵)
- [规范化](#规范化)

</div>
</nav>
<!--endtoc-->

神经网络相关基本知识笔记
Expand Down