Skip to content

Instantly share code, notes, and snippets.

@y-ack
Last active November 14, 2017 19:01
Show Gist options
  • Save y-ack/1e26898533975f013fea78c7d4d9df0a to your computer and use it in GitHub Desktop.
Save y-ack/1e26898533975f013fea78c7d4d9df0a to your computer and use it in GitHub Desktop.
org stuff
#toggle-table-of-contents {
display: none;
}
#toggle-table-of-contents ~ label {
text-decoration: underline;
}
#toggle-table-of-contents ~ label::before {
content: "hide ";
}
#toggle-table-of-contents:checked ~ label::before {
content: "show ";
}
#text-table-of-contents {
overflow-y: hidden;
}
#toggle-table-of-contents:checked ~ #text-table-of-contents {
height: 0; /* could probably become a fancy transition */
display: none;
}
(defun org-html-toc (depth info)
"Build a table of contents.
DEPTH is an integer specifying the depth of the table. INFO is a
plist used as a communication channel. Return the table of
contents as a string, or nil if it is empty."
(let ((toc-entries
(mapcar (lambda (headline)
(cons (org-html--format-toc-headline headline info)
(org-export-get-relative-level headline info)))
(org-export-collect-headlines info depth)))
(outer-tag (if (and (org-html-html5-p info)
(plist-get info :html-html5-fancy))
"nav"
"div")))
(when toc-entries
(concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
(format "<h%d>%s</h%d>\n"
org-html-toplevel-hlevel
(org-html--translate "Table of Contents" info)
org-html-toplevel-hlevel)
;;
"<input id=\"toggle-table-of-contents\" type=\"checkbox\">"
"<label for=\"toggle-table-of-contents\">table of contents</label>"
;;
"<div id=\"text-table-of-contents\">"
(org-html--toc-text toc-entries)
"</div>\n"
(format "</%s>\n" outer-tag)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment