diff options
Diffstat (limited to 'lisp/org/ox-html.el')
-rw-r--r-- | lisp/org/ox-html.el | 92 |
1 files changed, 63 insertions, 29 deletions
diff --git a/lisp/org/ox-html.el b/lisp/org/ox-html.el index b4094d3e44c..44962a533e5 100644 --- a/lisp/org/ox-html.el +++ b/lisp/org/ox-html.el @@ -130,7 +130,9 @@ (:infojs-opt "INFOJS_OPT" nil nil) ;; Redefine regular options. (:creator "CREATOR" nil org-html-creator-string) - (:with-latex nil "tex" org-html-with-latex))) + (:with-latex nil "tex" org-html-with-latex) + ;; Retrieve LaTeX header for fragments. + (:latex-header "LATEX_HEADER" nil nil newline))) ;;; Internal Variables @@ -544,6 +546,8 @@ a formatting string to wrap fontified text with. If no association can be found for a given markup, text will be returned as-is." :group 'org-export-html + :version "24.4" + :package-version '(Org . "8.0") :type '(alist :key-type (symbol :tag "Markup type") :value-type (string :tag "Format string")) :options '(bold code italic strike-through underline verbatim)) @@ -565,7 +569,8 @@ Warning: non-nil may break indentation of source code blocks." ;;;; Drawers -(defcustom org-html-format-drawer-function nil +(defcustom org-html-format-drawer-function + (lambda (name contents) contents) "Function called to format a drawer in HTML code. The function must accept two parameters: @@ -577,10 +582,10 @@ The function should return the string to be exported. For example, the variable could be set to the following function in order to mimic default behaviour: -\(defun org-html-format-drawer-default \(name contents\) - \"Format a drawer element for HTML export.\" - contents\)" +The default value simply returns the value of CONTENTS." :group 'org-export-html + :version "24.4" + :package-version '(Org . "8.0") :type 'function) ;;;; Footnotes @@ -622,7 +627,7 @@ document title." :group 'org-export-html :type 'integer) -(defcustom org-html-format-headline-function nil +(defcustom org-html-format-headline-function 'ignore "Function to format headline text. This function will be called with 5 arguments: @@ -634,6 +639,8 @@ TAGS the tags (string or nil). The function result will be used in the section format string." :group 'org-export-html + :version "24.4" + :package-version '(Org . "8.0") :type 'function) ;;;; HTML-specific @@ -649,7 +656,7 @@ attributes, when appropriate." ;;;; Inlinetasks -(defcustom org-html-format-inlinetask-function nil +(defcustom org-html-format-inlinetask-function 'ignore "Function called to format an inlinetask in HTML code. The function must accept six parameters: @@ -662,6 +669,8 @@ The function must accept six parameters: The function should return the string to be exported." :group 'org-export-html + :version "24.4" + :package-version '(Org . "8.0") :type 'function) ;;;; LaTeX @@ -1119,6 +1128,8 @@ like that: \"%%\"." "Information about the creator of the HTML document. This option can also be set on with the CREATOR keyword." :group 'org-export-html + :version "24.4" + :package-version '(Org . "8.0") :type '(string :tag "Creator string")) ;;;; Template :: Preamble @@ -1971,7 +1982,8 @@ and value is its relative level, as an integer." (defun org-html--format-toc-headline (headline info) "Return an appropriate table of contents entry for HEADLINE. INFO is a plist used as a communication channel." - (let* ((todo (and (plist-get info :with-todo-keywords) + (let* ((headline-number (org-export-get-headline-number headline info)) + (todo (and (plist-get info :with-todo-keywords) (let ((todo (org-element-property :todo-keyword headline))) (and todo (org-export-data todo info))))) (todo-type (and todo (org-element-property :todo-type headline))) @@ -1992,19 +2004,23 @@ INFO is a plist used as a communication channel." (tags (and (eq (plist-get info :with-tags) t) (org-export-get-tags headline info)))) (format "<a href=\"#%s\">%s</a>" + ;; Label. (org-export-solidify-link-text (or (org-element-property :CUSTOM_ID headline) (concat "sec-" - (mapconcat - #'number-to-string - (org-export-get-headline-number headline info) - "-")))) - (apply (if (functionp org-html-format-headline-function) - (lambda (todo todo-type priority text tags &rest ignore) - (funcall org-html-format-headline-function - todo todo-type priority text tags)) - #'org-html-format-headline) - todo todo-type priority text tags :section-number nil)))) + (mapconcat #'number-to-string headline-number "-")))) + ;; Body. + (concat + (and (not (org-export-low-level-p headline info)) + (org-export-numbered-headline-p headline info) + (concat (mapconcat #'number-to-string headline-number ".") + ". ")) + (apply (if (not (eq org-html-format-headline-function 'ignore)) + (lambda (todo todo-type priority text tags &rest ignore) + (funcall org-html-format-headline-function + todo todo-type priority text tags)) + #'org-html-format-headline) + todo todo-type priority text tags :section-number nil))))) (defun org-html-list-of-listings (info) "Build a list of listings. @@ -2244,7 +2260,7 @@ holding contextual information." headline-number "-")))) (format-function (cond ((functionp format-function) format-function) - ((functionp org-html-format-headline-function) + ((not (eq org-html-format-headline-function 'ignore)) (lambda (todo todo-type priority text tags &rest ignore) (funcall org-html-format-headline-function todo todo-type priority text tags))) @@ -2371,9 +2387,9 @@ contextual information." CONTENTS holds the contents of the block. INFO is a plist holding contextual information." (cond - ;; If `org-html-format-inlinetask-function' is provided, call it + ;; If `org-html-format-inlinetask-function' is not 'ignore, call it ;; with appropriate arguments. - ((functionp org-html-format-inlinetask-function) + ((not (eq org-html-format-inlinetask-function 'ignore)) (let ((format-function (function* (lambda (todo todo-type priority text tags @@ -2474,18 +2490,34 @@ CONTENTS is nil. INFO is a plist holding contextual information." ;;;; Latex Environment -(defun org-html-format-latex (latex-frag processing-type) - "Format a LaTeX fragment LATEX-FRAG into HTML." +(defun org-html-format-latex (latex-frag processing-type info) + "Format a LaTeX fragment LATEX-FRAG into HTML. +PROCESSING-TYPE designates the tool used for conversion. It is +a symbol among `mathjax', `dvipng', `imagemagick', `verbatim' nil +and t. See `org-html-with-latex' for more information. INFO is +a plist containing export properties." (let ((cache-relpath "") (cache-dir "")) (unless (eq processing-type 'mathjax) (let ((bfn (or (buffer-file-name) (make-temp-name - (expand-file-name "latex" temporary-file-directory))))) + (expand-file-name "latex" temporary-file-directory)))) + (latex-header + (let ((header (plist-get info :latex-header))) + (and header + (concat (mapconcat + (lambda (line) (concat "#+LATEX_HEADER: " line)) + (org-split-string header "\n") + "\n") + "\n"))))) (setq cache-relpath (concat "ltxpng/" (file-name-sans-extension (file-name-nondirectory bfn))) - cache-dir (file-name-directory bfn)))) + cache-dir (file-name-directory bfn)) + ;; Re-create LaTeX environment from original buffer in + ;; temporary buffer so that dvipng/imagemagick can properly + ;; turn the fragment into an image. + (setq latex-frag (concat latex-header latex-frag)))) (with-temp-buffer (insert latex-frag) (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..." @@ -2501,9 +2533,10 @@ CONTENTS is nil. INFO is a plist holding contextual information." (attributes (org-export-read-attribute :attr_html latex-environment))) (case processing-type ((t mathjax) - (org-html-format-latex latex-frag 'mathjax)) + (org-html-format-latex latex-frag 'mathjax info)) ((dvipng imagemagick) - (let ((formula-link (org-html-format-latex latex-frag processing-type))) + (let ((formula-link + (org-html-format-latex latex-frag processing-type info))) (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link)) ;; Do not provide a caption or a name to be consistent with ;; `mathjax' handling. @@ -2521,9 +2554,10 @@ CONTENTS is nil. INFO is a plist holding contextual information." (processing-type (plist-get info :with-latex))) (case processing-type ((t mathjax) - (org-html-format-latex latex-frag 'mathjax)) + (org-html-format-latex latex-frag 'mathjax info)) ((dvipng imagemagick) - (let ((formula-link (org-html-format-latex latex-frag processing-type))) + (let ((formula-link + (org-html-format-latex latex-frag processing-type info))) (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link)) (org-html--format-image (match-string 1 formula-link) nil info)))) (t latex-frag)))) |