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

HTML container improvements #735

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions doc/ox-hugo-manual.org
Original file line number Diff line number Diff line change
Expand Up @@ -4303,6 +4303,11 @@ sub-tree is exported as a heading surrounding with ~<section>~ and
~</section>~. By default, that ~section~ tag has the class
"outline-NUM" where /NUM/ is the level of that heading in that post.

By default, if ~HTML_CONTAINER~ is inherited (for example, set at the
file level), it is only applied to top-level sections. Deeper sections
get wrapped in ~div~ tags. If you would like the same container to be
applied throughout, set ~HTML_CONTAINER_NESTED~ to ~t~.

Additionally, if it has the property ~EXPORT_HTML_CONTAINER_CLASS:
foo~, the "foo" class gets added to that container tag as well.

Expand Down
9 changes: 6 additions & 3 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ The software list is taken from https://www.gnu.org/software/."
(:bibliography "BIBLIOGRAPHY" nil nil newline) ;Used in ox-hugo-pandoc-cite
(:html-container "HTML_CONTAINER" nil org-hugo-container-element)
(:html-container-class "HTML_CONTAINER_CLASS" nil "")
(:html-container-nested "HTML_CONTAINER_NESTED" nil nil)

;; Front-matter variables
;; https://gohugo.io/content-management/front-matter/#front-matter-variables
Expand Down Expand Up @@ -2151,8 +2152,9 @@ a communication channel."
(let* ((container-class (or (org-element-property :HTML_CONTAINER_CLASS heading)
(org-element-property :EXPORT_HTML_CONTAINER_CLASS heading)
(plist-get info :html-container-class)))
(container-class-str (when (org-string-nw-p container-class)
(concat " " container-class))))
(container-class-str (if (org-string-nw-p container-class)
(concat " " container-class)
container-class)))
(format (concat "<%s class=\"outline-%d%s\">\n"
"%s%s\n"
"</%s>")
Expand All @@ -2179,7 +2181,8 @@ Else, no HTML element is wrapped around the HEADING."
(or (org-element-property :HTML_CONTAINER heading) ;property of the immediate heading
(org-element-property :EXPORT_HTML_CONTAINER heading) ;property of the immediate heading
(and (org-string-nw-p (plist-get info :html-container)) ;inherited :html-container: property if any
(if (= 1 (org-export-get-relative-level heading info))
(if (or (plist-get info :html-container-nested)
(= 1 (org-export-get-relative-level heading info)))
(plist-get info :html-container)
"div"))))

Expand Down
17 changes: 17 additions & 0 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,23 @@ This heading is wrapped in an ~aside~ tag with classes ~outline-1~ and
:END:
This heading is wrapped in a ~blockquote~ tag with classes ~outline-2~
and ~baz~.
*** HTML Container without class
:PROPERTIES:
:EXPORT_FILE_NAME: html-container-without-class
:END:
**** Top level heading 1
This heading is wrapped in a ~section~ tag with class ~outline-1~.
***** Sub-heading 1.1
This heading is wrapped in a ~div~ tag with class ~outline-2~.
*** HTML Container nested
:PROPERTIES:
:EXPORT_FILE_NAME: html-container-nested
:EXPORT_HTML_CONTAINER_NESTED: t
:END:
**** Top level heading 1
This heading is wrapped in a ~section~ tag with class ~outline-1~.
***** Sub-heading 1.1
This heading is wrapped in a ~section~ tag with class ~outline-2~.
** Export with planning info :planning:
:PROPERTIES:
:EXPORT_FILE_NAME: planning-info
Expand Down
21 changes: 21 additions & 0 deletions test/site/content/posts/html-container-nested.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
+++
title = "HTML Container nested"
tags = ["headings", "container", "html"]
draft = false
+++

<section class="outline-1">

## Top level heading 1 {#top-level-heading-1}

This heading is wrapped in a `section` tag with class `outline-1`.

<section class="outline-2">

### Sub-heading 1.1 {#sub-heading-1-dot-1}

This heading is wrapped in a `section` tag with class `outline-2`.

</section>

</section>
21 changes: 21 additions & 0 deletions test/site/content/posts/html-container-without-class.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
+++
title = "HTML Container without class"
tags = ["headings", "container", "html"]
draft = false
+++

<section class="outline-1">

## Top level heading 1 {#top-level-heading-1}

This heading is wrapped in a `section` tag with class `outline-1`.

<div class="outline-2">

### Sub-heading 1.1 {#sub-heading-1-dot-1}

This heading is wrapped in a `div` tag with class `outline-2`.

</div>

</section>