Skip to content

Commit

Permalink
Export tags in sub-headings; recognize tags:t export option
Browse files Browse the repository at this point in the history
Fixes #513
  • Loading branch information
kaushalmodi committed Jan 11, 2022
1 parent 7925747 commit 552386e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
25 changes: 16 additions & 9 deletions ox-hugo.el
Expand Up @@ -1857,17 +1857,21 @@ a communication channel."
(org-element-property :todo-keyword heading)))
(todo-fmtd (when todo
(concat (org-hugo--todo todo info) " ")))
(tags (and (org-hugo--plist-get-true-p info :with-tags)
(let ((tag-list (org-export-get-tags heading info)))
(and tag-list
(format " :%s:"
(mapconcat #'identity tag-list ":"))))))
(tags-fmtd (and (org-hugo--plist-get-true-p info :with-tags)
(let* ((tags-list (org-export-get-tags heading info))
(tags-list (dolist (fn org-hugo-tag-processing-functions tags-list)
(setq tags-list (funcall fn tags-list info))))
(tags-html (org-html--tags tags-list info)))
(when (org-string-nw-p tags-html)
(concat " " tags-html)))))
(priority
(and (org-hugo--plist-get-true-p info :with-priority)
(let ((char (org-element-property :priority heading)))
(and char (format "[#%c] " char)))))
(style (plist-get info :md-headline-style)))
;; (message "[ox-hugo-heading DBG] num: %s" numbers)
;; (message "[ox-hugo-heading DBG] with-tags: %S" (org-hugo--plist-get-true-p info :with-tags))
;; (message "[ox-hugo-heading DBG] tags: %S" (org-export-get-tags heading info))
(cond
;; Cannot create a heading. Fall-back to a list.
((or (org-export-low-level-p heading info)
Expand All @@ -1886,13 +1890,13 @@ a communication channel."
;; section above is ending with a plain list. That
;; HTML comment will force-end the <ul> or <ol> tag
;; of that preceding list.
bullet " " heading tags "\n\n"
bullet " " heading tags-fmtd "\n\n"
(and contents (replace-regexp-in-string "^" " " contents)))))
(t
(let* ((anchor (format "{#%s}" ;https://gohugo.io/extras/crossreferences/
(org-hugo--get-anchor heading info)))
(heading-title (org-hugo--heading-title style level loffset title
todo-fmtd anchor numbers))
todo-fmtd tags-fmtd anchor numbers))
(wrap-element (org-hugo--container heading info))
(content-str (or (org-string-nw-p contents) "")))
(if wrap-element
Expand Down Expand Up @@ -2027,7 +2031,7 @@ output."
(setq ret (org-hugo-slug title))))
ret))

(defun org-hugo--heading-title (style level loffset title &optional todo anchor numbers)
(defun org-hugo--heading-title (style level loffset title &optional todo tags anchor numbers)
"Generate a heading title in the preferred Markdown heading style.
STYLE is the preferred style (`atx' or `setext').
Expand All @@ -2038,12 +2042,15 @@ TITLE is the heading title.
Optional argument TODO is the Org TODO string.
Optional argument TAGS is a string containing the current
heading's tags.
Optional argument ANCHOR is the Hugo anchor tag for the section as a
string.
Optional argument NUMBERS, if non-nil, is an htmlized string
containing the TITLE's number."
(let ((heading (concat todo numbers title " " anchor "\n")))
(let ((heading (concat todo numbers title tags " " anchor "\n")))
;; Use "Setext" style
(if (and (eq style 'setext) (< level 3))
(let* ((underline-char (if (= level 1) ?= ?-))
Expand Down
20 changes: 20 additions & 0 deletions test/site/content-org/all-posts.org
Expand Up @@ -538,6 +538,26 @@ Export the SCHEDULED, DEADLINE, etc. planning info time stamps.
{{{oxhugoissue(514)}}}
*** TODO Some plan
SCHEDULED: <2022-01-20 Mon> DEADLINE: <2022-01-30 Mon>
** Export with sub-heading tags :tags:subtree:
:PROPERTIES:
:EXPORT_FILE_NAME: sub-headings-with-tags
:EXPORT_OPTIONS: tags:t
:END:
#+begin_description
Export tags of sub-headings
#+end_description
{{{oxhugoissue(513)}}}

#+begin_export html
<style>
.tag span {
background: lightgrey;
font-size: small;
padding: 0.1rem 0.2rem;
}
</style>
#+end_export
*** Sub heading :abc:def:@abc__def__ghi:ghi_jkl:
* Title in Front Matter :title:
** Awesome title with "quoted text"
:PROPERTIES:
Expand Down
19 changes: 19 additions & 0 deletions test/site/content/posts/sub-headings-with-tags.md
@@ -0,0 +1,19 @@
+++
title = "Export with sub-heading tags"
description = "Export tags of sub-headings"
tags = ["headings", "tags", "subtree"]
draft = false
+++

`ox-hugo` Issue #[513](https://github.com/kaushalmodi/ox-hugo/issues/513)

<style>
.tag span {
background: lightgrey;
font-size: small;
padding: 0.1rem 0.2rem;
}
</style>


## Sub heading <span class="tag"><span class="abc">abc</span>&#xa0;<span class="def">def</span>&#xa0;<span class="_abc_def_ghi">@abc def ghi</span>&#xa0;<span class="ghi_jkl">ghi-jkl</span></span> {#sub-heading}
2 changes: 1 addition & 1 deletion test/site/themes/hugo-bare-min-theme

0 comments on commit 552386e

Please sign in to comment.