diff --git a/contrib/lisp/org-e-ascii.el b/contrib/lisp/org-e-ascii.el index 654f688d4..c8bc33480 100644 --- a/contrib/lisp/org-e-ascii.el +++ b/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 ":")))))) diff --git a/contrib/lisp/org-e-html.el b/contrib/lisp/org-e-html.el index 2c25a6adc..5adb30522 100644 --- a/contrib/lisp/org-e-html.el +++ b/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) diff --git a/contrib/lisp/org-e-latex.el b/contrib/lisp/org-e-latex.el index 7acc8bfb1..67e9197ed 100644 --- a/contrib/lisp/org-e-latex.el +++ b/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 diff --git a/contrib/lisp/org-e-odt.el b/contrib/lisp/org-e-odt.el index 7d719cd05..4672bb97c 100644 --- a/contrib/lisp/org-e-odt.el +++ b/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 diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index e9fa2a286..58f1379de 100644 --- a/contrib/lisp/org-export.el +++ b/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." diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el index e1e77dc27..9aedbbab2 100644 --- a/testing/lisp/test-org-export.el +++ b/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