浏览代码

org-export: Hide select tags

* contrib/lisp/org-export.el (org-export-get-tags): New function.
* contrib/lisp/org-e-ascii.el (org-e-ascii--build-title): Use new function.
* contrib/lisp/org-e-html.el (org-e-html-format-headline--wrap,
  org-e-html-headline): Use new function.
* contrib/lisp/org-e-latex.el (org-e-latex-headline,
  org-e-latex-inlinetask): Use new function.
* contrib/lisp/org-e-odt.el (org-e-odt-format-headline--wrap): Use new
  function.
* testing/lisp/test-org-export.el: Add tests.
Nicolas Goaziou 13 年之前
父节点
当前提交
09164e5c72

+ 1 - 1
contrib/lisp/org-e-ascii.el

@@ -649,7 +649,7 @@ title."
 		 (and todo (concat (org-export-data todo info) " ")))))
 	 (tags (and (not notags)
 		    (plist-get info :with-tags)
-		    (let ((tag-list (org-element-property :tags element)))
+		    (let ((tag-list (org-export-get-tags element info)))
 		      (and tag-list
 			   (format ":%s:"
 				   (mapconcat 'identity tag-list ":"))))))

+ 2 - 2
contrib/lisp/org-e-html.el

@@ -2071,7 +2071,7 @@ holding contextual information."
 			(org-element-property :priority headline)))
 	 (text (org-export-data (org-element-property :title headline) info))
 	 (tags (and (plist-get info :with-tags)
-		    (org-element-property :tags headline)))
+		    (org-export-get-tags headline info)))
 	 (headline-label (concat "sec-" (mapconcat 'number-to-string
 						   headline-number "-")))
 	 (format-function (cond
@@ -2100,7 +2100,7 @@ holding contextual information."
 		      (and todo (org-export-data todo info)))))
 	 (todo-type (and todo (org-element-property :todo-type headline)))
 	 (tags (and (plist-get info :with-tags)
-		    (org-element-property :tags headline)))
+		    (org-export-get-tags headline info)))
 	 (priority (and (plist-get info :with-priority)
 			(org-element-property :priority headline)))
 	 (section-number (and (org-export-numbered-headline-p headline info)

+ 2 - 2
contrib/lisp/org-e-latex.el

@@ -1241,7 +1241,7 @@ holding contextual information."
 		 (and todo (org-export-data todo info)))))
 	 (todo-type (and todo (org-element-property :todo-type headline)))
 	 (tags (and (plist-get info :with-tags)
-		    (org-element-property :tags headline)))
+		    (org-export-get-tags headline info)))
 	 (priority (and (plist-get info :with-priority)
 			(org-element-property :priority headline)))
 	 ;; Create the headline text.
@@ -1360,7 +1360,7 @@ holding contextual information."
 		     (and todo (org-export-data todo info)))))
 	(todo-type (org-element-property :todo-type inlinetask))
 	(tags (and (plist-get info :with-tags)
-		   (org-element-property :tags inlinetask)))
+		   (org-export-get-tags inlinetask info)))
 	(priority (and (plist-get info :with-priority)
 		       (org-element-property :priority inlinetask))))
     ;; If `org-e-latex-format-inlinetask-function' is provided, call it

+ 1 - 1
contrib/lisp/org-e-odt.el

@@ -3080,7 +3080,7 @@ holding contextual information."
 			(org-element-property :priority headline)))
 	 (text (org-export-data (org-element-property :title headline) info))
 	 (tags (and (plist-get info :with-tags)
-		    (org-element-property :tags headline)))
+		    (org-export-get-tags headline info)))
 	 (headline-label (concat "sec-" (mapconcat 'number-to-string
 						   headline-number "-")))
 	 (format-function (cond

+ 16 - 0
contrib/lisp/org-export.el

@@ -2823,6 +2823,22 @@ INFO is a plist used as a communication channel."
 	  (pop roman)))
       res)))
 
+(defun org-export-get-tags (element info &optional tags)
+  "Return list of tags associated to ELEMENT.
+
+ELEMENT has either an `headline' or an `inlinetask' type.  INFO
+is a plist used as a communication channel.
+
+Select tags (see `org-export-select-tags') and exclude tags (see
+`org-export-exclude-tags') are removed from the list.
+
+When non-nil, optional argument TAGS should be a list of strings.
+Any tag belonging to this list will also be removed."
+  (org-remove-if (lambda (tag) (or (member tag (plist-get info :select-tags))
+			      (member tag (plist-get info :exclude-tags))
+			      (member tag tags)))
+		 (org-element-property :tags element)))
+
 (defun org-export-first-sibling-p (headline info)
   "Non-nil when HEADLINE is the first sibling in its sub-tree.
 INFO is the plist used as a communication channel."

+ 40 - 4
testing/lisp/test-org-export.el

@@ -16,10 +16,6 @@
 (unless (featurep 'org-export)
   (signal 'missing-test-dependency "org-export"))
 
-
-
-;;; Tests
-
 (defmacro org-test-with-backend (backend &rest body)
   "Execute body with an export back-end defined.
 
@@ -63,6 +59,10 @@ already filled in `info'."
 		   tree (org-export-get-environment))))
        ,@body)))
 
+
+
+;;; Tests
+
 (ert-deftest test-org-export/parse-option-keyword ()
   "Test reading all standard #+OPTIONS: items."
   (should
@@ -445,6 +445,42 @@ Paragraph[fn:1]"
 			 (org-export-as 'test 'subtree))))))))
 
 
+
+;;; Headlines and Inlinetasks
+
+(ert-deftest test-org-export/get-tags ()
+  "Test `org-export-get-tags' specifications."
+  (let ((org-export-exclude-tags '("noexport"))
+	(org-export-select-tags '("export")))
+    ;; Standard test: tags which are not a select tag, an exclude tag,
+    ;; or specified as optional argument shouldn't be ignored.
+    (should
+     (org-test-with-parsed-data "* Headline :tag:"
+       (org-export-get-tags (org-element-map tree 'headline 'identity info t)
+			    info)))
+    ;; Exclude tags are removed.
+    (should-not
+     (org-test-with-parsed-data "* Headline :noexport:"
+       (org-export-get-tags (org-element-map tree 'headline 'identity info t)
+			    info)))
+    ;; Select tags are removed.
+    (should-not
+     (org-test-with-parsed-data "* Headline :export:"
+       (org-export-get-tags (org-element-map tree 'headline 'identity info t)
+			    info)))
+    (should
+     (equal
+      '("tag")
+      (org-test-with-parsed-data "* Headline :tag:export:"
+	(org-export-get-tags (org-element-map tree 'headline 'identity info t)
+			     info))))
+    ;; Tags provided in the optional argument are also ignored.
+    (should-not
+     (org-test-with-parsed-data "* Headline :ignore:"
+       (org-export-get-tags (org-element-map tree 'headline 'identity info t)
+			    info '("ignore"))))))
+
+
 
 ;;; Links