0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-08-26 07:32:52 +00:00

Export: Use custom IDs.

Users can now define custom IDs for use in HTML export.
These IDs are stores as property CUSTOM_ID.  When present, HTML will
prefer using these over automatic targets like "sec-N.M".
This commit is contained in:
Carsten Dominik 2009-04-16 18:19:20 +02:00
parent 02dc6813dc
commit 53d0746d8d
3 changed files with 45 additions and 18 deletions

View file

@ -1,5 +1,13 @@
2009-04-16 Carsten Dominik <carsten.dominik@gmail.com> 2009-04-16 Carsten Dominik <carsten.dominik@gmail.com>
* org-html.el (org-export-as-html): Use custom IDs in the toc.
* org-exp.el (org-export-preferred-target-alist): New variable.
(org-export-define-heading-targets): Find the new CUSTOM_ID
property.
(org-export-target-internal-links): Target the custom ids when
possible.
* org-latex.el (org-export-latex-preprocess): Better regexp for * org-latex.el (org-export-latex-preprocess): Better regexp for
matching latex macros with arguments. matching latex macros with arguments.

View file

@ -1125,6 +1125,8 @@ translations. There is currently no way for users to extend this.")
(defvar org-export-target-aliases nil (defvar org-export-target-aliases nil
"Alist of targets with invisible aliases.") "Alist of targets with invisible aliases.")
(defvar org-export-preferred-target-alist nil
"Alist of section id's with preferred aliases.")
(defvar org-export-code-refs nil (defvar org-export-code-refs nil
"Alist of code references and line numbers") "Alist of code references and line numbers")
@ -1317,19 +1319,24 @@ The new targets are added to TARGET-ALIST, which is also returned."
(goto-char (point-min)) (goto-char (point-min))
(org-init-section-numbers) (org-init-section-numbers)
(let ((re (concat "^" org-outline-regexp (let ((re (concat "^" org-outline-regexp
"\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)")) "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)"))
level target last-section-target a) level target last-section-target a id)
(while (re-search-forward re nil t) (while (re-search-forward re nil t)
(if (match-end 1) (if (match-end 2)
(progn (progn
(push (cons (org-match-string-no-properties 1) (setq id (org-match-string-no-properties 2))
target) target-alist) (push (cons id target) target-alist)
(setq a (or (assoc last-section-target org-export-target-aliases) (setq a (or (assoc last-section-target org-export-target-aliases)
(progn (progn
(push (list last-section-target) (push (list last-section-target)
org-export-target-aliases) org-export-target-aliases)
(car org-export-target-aliases)))) (car org-export-target-aliases))))
(push (caar target-alist) (cdr a))) (push (caar target-alist) (cdr a))
(when (equal (match-string 1) "CUSTOM_ID")
(if (not (assoc last-section-target
org-export-preferred-target-alist))
(push (cons last-section-target id)
org-export-preferred-target-alist))))
(setq level (org-reduced-level (setq level (org-reduced-level
(save-excursion (goto-char (point-at-bol)) (save-excursion (goto-char (point-at-bol))
(org-outline-level)))) (org-outline-level))))
@ -1386,7 +1393,10 @@ the current file."
((= (string-to-char link) ?#) ((= (string-to-char link) ?#)
;; user wants exactly this link ;; user wants exactly this link
link) link)
((cdr (assoc slink target-alist))) ((cdr (assoc slink target-alist))
(or (cdr (assoc (assoc slink target-alist)
org-export-preferred-target-alist))
(cdr (assoc slink target-alist))))
((and (string-match "^id:" link) ((and (string-match "^id:" link)
(cdr (assoc (substring link 3) target-alist)))) (cdr (assoc (substring link 3) target-alist))))
((string-match "^(\\(.*\\))$" link) ((string-match "^(\\(.*\\))$" link)

View file

@ -594,7 +594,7 @@ PUB-DIR is set, use this as the publishing directory."
rpl path attr desc descp desc1 desc2 link rpl path attr desc descp desc1 desc2 link
snumber fnc item-tag snumber fnc item-tag
footnotes footref-seen footnotes footref-seen
id-file id-file href
) )
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
@ -733,12 +733,14 @@ lang=\"%s\" xml:lang=\"%s\">
t t line))) t t line)))
(while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt) (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
(setq txt (replace-match "" t t txt))) (setq txt (replace-match "" t t txt)))
(setq href (format "sec-%s" snumber))
(setq href (or (cdr (assoc href org-export-preferred-target-alist)) href))
(push (push
(format (format
(if todo (if todo
"</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>" "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
"</li>\n<li><a href=\"#sec-%s\">%s</a>") "</li>\n<li><a href=\"#%s\">%s</a>")
snumber txt) thetoc) href txt) thetoc)
(setq org-last-level level)) (setq org-last-level level))
))) )))
@ -1811,15 +1813,19 @@ If there are links in the string, don't modify these."
When TITLE is nil, just close all open levels." When TITLE is nil, just close all open levels."
(org-close-par-maybe) (org-close-par-maybe)
(let* ((target (and title (org-get-text-property-any 0 'target title))) (let* ((target (and title (org-get-text-property-any 0 'target title)))
(extra-targets (extra-targets (assoc target org-export-target-aliases))
(preferred (cdr (assoc target org-export-preferred-target-alist)))
(remove (or preferred target))
(l org-level-max)
snumber href suffix)
(setq extra-targets (remove remove extra-targets))
(setq extra-targets
(mapconcat (lambda (x) (mapconcat (lambda (x)
(if (org-uuidgen-p x) (setq x (concat "ID-" x))) (if (org-uuidgen-p x) (setq x (concat "ID-" x)))
(format "<a name=\"%s\" id=\"%s\"></a>" (format "<a name=\"%s\" id=\"%s\"></a>"
x x)) x x))
(cdr (assoc target org-export-target-aliases)) extra-targets
"")) ""))
(l org-level-max)
snumber)
(while (>= l level) (while (>= l level)
(if (aref org-levels-open (1- l)) (if (aref org-levels-open (1- l))
(progn (progn
@ -1868,9 +1874,12 @@ When TITLE is nil, just close all open levels."
level snumber) level snumber)
" " title))) " " title)))
(unless (= head-count 1) (insert "\n</div>\n")) (unless (= head-count 1) (insert "\n</div>\n"))
(insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n" (setq href (cdr (assoc (concat "sec-" snumber) org-export-preferred-target-alist)))
snumber level level snumber extra-targets (setq suffix (or href (concat "sec-" snumber)))
title level level snumber)) (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
suffix level level href
extra-targets
title level level suffix))
(org-open-par))))) (org-open-par)))))
(defun org-export-html-get-tag-class-name (tag) (defun org-export-html-get-tag-class-name (tag)