[Emacs] Make headings in org exported html links to themselves

This commit is contained in:
Ivan Malison 2016-12-28 18:17:57 -08:00
parent 2ac6c50d83
commit 355b81d9fe
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8

View File

@ -30,7 +30,7 @@ are placed in a repository. The org-mode file that they target is set [[https://
should be relatively easy to change.
*** [[https://github.com/fniessen/org-html-themes][Read The Org]]
I use [[https://github.com/fniessen][fniessen]]'s ReadTheOrg theme which can be found at https://github.com/fniessen/org-html-themes.
*** Heading Links
*** Predictable and Human Readable Heading Links
To make it so that internal heading links have names that correspond to the
heading text, and don't change when new headings are added to the document, I
wrote a custom version of ~org-export-get-reference~.
@ -44,6 +44,9 @@ this.
I'm considering turning this snippet in to a package, so please let me know if
that is something you are interested in.
*** Make Headings Link to Themselves
See the [[Make headings in exported html links to themselves][Make headings in exported html links to themselves]]. This is another pretty nasty hack. This is useful when you are browsing the document and you want to grab a link to
the current heading.
*** Set Background Color Source Blocks
For some reason, org-mode uses all of your currently active fontification when exporting EXCEPT for background color. [[Set Background Color of Source Blocks for Export][This]] modification fixes this.
** [[framecontrol][Frame control]]
@ -3295,6 +3298,35 @@ alphanumeric characters only."
(puthash datum new-name cache)
new-name)))))
#+END_SRC
**** Make headings in exported html links to themselves
#+BEGIN_SRC emacs-lisp :tangle org-config.el
(use-package ox-html
:ensure nil
:preface
(progn
(defvar imalison:current-html-headline)
(defun imalison:set-current-html-headline (headline &rest args)
(setq imalison:current-html-headline headline))
(defun imalison:clear-current-html-headline (&rest args)
(setq imalison:current-html-headline nil))
(defun imalison:org-html-format-heading-function (todo todo-type priority text tags info)
(let* ((reference (when imalison:current-html-headline
(org-export-get-reference imalison:current-html-headline info)))
;; Don't do anything special if the current headline is not set
(new-text (if imalison:current-html-headline
(format "<a href=\"#%s\">%s</a>" reference text)
text)))
(org-html-format-headline-default-function
todo todo-type priority new-text tags info))))
:config
(progn
;; This is set before and cleared afterwards, so that we know when we are
;; generating the text for the headline itself and when we are not.
(advice-add 'org-html-headline :before 'imalison:set-current-html-headline)
(advice-add 'org-html-headline :after 'imalison:clear-current-html-headline)
(setq org-html-format-headline-function
'imalison:org-html-format-heading-function)))
#+END_SRC
**** org-projectile
#+BEGIN_SRC emacs-lisp
(use-package org-projectile