;;; ox-tufte.el --- Tufte HTML org-mode export backend
;; Copyright (C) 2022 Yann Herklotz
;; Copyright (C) 2016 Matthew Lee Hinman
;; Author: M. Lee Hinman
;; Description: An org exporter for Tufte HTML
;; Keywords: org, tufte, html
;; Version: 1.1.0
;; Package-Requires: ((org "8.2") (emacs "24.4"))
;; URL: https://git.sr.ht/~ymherklotz/ox-tufte
;; This file is not part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see
\n%s\n%s
\n%s\n%s
tags removed or they will not work (replace-regexp-in-string "?p.*>" "" fn-data)))) (defun org-tufte-maybe-margin-note-link (link desc info) "Render LINK as a margin note if it starts with `mn:'. For example, `[[mn:1][this is some text]]' is margin note 1 that will show \"this is some text\" in the margin. If it does not, it will be passed onto the original function in order to be handled properly. DESC is the description part of the link. INFO is a plist holding contextual information." (let ((path (split-string (org-element-property :path link) ":"))) (if (and (string= (org-element-property :type link) "fuzzy") (string= (car path) "mn")) (format (concat "" "" "%s") (cadr path) (cadr path) (replace-regexp-in-string "?p.*>" "" desc)) (org-html-link link desc info)))) (defun org-tufte-src-block (src-block contents info) "Transcode SRC-BLOCK element into Tufte HTML format. CONTENTS is nil. INFO is a plist used as a communication channel." (format "
%s
"
(org-html-format-code src-block info)))
;;; Export functions
;;;###autoload
(defun org-tufte-export-to-buffer (&optional async subtreep visible-only)
"Export current buffer to a Tufte HTML buffer.
If narrowing is active in the current buffer, only export its
narrowed part.
If a region is active, export that region.
A non-nil optional argument ASYNC means the process should happen
asynchronously. The resulting buffer should be accessible
through the `org-export-stack' interface.
When optional argument SUBTREEP is non-nil, export the sub-tree
at point, extracting information from the headline properties
first.
When optional argument VISIBLE-ONLY is non-nil, don't export
contents of hidden elements.
Export is done in a buffer named \"*Org Tufte Export*\", which will
be displayed when `org-export-show-temporary-export-buffer' is
non-nil."
(interactive)
(let (;; need to bind this because tufte treats footnotes specially, so we
;; don't want to display them at the bottom
(org-html-footnotes-section (if org-tufte-include-footnotes-at-bottom
org-html-footnotes-section
"")))
(org-export-to-buffer 'tufte-html "*Org Tufte Export*"
async subtreep visible-only nil nil (lambda () (text-mode)))))
;;;###autoload
(defun org-tufte-export-to-file (&optional async subtreep visible-only)
"Export current buffer to a Tufte HTML file.
If narrowing is active in the current buffer, only export its
narrowed part.
If a region is active, export that region.
A non-nil optional argument ASYNC means the process should happen
asynchronously. The resulting file should be accessible through
the `org-export-stack' interface.
When optional argument SUBTREEP is non-nil, export the sub-tree
at point, extracting information from the headline properties
first.
When optional argument VISIBLE-ONLY is non-nil, don't export
contents of hidden elements.
Return output file's name."
(interactive)
(let ((outfile (org-export-output-file-name ".html" subtreep))
;; need to bind this because tufte treats footnotes specially, so we
;; don't want to display them at the bottom
(org-html-footnotes-section (if org-tufte-include-footnotes-at-bottom
org-html-footnotes-section
"")))
(org-export-to-file 'tufte-html outfile async subtreep visible-only)))
;;; publishing function
;;;###autoload
(defun org-html-publish-to-tufte-html (plist filename pub-dir)
"Publish an org file to Tufte-styled HTML.
PLIST is the property list for the given project. FILENAME is
the filename of the Org file to be published. PUB-DIR is the
publishing directory.
Return output file name."
(org-publish-org-to 'tufte-html filename
(concat "." (or (plist-get plist :html-extension)
org-html-extension
"html"))
plist pub-dir))
(provide 'ox-tufte)
;;; ox-tufte.el ends here