浏览代码

Export: Fix bug with ID property search

Jan Bcker 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:
>
Carsten Dominik 15 年之前
父节点
当前提交
3672910d2f
共有 2 个文件被更改,包括 40 次插入32 次删除
  1. 5 0
      lisp/ChangeLog
  2. 35 32
      lisp/org-exp.el

+ 5 - 0
lisp/ChangeLog

@@ -1,3 +1,8 @@
+2010-04-16  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org-exp.el (org-export-define-heading-targets): Fix bug in
+	regexp finding ID and CUSTOM_ID properties.
+
 2010-04-14  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org-footnote.el (org-footnote-goto-previous-reference): Renamed

+ 35 - 32
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)