Skip to content

Commit

Permalink
Don't use   or   to separate the tags
Browse files Browse the repository at this point in the history
Update the test to include the scenario where tags are used on
sub-headings which will be rendered as list items.
  • Loading branch information
kaushalmodi committed Jan 11, 2022
1 parent 5b3f856 commit 77bb4b8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
17 changes: 17 additions & 0 deletions doc/ox-hugo-manual.org
Expand Up @@ -1729,6 +1729,23 @@ These variables do not affect the tags set via keywords =#+hugo_tags=,
property forms), because Org keywords and properties allow using the
hyphen and space (/in "double-quoted strings"/) characters. So the
underscores in these keywords remain untransformed on export.
**** Sub-heading Tags
Sub-heading tags are exported wrapped in HTML ~span~ tags to the right
of the exported heading if ~org-export-with-tags~ is non-nil (default)
or if ~#+options: tags:t~ is used.

The ~span~ tags are best formatted using CSS. Here's one example:

#+begin_src css
.tag span {
background: lightgrey;
font-size: small;
padding: 0.1rem 0.2rem;
margin: 0.2rem;
}
#+end_src

{{{test-search(subheading-tags)}}}
**** More Examples
- [[https://raw.githubusercontent.com/kaushalmodi/ox-hugo/main/test/site/content-org/tags-and-categories.org][Org source]]
- Exported Markdown -- [[https://raw.githubusercontent.com/kaushalmodi/ox-hugo/main/test/site/content/posts/inheriting-tags.md][=inheriting-tags.md=]], [[https://raw.githubusercontent.com/kaushalmodi/ox-hugo/main/test/site/content/posts/overriding-tags.md][=overriding-tags.md=]]
Expand Down
18 changes: 17 additions & 1 deletion ox-hugo.el
Expand Up @@ -1723,6 +1723,22 @@ user has requested for it.)"
(member lang-2chars '("zh" ;"zh", "zh_CH", ..
"ja"))))) ;"ja", ..

(defun org-hugo--tags (tags info)
"Format TAGS into HTML.
INFO is a plist containing export options.
This function is almost identical to `org-html--tags' from
`ox-html' except that the tag separator is an empty string."
(when tags
(format "<span class=\"tag\">%s</span>"
(mapconcat
(lambda (tag)
(format "<span class=\"%s\">%s</span>"
(concat (plist-get info :html-tag-class-prefix)
(org-html-fix-class-name tag))
tag))
tags ""))))



;;; Transcode Functions
Expand Down Expand Up @@ -1861,7 +1877,7 @@ a communication channel."
(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)))
(tags-html (org-hugo--tags tags-list info)))
(when (org-string-nw-p tags-html)
(concat " " tags-html)))))
(priority
Expand Down
9 changes: 6 additions & 3 deletions test/site/content-org/all-posts.org
Expand Up @@ -538,16 +538,19 @@ 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:
** Export with sub-heading tags :tags:subheading_tags:
:PROPERTIES:
:EXPORT_FILE_NAME: sub-headings-with-tags
:EXPORT_OPTIONS: tags:t
:EXPORT_OPTIONS: tags:t h:2
:END:
#+begin_description
Export tags of sub-headings
#+end_description
{{{oxhugoissue(513)}}}
*** Sub heading :abc:def:@abc__def__ghi:ghi_jkl:
*** Sub heading level 1 :abc:def:@abc__def__ghi:ghi_jkl:
**** Sub heading level 2 :abc:def:@abc__def__ghi:ghi_jkl:
***** Sub heading level 3 :abc:def:@abc__def__ghi:ghi_jkl:
****** Sub heading level 4 :abc:def:@abc__def__ghi:ghi_jkl:
* Title in Front Matter :title:
** Awesome title with "quoted text"
:PROPERTIES:
Expand Down
15 changes: 13 additions & 2 deletions test/site/content/posts/sub-headings-with-tags.md
@@ -1,11 +1,22 @@
+++
title = "Export with sub-heading tags"
description = "Export tags of sub-headings"
tags = ["headings", "tags", "subtree"]
tags = ["headings", "tags", "subheading-tags"]
draft = false
+++

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


## 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}
## Sub heading level 1 <span class="tag"><span class="abc">abc</span><span class="def">def</span><span class="_abc_def_ghi">@abc def ghi</span><span class="ghi_jkl">ghi-jkl</span></span> {#sub-heading-level-1}


### Sub heading level 2 <span class="tag"><span class="abc">abc</span><span class="def">def</span><span class="_abc_def_ghi">@abc def ghi</span><span class="ghi_jkl">ghi-jkl</span></span> {#sub-heading-level-2}

<!--list-separator-->

- Sub heading level 3 <span class="tag"><span class="abc">abc</span><span class="def">def</span><span class="_abc_def_ghi">@abc def ghi</span><span class="ghi_jkl">ghi-jkl</span></span>

<!--list-separator-->

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

0 comments on commit 77bb4b8

Please sign in to comment.