Skip to content

Commit

Permalink
Make the "Table of Contents" heading a div element instead of h2
Browse files Browse the repository at this point in the history
Hard-coding the "Table of Contents" heading to h2 now looked like a
bad idea.. it seems semantically incorrect. So now it is a div tag.

This also allows more flexibility on how to show that "Table of
Contents" heading.  See
https://ox-hugo.scripter.co/doc/org-toc/#table-of-contents-heading
for more info.

This is a "breaking change" in the sense that that heading will no
longer auto-render looking like a heading. So user might need to add
some CSS to make it look just like before. See example CSS in the
above doc link.
  • Loading branch information
kaushalmodi committed Jun 13, 2018
1 parent 85b19cc commit 1afb24a
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 17 deletions.
13 changes: 13 additions & 0 deletions doc/ox-hugo-manual.org
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,19 @@ See Org manual [[https://orgmode.org/manual/Table-of-contents.html][Table of Con

/Note that =ox-hugo= does not support =#+toc: listings= and =#+toc:
tables=./
**** "Table of Contents" heading
The "Table of Contents" heading is inserted as a plain HTML ~div~
element. Users can customize the looks of that ~div~ by setting CSS
rules for ~.ox-hugo-toc .heading~.

Here is an example CSS rule for that:
#+begin_src css
.ox-hugo-toc .heading {
font-size: 1.8em;
font-weight: bold;
text-align: center;
}
#+end_src
**** Excluding Org-generated TOC from Hugo summaries
As mentioned above, if you use Hugo-generated TOC, the advantage is
that the TOC is not inserted physically in the content Markdown
Expand Down
6 changes: 2 additions & 4 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -995,10 +995,8 @@ When optional argument LOCAL is non-nil, build a table of
contents according to the current headline."
(let* ((toc-headline
(unless local
(let ((style (plist-get info :md-headline-style))
(loffset (string-to-number (plist-get info :hugo-level-offset)))
(title (org-html--translate "Table of Contents" info)))
(org-hugo--headline-title style 1 loffset title))))
(format "\n<div class=\"heading\">%s</div>\n\n"
(org-html--translate "Table of Contents" info))))
(toc-items
(mapconcat
(lambda (headline)
Expand Down
2 changes: 1 addition & 1 deletion test/site/content/posts/link-to-headings-by-name.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

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

- [Alpha 101](#alpha-101)
- <span class="section-num">1</span> [Beta 102](#beta-102)
Expand Down
2 changes: 1 addition & 1 deletion test/site/content/posts/no-toc-in-summary--with-more.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

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

- [`ox-hugo`'s Solution](#ox-hugo-s-solution)
- [Snippet](#snippet)
Expand Down
2 changes: 1 addition & 1 deletion test/site/content/posts/no-toc-in-summary--without-more.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

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

- [`ox-hugo`'s Solution](#ox-hugo-s-solution)
- [Snippet](#snippet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

## Table of Contents
<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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

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

- [Post sub-heading 1](#post-sub-heading-1)
- [Post sub-heading 1.1](#post-sub-heading-1-dot-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

## Table of Contents
<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">1.1</span> [Post sub-heading 1.1](#post-sub-heading-1-dot-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

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

- [Post sub-heading 1](#post-sub-heading-1)
- [Post sub-heading 1.1](#post-sub-heading-1-dot-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

## Table of Contents
<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">1.1</span> [Post sub-heading 1.1](#post-sub-heading-1-dot-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

## Table of Contents
<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">1.1</span> [Post sub-heading 1.1](#post-sub-heading-1-dot-1)
Expand Down
2 changes: 1 addition & 1 deletion test/site/content/posts/post-with-toc-keyword-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

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

- [Post sub-heading 1](#post-sub-heading-1)
- [Post sub-heading 1.1](#post-sub-heading-1-dot-1)
Expand Down
2 changes: 1 addition & 1 deletion test/site/content/posts/post-with-toc-keyword-6.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

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

- [Post sub-heading 1](#post-sub-heading-1)
- [Post sub-heading 1.1](#post-sub-heading-1-dot-1)
Expand Down
2 changes: 1 addition & 1 deletion test/site/content/posts/toc-with-todo-disabled.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

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

- [No TODO state](#no-todo-state)
- [Something to do](#something-to-do)
Expand Down
2 changes: 1 addition & 1 deletion test/site/content/posts/toc-with-todo-enabled.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ draft = false
<div class="ox-hugo-toc toc">
<div></div>

## Table of Contents
<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)
Expand Down

0 comments on commit 1afb24a

Please sign in to comment.