Browse Source

ox-texinfo: Fix conflicts between @node and @anchor names

* lisp/ox-texinfo.el (org-texinfo--get-node): Prevent using reserved
  "Top" node.
(org-texinfo-radio-target):
(org-texinfo-src-block):
(org-texinfo-table):
(org-texinfo-target): Use `org-texinfo--get-node' instead of
`org-export-get-reference'.
Nicolas Goaziou 8 years ago
parent
commit
d44cadbe3e
1 changed files with 15 additions and 14 deletions
  1. 15 14
      lisp/ox-texinfo.el

+ 15 - 14
lisp/ox-texinfo.el

@@ -448,21 +448,22 @@ INFO is a plist used as a communication channel.  See
     ;; Else use format string.
     ;; Else use format string.
     (fmt (format fmt text))))
     (fmt (format fmt text))))
 
 
-(defun org-texinfo--get-node (blob info)
-  "Return node or anchor associated to BLOB.
-BLOB is an element or object.  INFO is a plist used as
+(defun org-texinfo--get-node (datum info)
+  "Return node or anchor associated to DATUM.
+DATUM is an element or object.  INFO is a plist used as
 a communication channel.  The function guarantees the node or
 a communication channel.  The function guarantees the node or
 anchor name is unique."
 anchor name is unique."
   (let ((cache (plist-get info :texinfo-node-cache)))
   (let ((cache (plist-get info :texinfo-node-cache)))
-    (or (cdr (assq blob cache))
+    (or (cdr (assq datum cache))
 	(let ((name
 	(let ((name
 	       (org-texinfo--sanitize-node
 	       (org-texinfo--sanitize-node
-		(if (eq (org-element-type blob) 'headline)
-		    (org-export-data (org-export-get-alt-title blob info) info)
-		  (org-export-get-reference blob info)))))
-	  ;; Ensure NAME is unique.
-	  (while (rassoc name cache) (setq name (concat name "x")))
-	  (plist-put info :texinfo-node-cache (cons (cons blob name) cache))
+		(if (eq (org-element-type datum) 'headline)
+		    (org-export-data (org-export-get-alt-title datum info) info)
+		  (org-export-get-reference datum info)))))
+	  ;; Ensure NAME is unique and not reserved node name "Top".
+	  (while (or (equal name "Top") (rassoc name cache))
+	    (setq name (concat name "x")))
+	  (plist-put info :texinfo-node-cache (cons (cons datum name) cache))
 	  name))))
 	  name))))
 
 
 (defun org-texinfo--sanitize-node (title)
 (defun org-texinfo--sanitize-node (title)
@@ -1266,7 +1267,7 @@ holding contextual information."
 TEXT is the text of the target.  INFO is a plist holding
 TEXT is the text of the target.  INFO is a plist holding
 contextual information."
 contextual information."
   (format "@anchor{%s}%s"
   (format "@anchor{%s}%s"
-	  (org-export-get-reference radio-target info)
+	  (org-texinfo--get-node radio-target info)
 	  text))
 	  text))
 
 
 ;;;; Section
 ;;;; Section
@@ -1314,7 +1315,7 @@ contextual information."
       (org-texinfo--wrap-float value
       (org-texinfo--wrap-float value
 			       info
 			       info
 			       (org-export-translate "Listing" :utf-8 info)
 			       (org-export-translate "Listing" :utf-8 info)
-			       (org-export-get-reference src-block info)
+			       (org-texinfo--get-node src-block info)
 			       caption
 			       caption
 			       shortcaption))))
 			       shortcaption))))
 
 
@@ -1373,7 +1374,7 @@ contextual information."
 	(org-texinfo--wrap-float table-str
 	(org-texinfo--wrap-float table-str
 				 info
 				 info
 				 (org-export-translate "Table" :utf-8 info)
 				 (org-export-translate "Table" :utf-8 info)
-				 (org-export-get-reference table info)
+				 (org-texinfo--get-node table info)
 				 caption
 				 caption
 				 shortcaption)))))
 				 shortcaption)))))
 
 
@@ -1441,7 +1442,7 @@ a communication channel."
   "Transcode a TARGET object from Org to Texinfo.
   "Transcode a TARGET object from Org to Texinfo.
 CONTENTS is nil.  INFO is a plist holding contextual
 CONTENTS is nil.  INFO is a plist holding contextual
 information."
 information."
-  (format "@anchor{%s}" (org-export-get-reference target info)))
+  (format "@anchor{%s}" (org-texinfo--get-node target info)))
 
 
 ;;;; Timestamp
 ;;;; Timestamp