Browse Source

Merge branch 'maint'

Nicolas Goaziou 1 year ago
parent
commit
7df5d21f79
7 changed files with 129 additions and 38 deletions
  1. 2 2
      contrib/lisp/ox-koma-letter.el
  2. 1 9
      lisp/ox-html.el
  3. 1 10
      lisp/ox-md.el
  4. 2 6
      lisp/ox-odt.el
  5. 23 10
      lisp/ox-texinfo.el
  6. 30 1
      lisp/ox.el
  7. 70 0
      testing/lisp/test-ox.el

+ 2 - 2
contrib/lisp/ox-koma-letter.el

@@ -705,7 +705,7 @@ holding export options."
 	      (or (if (plist-get info :special-headings)
 		      (or heading-val keyword-val)
 		    (or keyword-val heading-val))
-		  "\\\\mbox{}"))))
+		  "\\mbox{}"))))
    ;; Opening.
    (format "\\opening{%s}\n\n"
 	   (org-koma-letter--keyword-or-headline
@@ -717,7 +717,7 @@ holding export options."
    (format "\\closing{%s}\n"
 	   (org-koma-letter--keyword-or-headline
 	    :closing (lambda (h i) (eq (org-koma-letter--special-tag h i)
-				       'closing))
+				  'closing))
 	    info))
    (org-koma-letter--special-contents-inline
     (plist-get info :special-tags-after-closing) info)

+ 1 - 9
lisp/ox-html.el

@@ -2328,15 +2328,7 @@ INFO is a plist used as a communication channel."
 			(org-element-property :priority headline)))
 	 (text (org-export-data-with-backend
 		(org-export-get-alt-title headline info)
-		;; Create an anonymous back-end that will ignore any
-		;; footnote-reference, link, radio-target and target
-		;; in table of contents.
-		(org-export-create-backend
-		 :parent 'html
-		 :transcoders '((footnote-reference . ignore)
-				(link . (lambda (object c i) c))
-				(radio-target . (lambda (object c i) c))
-				(target . ignore)))
+		(org-export-toc-entry-backend 'html)
 		info))
 	 (tags (and (eq (plist-get info :with-tags) t)
 		    (org-export-get-tags headline info))))

+ 1 - 10
lisp/ox-md.el

@@ -582,16 +582,7 @@ contents according to the current headline."
 	      (format "[%s](#%s)"
 		      (org-export-data-with-backend
 		       (org-export-get-alt-title headline info)
-		       ;; Create an anonymous back-end that will
-		       ;; ignore any footnote-reference, link,
-		       ;; radio-target and target in table of
-		       ;; contents.
-		       (org-export-create-backend
-			:parent 'md
-			:transcoders '((footnote-reference . ignore)
-				       (link . (lambda (object c i) c))
-				       (radio-target . (lambda (object c i) c))
-				       (target . ignore)))
+		       (org-export-toc-entry-backend 'md)
 		       info)
 		      (or (org-element-property :CUSTOM_ID headline)
 			  (org-export-get-reference headline info))))

+ 2 - 6
lisp/ox-odt.el

@@ -1159,12 +1159,8 @@ table of contents as a string, or nil."
   ;; Likewise, links, footnote references and regular targets are also
   ;; suppressed.
   (let* ((headlines (org-export-collect-headlines info depth scope))
-	 (backend (org-export-create-backend
-		   :parent (org-export-backend-name (plist-get info :back-end))
-		   :transcoders '((footnote-reference . ignore)
-				  (link . (lambda (object c i) c))
-				  (radio-target . (lambda (object c i) c))
-				  (target . ignore)))))
+	 (backend (org-export-toc-entry-backend
+		      (org-export-backend-name (plist-get info :back-end)))))
     (when headlines
       (org-odt--format-toc
        (and (not scope) (org-export-translate "Table of Contents" :utf-8 info))

+ 23 - 10
lisp/ox-texinfo.el

@@ -499,8 +499,12 @@ export state, as a plist."
    (org-export-create-backend
     :parent 'texinfo
     :transcoders '((footnote-reference . ignore)
-		   (link . (lambda (object c i) c))
-		   (radio-target . (lambda (object c i) c))
+		   (link . (lambda (l c i)
+			     (or c
+				 (org-export-data
+				  (org-element-property :raw-link l)
+				  i))))
+		   (radio-target . (lambda (_r c _i) c))
 		   (target . ignore)))
    info))
 
