0

I would like tags in headers (specifically) to export to html as links to a file of the same name, something like:

 * My first post is about dogs :DOGS:

where :DOGS: then exports as

<span class="tag">
    <a href="./dogs.html">DOGS</a>
</span>

instead of what it currently exports as which is

<span class="tag">
    <span class="DOGS">DOGS</span>
</span>

I assume another issue I'll have to work through is that I'd need to specify that some tags get exported (like ones in headers), while others don't (like ones in bodies).

1

Write a modified org-html-format-headline-function that calls a modified org-html--tags function and hook it into the standard HTML exporter by redefining/customizing the variable org-html-format-headline-function.

Here's a possible implementation:

#+begin_src elisp
  (defun ndk/org-html-format-headline-function
      (todo _todo-type priority text tags info)
    "Default format function for a headline.
  See `org-html-format-headline-function' for details."
    (let ((todo (org-html--todo todo info))
          (priority (org-html--priority priority info))
          (tags (ndk/org-html--tags tags info)))
      (concat todo (and todo " ")
          priority (and priority " ")
          text
          tags)))

  (defun ndk/org-html--tags (tags info)
    "Format TAGS into HTML.
  INFO is a plist containing export options."
    (when tags
      (format "<span class=\"tag\">%s</span>"
          (mapconcat
           (lambda (tag)
             (format "<a href=\"%s\">%s</a>"
                     (format "./%s.html" (downcase tag))
                     tag))
           tags  "&#xa0;"))))

  ;; (setq org-html-format-headline-function #'org-html-format-headline-default-function)
  (setq org-html-format-headline-function #'ndk/org-html-format-headline-function)
#+end_src

If you compare the two functions above with the standard ones in ox-html.el, you should be able to see clearly the small differences between them (and how to modify them further if needed).

For testing, the two setq forms at the end are convenient: comment one or the other out to get either the default or the modified behavior. When you are satisfied with the functions, you should probably customize the variable org-html-format-headline-function to set the whole thing in stone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.