Correctly export lists in footnotes (take 2)
* lisp/org-exp.el (org-export-preprocess-string): add the possibility to call recursively the function. Also change order of some function calls. Comment export process for footnotes. * lisp/org-footnote.el (org-footnote-normalize): change the export specific parameter to hold properties of export. Thus, the function can send every footnote definition in the buffer through `org-export-process-string'.
This commit is contained in:
parent
14ba8ebc28
commit
31e92984bc
|
@ -1092,7 +1092,7 @@ on this string to produce the exported version."
|
||||||
org-export-id-target-alist nil
|
org-export-id-target-alist nil
|
||||||
org-export-code-refs nil)
|
org-export-code-refs nil)
|
||||||
|
|
||||||
(with-current-buffer (get-buffer-create " org-mode-tmp")
|
(with-temp-buffer
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(insert string)
|
(insert string)
|
||||||
(setq case-fold-search t)
|
(setq case-fold-search t)
|
||||||
|
@ -1120,14 +1120,6 @@ on this string to produce the exported version."
|
||||||
(org-export-handle-include-files-recurse)
|
(org-export-handle-include-files-recurse)
|
||||||
(run-hooks 'org-export-preprocess-after-include-files-hook)
|
(run-hooks 'org-export-preprocess-after-include-files-hook)
|
||||||
|
|
||||||
;; Change lists ending. Other parts of export may insert blank
|
|
||||||
;; lines and lists' structure could be altered.
|
|
||||||
(org-export-mark-list-end)
|
|
||||||
|
|
||||||
;; Process the macros
|
|
||||||
(org-export-preprocess-apply-macros)
|
|
||||||
(run-hooks 'org-export-preprocess-after-macros-hook)
|
|
||||||
|
|
||||||
;; Get rid of archived trees
|
;; Get rid of archived trees
|
||||||
(org-export-remove-archived-trees archived-trees)
|
(org-export-remove-archived-trees archived-trees)
|
||||||
|
|
||||||
|
@ -1142,9 +1134,35 @@ on this string to produce the exported version."
|
||||||
;; Get rid of tasks, depending on configuration
|
;; Get rid of tasks, depending on configuration
|
||||||
(org-export-remove-tasks (plist-get parameters :tasks))
|
(org-export-remove-tasks (plist-get parameters :tasks))
|
||||||
|
|
||||||
;; Normalize footnotes
|
;; Prepare footnotes for export. During that process, footnotes
|
||||||
|
;; actually included in the exported part of the buffer go
|
||||||
|
;; though some transformations:
|
||||||
|
|
||||||
|
;; 1. They have their label normalized (like "[N]");
|
||||||
|
|
||||||
|
;; 2. They get moved at the same place in the buffer (usually at
|
||||||
|
;; its end, but backends may define another place via
|
||||||
|
;; `org-footnote-insert-pos-for-preprocessor');
|
||||||
|
|
||||||
|
;; 3. The are stored in `org-export-footnotes-seen', while
|
||||||
|
;; `org-export-preprocess-string' is applied to their
|
||||||
|
;; definition.
|
||||||
|
|
||||||
|
;; Line-wise exporters ignore `org-export-footnotes-seen', as
|
||||||
|
;; they interpret footnotes at the moment they see them in the
|
||||||
|
;; buffer. Context-wise exporters grab all the info needed in
|
||||||
|
;; that variable and delete moved definitions (as described in
|
||||||
|
;; 2nd step).
|
||||||
(when (plist-get parameters :footnotes)
|
(when (plist-get parameters :footnotes)
|
||||||
(org-footnote-normalize nil 'pre-process-p))
|
(org-footnote-normalize nil parameters))
|
||||||
|
|
||||||
|
;; Change lists ending. Other parts of export may insert blank
|
||||||
|
;; lines and lists' structure could be altered.
|
||||||
|
(org-export-mark-list-end)
|
||||||
|
|
||||||
|
;; Process the macros
|
||||||
|
(org-export-preprocess-apply-macros)
|
||||||
|
(run-hooks 'org-export-preprocess-after-macros-hook)
|
||||||
|
|
||||||
;; Export code blocks
|
;; Export code blocks
|
||||||
(org-export-blocks-preprocess)
|
(org-export-blocks-preprocess)
|
||||||
|
@ -1261,7 +1279,6 @@ on this string to produce the exported version."
|
||||||
(run-hooks 'org-export-preprocess-final-hook)
|
(run-hooks 'org-export-preprocess-final-hook)
|
||||||
|
|
||||||
(setq rtn (buffer-string)))
|
(setq rtn (buffer-string)))
|
||||||
(kill-buffer " org-mode-tmp")
|
|
||||||
rtn))
|
rtn))
|
||||||
|
|
||||||
(defun org-export-kill-licensed-text ()
|
(defun org-export-kill-licensed-text ()
|
||||||
|
|
|
@ -52,6 +52,8 @@
|
||||||
(declare-function org-inside-latex-macro-p "org" ())
|
(declare-function org-inside-latex-macro-p "org" ())
|
||||||
(declare-function org-id-uuid "org" ())
|
(declare-function org-id-uuid "org" ())
|
||||||
(declare-function org-fill-paragraph "org" (&optional justify))
|
(declare-function org-fill-paragraph "org" (&optional justify))
|
||||||
|
(declare-function org-export-preprocess-string "org-exp"
|
||||||
|
(string &rest parameters))
|
||||||
(defvar org-odd-levels-only) ;; defined in org.el
|
(defvar org-odd-levels-only) ;; defined in org.el
|
||||||
(defvar org-bracket-link-regexp) ; defined in org.el
|
(defvar org-bracket-link-regexp) ; defined in org.el
|
||||||
(defvar message-signature-separator) ;; defined in message.el
|
(defvar message-signature-separator) ;; defined in message.el
|
||||||
|
@ -520,7 +522,7 @@ With prefix arg SPECIAL, offer additional commands in a menu."
|
||||||
(defvar org-export-footnotes-data nil) ; silence byte-compiler
|
(defvar org-export-footnotes-data nil) ; silence byte-compiler
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun org-footnote-normalize (&optional sort-only pre-process-p)
|
(defun org-footnote-normalize (&optional sort-only export-props)
|
||||||
"Collect the footnotes in various formats and normalize them.
|
"Collect the footnotes in various formats and normalize them.
|
||||||
|
|
||||||
This finds the different sorts of footnotes allowed in Org, and
|
This finds the different sorts of footnotes allowed in Org, and
|
||||||
|
@ -530,7 +532,10 @@ Org-mode exporters.
|
||||||
When SORT-ONLY is set, only sort the footnote definitions into the
|
When SORT-ONLY is set, only sort the footnote definitions into the
|
||||||
referenced sequence.
|
referenced sequence.
|
||||||
|
|
||||||
When PRE-PROCESS-P is non-nil, the default action, is to insert
|
If Org is amidst an export process, EXPORT-PROPS will hold the
|
||||||
|
export properties of the buffer.
|
||||||
|
|
||||||
|
When EXPORT-PROPS is non-nil, the default action is to insert
|
||||||
normalized footnotes towards the end of the pre-processing buffer.
|
normalized footnotes towards the end of the pre-processing buffer.
|
||||||
Some exporters like docbook, odt, etc. expect that footnote
|
Some exporters like docbook, odt, etc. expect that footnote
|
||||||
definitions be available before any references to them. Such
|
definitions be available before any references to them. Such
|
||||||
|
@ -557,8 +562,8 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
|
||||||
(outline-regexp
|
(outline-regexp
|
||||||
(concat "\\*" (if nstars (format "\\{1,%d\\} " nstars) "+ ")))
|
(concat "\\*" (if nstars (format "\\{1,%d\\} " nstars) "+ ")))
|
||||||
;; Determine the highest marker used so far.
|
;; Determine the highest marker used so far.
|
||||||
(ref-table (when pre-process-p org-export-footnotes-seen))
|
(ref-table (when export-props org-export-footnotes-seen))
|
||||||
(count (if (and pre-process-p ref-table)
|
(count (if (and export-props ref-table)
|
||||||
(apply 'max (mapcar (lambda (e) (nth 1 e)) ref-table))
|
(apply 'max (mapcar (lambda (e) (nth 1 e)) ref-table))
|
||||||
0))
|
0))
|
||||||
ins-point ref)
|
ins-point ref)
|
||||||
|
@ -582,7 +587,7 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
|
||||||
;; Replace footnote reference with [MARKER]. Maybe fill
|
;; Replace footnote reference with [MARKER]. Maybe fill
|
||||||
;; paragraph once done. If SORT-ONLY is non-nil, only move
|
;; paragraph once done. If SORT-ONLY is non-nil, only move
|
||||||
;; to the end of reference found to avoid matching it twice.
|
;; to the end of reference found to avoid matching it twice.
|
||||||
;; If PRE-PROCESS-P isn't nil, also add `org-footnote'
|
;; If EXPORT-PROPS isn't nil, also add `org-footnote'
|
||||||
;; property to it, so it can be easily recognized by
|
;; property to it, so it can be easily recognized by
|
||||||
;; exporters.
|
;; exporters.
|
||||||
(if sort-only
|
(if sort-only
|
||||||
|
@ -590,7 +595,7 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
|
||||||
(delete-region (nth 1 ref) (nth 2 ref))
|
(delete-region (nth 1 ref) (nth 2 ref))
|
||||||
(goto-char (nth 1 ref))
|
(goto-char (nth 1 ref))
|
||||||
(let ((new-ref (format "[%d]" marker)))
|
(let ((new-ref (format "[%d]" marker)))
|
||||||
(when pre-process-p (org-add-props new-ref '(org-footnote t)))
|
(when export-props (org-add-props new-ref '(org-footnote t)))
|
||||||
(insert new-ref))
|
(insert new-ref))
|
||||||
(and inlinep
|
(and inlinep
|
||||||
org-footnote-fill-after-inline-note-extraction
|
org-footnote-fill-after-inline-note-extraction
|
||||||
|
@ -599,10 +604,22 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
|
||||||
;; to REF-TABLE if data was unknown.
|
;; to REF-TABLE if data was unknown.
|
||||||
(unless a
|
(unless a
|
||||||
(let ((def (or (nth 3 ref) ; inline
|
(let ((def (or (nth 3 ref) ; inline
|
||||||
(and pre-process-p
|
(and export-props
|
||||||
(cdr (assoc lbl org-export-footnotes-data)))
|
(cdr (assoc lbl org-export-footnotes-data)))
|
||||||
(nth 3 (org-footnote-get-definition lbl)))))
|
(nth 3 (org-footnote-get-definition lbl)))))
|
||||||
(push (list lbl marker def inlinep) ref-table)))
|
(push (list lbl marker
|
||||||
|
;; When exporting, each definition goes
|
||||||
|
;; through `org-export-preprocess-string' so
|
||||||
|
;; it is ready to insert in the
|
||||||
|
;; backend-specific buffer.
|
||||||
|
(if export-props
|
||||||
|
(let ((parameters
|
||||||
|
(org-combine-plists
|
||||||
|
export-props
|
||||||
|
'(:todo-keywords t :tags t :priority t))))
|
||||||
|
(org-export-preprocess-string def parameters))
|
||||||
|
def)
|
||||||
|
inlinep) ref-table)))
|
||||||
;; Remove definition of non-inlined footnotes.
|
;; Remove definition of non-inlined footnotes.
|
||||||
(unless inlinep (org-footnote-delete-definitions lbl))))
|
(unless inlinep (org-footnote-delete-definitions lbl))))
|
||||||
;; 2. Find and remove the footnote section, if any. If we are
|
;; 2. Find and remove the footnote section, if any. If we are
|
||||||
|
@ -617,14 +634,14 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
|
||||||
(concat "^\\*[ \t]+" (regexp-quote org-footnote-section)
|
(concat "^\\*[ \t]+" (regexp-quote org-footnote-section)
|
||||||
"[ \t]*$")
|
"[ \t]*$")
|
||||||
nil t))
|
nil t))
|
||||||
(if pre-process-p
|
(if export-props
|
||||||
(replace-match "")
|
(replace-match "")
|
||||||
(org-back-to-heading t)
|
(org-back-to-heading t)
|
||||||
(forward-line 1)
|
(forward-line 1)
|
||||||
(setq ins-point (point))
|
(setq ins-point (point))
|
||||||
(delete-region (point) (org-end-of-subtree t)))
|
(delete-region (point) (org-end-of-subtree t)))
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(unless pre-process-p
|
(unless export-props
|
||||||
(when org-footnote-section
|
(when org-footnote-section
|
||||||
(or (bolp) (insert "\n"))
|
(or (bolp) (insert "\n"))
|
||||||
(insert "* " org-footnote-section "\n")
|
(insert "* " org-footnote-section "\n")
|
||||||
|
@ -660,7 +677,7 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
|
||||||
;; 4. Insert the footnotes again in the buffer, at the
|
;; 4. Insert the footnotes again in the buffer, at the
|
||||||
;; appropriate spot.
|
;; appropriate spot.
|
||||||
(goto-char (or
|
(goto-char (or
|
||||||
(and pre-process-p
|
(and export-props
|
||||||
(eq org-footnote-insert-pos-for-preprocessor 'point-min)
|
(eq org-footnote-insert-pos-for-preprocessor 'point-min)
|
||||||
(point-min))
|
(point-min))
|
||||||
ins-point
|
ins-point
|
||||||
|
@ -678,7 +695,7 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
|
||||||
"\n\n")
|
"\n\n")
|
||||||
;; When exporting, add newly insert markers along with their
|
;; When exporting, add newly insert markers along with their
|
||||||
;; associated definition to `org-export-footnotes-seen'.
|
;; associated definition to `org-export-footnotes-seen'.
|
||||||
(when pre-process-p
|
(when export-props
|
||||||
(setq org-export-footnotes-seen ref-table)))
|
(setq org-export-footnotes-seen ref-table)))
|
||||||
;; Else, insert each definition at the end of the section
|
;; Else, insert each definition at the end of the section
|
||||||
;; containing their first reference. Happens only in Org
|
;; containing their first reference. Happens only in Org
|
||||||
|
|
Loading…
Reference in New Issue