@@ -519,18 +523,27 @@ strings (e.g., returned by `org-export-get-caption')."
   (let* ((backend
 	  (org-export-create-backend
 	   :parent 'texinfo
-	   :transcoders '((link . (lambda (object c i) c))
-			  (radio-target . (lambda (object c i) c))
+	   :transcoders '((link . (lambda (l c i)
+				    (or c
+					(org-export-data
+					 (org-element-property :raw-link l)
+					 i))))
+			  (radio-target . (lambda (_r c _i) c))
 			  (target . ignore))))
 	 (short-backend
 	  (org-export-create-backend
 	   :parent 'texinfo
-	   :transcoders '((footnote-reference . ignore)
-			  (inline-src-block . ignore)
-			  (link . (lambda (object c i) c))
-			  (radio-target . (lambda (object c i) c))
-			  (target . ignore)
-			  (verbatim . ignore))))
+	   :transcoders
+	   '((footnote-reference . ignore)
+	     (inline-src-block . ignore)
+	     (link . (lambda (l c i)
+		       (or c
+			   (org-export-data
+			    (org-element-property :raw-link l)
+			    i))))
+	     (radio-target . (lambda (_r c _i) c))
+	     (target . ignore)
+	     (verbatim . ignore))))
 	 (short-str
 	  (if (and short caption)
 	      (format "@shortcaption{%s}\n"

+ 30 - 1
lisp/ox.el

@@ -5186,7 +5186,7 @@ return nil."
       info 'first-match)))
 
 
-;;;; For Tables Of Contents
+;;;; For Tables of Contents
 ;;
 ;; `org-export-collect-headlines' builds a list of all exportable
 ;; headline elements, maybe limited to a certain depth.  One can then
@@ -5196,6 +5196,9 @@ return nil."
 ;; Once the generic function `org-export-collect-elements' is defined,
 ;; `org-export-collect-tables', `org-export-collect-figures' and
 ;; `org-export-collect-listings' can be derived from it.
+;;
+;; `org-export-toc-entry-backend' builds a special anonymous back-end
+;; useful to export table of contents' entries.
 
 (defun org-export-collect-headlines (info &optional n scope)
   "Collect headlines in order to build a table of contents.
@@ -5281,6 +5284,32 @@ INFO is a plist used as a communication channel.
 Return a list of src-block elements with a caption."
   (org-export-collect-elements 'src-block info))
 
+(defun org-export-toc-entry-backend (parent &rest transcoders)
+  "Return an export back-end appropriate for table of contents entries.
+
+PARENT is an export back-end the returned back-end should inherit
+from.
+
+By default, the back-end removes footnote references and targets.
+It also changes links and radio targets into regular text.
+TRANSCODERS optional argument, when non-nil, specifies additional
+transcoders.  A transcoder follows the pattern (TYPE . FUNCTION)
+where type is an element or object type and FUNCTION the function
+transcoding it."
+  (declare (indent 1))
+  (org-export-create-backend
+   :parent parent
+   :transcoders
+   (append transcoders
+	   `((footnote-reference . ,#'ignore)
+	     (link . ,(lambda (l c i)
+			(or c
+			    (org-export-data
+			     (org-element-property :raw-link l)
+			     i))))
+	     (radio-target . ,(lambda (_r c _) c))
+	     (target . ,#'ignore)))))
+
 
 ;;;; Smart Quotes
 ;;

+ 70 - 0
testing/lisp/test-ox.el

@@ -4329,6 +4329,76 @@ Another text. (ref:text)
 	      (mapcar (lambda (h) (org-element-property :raw-value h))
 		      (org-export-collect-headlines info 1 scope)))))))
 
+(ert-deftest test-org-export/toc-entry-backend ()
+  "Test `org-export-toc-entry-backend' specifications."
+  ;; Ignore targets.
+  (should
+   (equal "H \n"
+	  (org-test-with-temp-text "* H <<target>>"
+	    (let (org-export-registered-backends)
+	      (org-export-define-backend 'test
+		'((headline . (lambda (h _c i) (org-export-data-with-backend
+					   (org-element-property :title h)
+					   (org-export-toc-entry-backend 'test)
+					   i)))))
+	      (org-export-as 'test)))))
+  ;; Ignore footnote references.
+  (should
+   (equal "H \n"
+	  (org-test-with-temp-text "[fn:1] Definition\n* H [fn:1]"
+	    (let (org-export-registered-backends)
+	      (org-export-define-backend 'test
+		'((headline . (lambda (h _c i) (org-export-data-with-backend
+					   (org-element-property :title h)
+					   (org-export-toc-entry-backend 'test)
+					   i)))))
+	      (org-export-as 'test)))))
+  ;; Replace plain links with contents, or with path.
+  (should
+   (equal "H Org mode\n"
+	  (org-test-with-temp-text "* H [[http://orgmode.org][Org mode]]"
+	    (let (org-export-registered-backends)
+	      (org-export-define-backend 'test
+		'((headline . (lambda (h _c i) (org-export-data-with-backend
+					   (org-element-property :title h)
+					   (org-export-toc-entry-backend 'test)
+					   i)))))
+	      (org-export-as 'test)))))
+  (should
+   (equal "H http://orgmode.org\n"
+	  (org-test-with-temp-text "* H [[http://orgmode.org]]"
+	    (let (org-export-registered-backends)
+	      (org-export-define-backend 'test
+		'((headline . (lambda (h _c i) (org-export-data-with-backend
+					   (org-element-property :title h)
+					   (org-export-toc-entry-backend 'test)
+					   i)))))
+	      (org-export-as 'test)))))
+  ;; Replace radio targets with contents.
+  (should
+   (equal "H radio\n"
+	  (org-test-with-temp-text "* H <<<radio>>>"
+	    (let (org-export-registered-backends)
+	      (org-export-define-backend 'test
+		'((headline . (lambda (h _c i) (org-export-data-with-backend
+					   (org-element-property :title h)
+					   (org-export-toc-entry-backend 'test)
+					   i)))))
+	      (org-export-as 'test)))))
+  ;; With optional argument TRANSCODERS, specify other
+  ;; transformations.
+  (should
+   (equal "H bold\n"
+	  (org-test-with-temp-text "* H *bold*"
+	    (let (org-export-registered-backends)
+	      (org-export-define-backend 'test
+		'((headline . (lambda (h _c i) (org-export-data-with-backend
+					   (org-element-property :title h)
+					   (org-export-toc-entry-backend 'test
+					     '(bold . (lambda (_b c _i) c)))
+					   i)))))
+	      (org-export-as 'test))))))
+
 
 
 ;;; Templates