From 3672910d2f9706f6a8fe7a1b065427863a803387 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Fri, 16 Apr 2010 05:12:19 +0200 Subject: [PATCH] Export: Fix bug with ID property search MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Jan Böcker writes: > If you have a headline with an elisp code block containing the following > line: > > " :ID:" > > the HTML code will be garbled at the beginning of the headline. > > I have attached a minimal test case and the resulting HTML file. The > #+OPTIONS: line is not needed, but is included to make the HTML file > less cluttered. > > There has to be whitespace between the " and :ID: and the string must be > ended on the same line. For example, these lines trigger the bug: > > " :ID:" > " :ID:" > " :ID: garble-my-html" > > while these do not: > > ":ID:" > ":ID: garble-my-html" > " :ID: > --- lisp/ChangeLog | 5 +++++ lisp/org-exp.el | 67 ++++++++++++++++++++++++++++++--------------------------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 29e420dd4..b58fab43e 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2010-04-16 Carsten Dominik + + * org-exp.el (org-export-define-heading-targets): Fix bug in + regexp finding ID and CUSTOM_ID properties. + 2010-04-14 Carsten Dominik * org-footnote.el (org-footnote-goto-previous-reference): Renamed diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 59308969a..da8e1a4be 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -1205,43 +1205,46 @@ on this string to produce the exported version." (defun org-export-define-heading-targets (target-alist) "Find all headings and define the targets for them. -The new targets are added to TARGET-ALIST, which is also returned." +The new targets are added to TARGET-ALIST, which is also returned. +Also find all ID and CUSTOM_ID propertiess and store them." (goto-char (point-min)) (org-init-section-numbers) (let ((re (concat "^" org-outline-regexp - "\\| [ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)")) + "\\|" + "^[ \t]*:\\(ID\\|CUSTOM_ID\\):[ \t]*\\([^ \t\r\n]+\\)")) level target last-section-target a id) (while (re-search-forward re nil t) - (if (match-end 2) - (progn - (setq id (org-match-string-no-properties 2)) - (push (cons id target) target-alist) - (setq a (or (assoc last-section-target org-export-target-aliases) - (progn - (push (list last-section-target) - org-export-target-aliases) - (car org-export-target-aliases)))) - (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))) - (when (equal (match-string 1) "ID") - (if (not (assoc last-section-target - org-export-id-target-alist)) - (push (cons last-section-target (concat "ID-" id)) - org-export-id-target-alist)))) - (setq level (org-reduced-level - (save-excursion (goto-char (point-at-bol)) - (org-outline-level)))) - (setq target (org-solidify-link-text - (format "sec-%s" (org-section-number level)))) - (setq last-section-target target) - (push (cons target target) target-alist) - (add-text-properties - (point-at-bol) (point-at-eol) - (list 'target target))))) + (org-if-unprotected-at (match-beginning 0) + (if (match-end 2) + (progn + (setq id (org-match-string-no-properties 2)) + (push (cons id target) target-alist) + (setq a (or (assoc last-section-target org-export-target-aliases) + (progn + (push (list last-section-target) + org-export-target-aliases) + (car org-export-target-aliases)))) + (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))) + (when (equal (match-string 1) "ID") + (if (not (assoc last-section-target + org-export-id-target-alist)) + (push (cons last-section-target (concat "ID-" id)) + org-export-id-target-alist)))) + (setq level (org-reduced-level + (save-excursion (goto-char (point-at-bol)) + (org-outline-level)))) + (setq target (org-solidify-link-text + (format "sec-%s" (org-section-number level)))) + (setq last-section-target target) + (push (cons target target) target-alist) + (add-text-properties + (point-at-bol) (point-at-eol) + (list 'target target)))))) target-alist) (defun org-export-handle-invisible-targets (target-alist) -- 2.11.4.GIT