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

fix!: html validation: Do not export <style> elements above TOC #613

Merged
merged 1 commit into from
Apr 6, 2022
Merged
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
11 changes: 11 additions & 0 deletions doc/ox-hugo-manual.org
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,17 @@ tries to get the "summary you mean". This partial is used by the
/Note that you would need to use the =summary_minus_toc.html= partial
wherever you do not intend to have TOC included in the summary (for
example, in the Opengraph =og:description= meta tag)./
**** Hiding bullets when TOC has numbered headings
Add this to the CSS to hide bullets in table of contents when the
headings are numbered. Export options set like ~#+options: toc:t
num:t~ will cause this.

#+begin_src css
/* Hide bullets in TOC when headings are numbered. */
.toc.has-section-numbers ul {
list-style: none;
}
#+end_src
*** Table Styling
:PROPERTIES:
:EXPORT_FILE_NAME: table-styling
Expand Down
59 changes: 28 additions & 31 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -1048,37 +1048,34 @@ contents according to the current heading."
(replace-regexp-in-string "\n\\{2,\\}" "\n" toc-items))))
;; (message "[ox-hugo build-toc DBG] toc-items:%s" toc-items)
(when toc-items
(concat (when (string-match-p "^\\s-*\\-\\s-<span class=\"section\\-num\"" toc-items)
;; Hide the bullets if section numbers are present for
;; even one heading.
(concat "<style>\n"
" .ox-hugo-toc ul {\n"
" list-style: none;\n"
" }\n"
"</style>\n"))
(format "<div class=\"ox-hugo-toc toc%s\">\n"
(if local
" local"
""))
(unless (org-hugo--plist-get-true-p info :hugo-goldmark)
"<div></div>\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"
;; Special comment that can be use to filter out the TOC
;; from .Summary in Hugo templates.
;;
;; {{ $summary_splits := split .Summary "<!--endtoc-->" }}
;; {{ if eq (len $summary_splits) 2 }}
;; <!-- If that endtoc special comment is present, output only the part after that comment as Summary. -->
;; {{ index $summary_splits 1 | safeHTML }}
;; {{ else }}
;; <!-- Print the whole Summary if endtoc special comment is not found. -->
;; {{ .Summary }}
;; {{ end }}
"<!--endtoc-->\n"))))
(let ((toc-classes '("toc" "ox-hugo-toc"))
;; `has-section-numbers' is non-nil if section numbers are
;; present for even one heading.
(has-section-numbers (string-match-p "^\\s-*\\-\\s-<span class=\"section\\-num\"" toc-items)))
(when has-section-numbers
(push "has-section-numbers" toc-classes))
(when local
(push "local" toc-classes))
(concat (format "<div 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
toc-heading ;wrapping Markdown in HTML div's.
"\n"
toc-items ;https://github.com/kaushalmodi/ox-hugo/issues/93
"\n\n"
"</div>\n"
;; Special comment that can be use to filter out the TOC
;; from .Summary in Hugo templates.
;;
;; {{ $summary_splits := split .Summary "<!--endtoc-->" }}
;; {{ if eq (len $summary_splits) 2 }}
;; <!-- If that endtoc special comment is present, output only the part after that comment as Summary. -->
;; {{ index $summary_splits 1 | safeHTML }}
;; {{ else }}
;; <!-- Print the whole Summary if endtoc special comment is not found. -->
;; {{ .Summary }}
;; {{ end }}
"<!--endtoc-->\n")))))

;;;; Escape Hugo shortcode
(defun org-hugo--escape-hugo-shortcode (code lang)
Expand Down
7 changes: 1 addition & 6 deletions test/site/content/dir-locals-test/dir-locals-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ draft: false
creator: "Dummy creator string"
---

<style>
.ox-hugo-toc ul {
list-style: none;
}
</style>
<div class="ox-hugo-toc toc">
<div class="ox-hugo-toc toc has-section-numbers">

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

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

<style>
.ox-hugo-toc ul {
list-style: none;
}
</style>
<div class="ox-hugo-toc toc">
<div class="ox-hugo-toc toc has-section-numbers">

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

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

<style>
.ox-hugo-toc ul {
list-style: none;
}
</style>
<div class="ox-hugo-toc toc">
<div class="ox-hugo-toc toc has-section-numbers">

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

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

<style>
.ox-hugo-toc ul {
list-style: none;
}
</style>
<div class="ox-hugo-toc toc">
<div class="ox-hugo-toc toc has-section-numbers">

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

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

<style>
.ox-hugo-toc ul {
list-style: none;
}
</style>
<div class="ox-hugo-toc toc">
<div class="ox-hugo-toc toc has-section-numbers">

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

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

<style>
.ox-hugo-toc ul {
list-style: none;
}
</style>
<div class="ox-hugo-toc toc">
<div class="ox-hugo-toc toc has-section-numbers">

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

Expand Down