* [PATCH] Enhance org-html--build-meta-info @ 2020-09-17 13:50 TEC 2020-09-17 14:21 ` TEC 2020-09-17 15:53 ` Jens Lechtenboerger 0 siblings, 2 replies; 43+ messages in thread From: TEC @ 2020-09-17 13:50 UTC (permalink / raw) To: org-mode-email [-- Attachment #1.1: Type: text/plain, Size: 374 bytes --] Hi All, This just replaces the current `org-html--build-meta-info' with a cleaner, more extensible (I also added a new variable) version. Please give it a look and let me know what you think! Timothy. <#part type="text/x-patch" filename="/home/tec/.emacs.d/.local/straight/repos/org-mode/0001-lisp-ox-html.el-make-html-meta-func-nicer.patch" disposition=inline> <#/part> [-- Attachment #1.2: Type: text/html, Size: 2250 bytes --] ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-09-17 13:50 [PATCH] Enhance org-html--build-meta-info TEC @ 2020-09-17 14:21 ` TEC 2020-09-17 15:53 ` Jens Lechtenboerger 1 sibling, 0 replies; 43+ messages in thread From: TEC @ 2020-09-17 14:21 UTC (permalink / raw) To: org-mode-email TEC <tecosaur@gmail.com> writes: > <#part type=“text/x-patch” filename=“home/tec.emacs.d/.local/straight/repos/org-mode/0001-lisp-ox-html.el-make-html-meta-func-nicer.patch” > disposition=inline> > <#/part> I have no idea what I need to do to get Mu4e to attach files, but I'm clearly not doing it right. Here's the patch inline: From ae830f0be92c0b5ac3a9fb3d967a24d4292a1a4d Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Subject: [PATCH] lisp/ox-html.el: make html meta func nicer * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated structure extracted to new function `org-html--build-meta-entry'. The opportunity was taken to extract most metadata info to custom variable `org-html-meta-tags', allowing for easy end-user modification. --- lisp/ox-html.el | 111 ++++++++++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 50 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index d2f24f5c6..901f1a379 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1425,6 +1425,28 @@ not be modified." ;;;; Template :: Styles +(defcustom org-html-meta-tags + '((lambda (_title author _info) + (when (org-string-nw-p author) + (org-html--build-meta-entry "name" "author" author))) + (lambda (_title _author info) + (when (org-string-nw-p (plist-get info :description)) + (org-html--build-meta-entry "name" "description" + (plist-get info :description)))) + ("name" "generator" "Org Mode")) + "A list of arguments to be passed to `org-html--build-meta-entry'. +Each argument can either be an list which is applied, or a function which +generates such a list with signature (TITLE AUTHOR INFO) where TITLE and AUTHOR +are strings, and INFO a communication plist." + :group 'org-export-html + :package-version '(Org . "9.5") + :type '(repeat + (choice + (list (string :tag "Meta label") + (string :tag "label value") + (string :tag "Content value")) + function))) + (defcustom org-html-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-html-style-default' and @@ -1835,23 +1857,31 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) + "Construct <meta> tag with LABEL=\"IDENTITY\" and content from CONTENT-FORMAT and CONTENT-FORMATTER." + (concat "<meta " + (format "%s=\"%s" label identity) + (when content-format + (concat "\" content=\"" + (replace-regexp-in-string + "\"" """ + (org-html-encode-plain-text + (if content-formatters + (apply #'format content-format content-formatters) + content-format))))) + "\" />\n")) + (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((protect-string - (lambda (str) - (replace-regexp-in-string - "\"" """ (org-html-encode-plain-text str)))) - (title (org-export-data (plist-get info :title) info)) + (let* ((title (org-export-data (plist-get info :title) info)) ;; Set title to an invisible character instead of leaving it ;; empty, which is invalid. (title (if (org-string-nw-p title) title "‎")) (author (and (plist-get info :with-author) (let ((auth (plist-get info :author))) - ;; Return raw Org syntax. + ;; Return raw Org syntax. (and auth (org-element-interpret-data auth))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords)) (charset (or (and org-html-coding-system (fboundp 'coding-system-get) (coding-system-get org-html-coding-system @@ -1863,50 +1893,31 @@ INFO is a plist used as a communication channel." (concat "<!-- " (plist-get info :html-metadata-timestamp-format) " -->\n"))) - (format - (if (org-html-html5-p info) - (org-html-close-tag "meta" "charset=\"%s\"" info) - (org-html-close-tag - "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" - info)) - charset) "\n" + + (if (org-html-html5-p info) + (org-html--build-meta-entry "charset" charset) + (org-html--build-meta-entry "http-equiv" "Content-Type" + (concat "text/html;charset=" charset))) + (let ((viewport-options - (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) - (plist-get info :html-viewport)))) - (and viewport-options - (concat - (org-html-close-tag - "meta" - (format "name=\"viewport\" content=\"%s\"" - (mapconcat - (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) - viewport-options ", ")) - info) - "\n"))) + (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) + (plist-get info :html-viewport)))) + (if viewport-options + (org-html--build-meta-entry "name" "viewport" + (mapconcat + (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) + viewport-options ", ")))) + (format "<title>%s</title>\n" title) - (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info) - "\n" - (and (org-string-nw-p author) - (concat - (org-html-close-tag "meta" - (format "name=\"author\" content=\"%s\"" - (funcall protect-string author)) - info) - "\n")) - (and (org-string-nw-p description) - (concat - (org-html-close-tag "meta" - (format "name=\"description\" content=\"%s\"\n" - (funcall protect-string description)) - info) - "\n")) - (and (org-string-nw-p keywords) - (concat - (org-html-close-tag "meta" - (format "name=\"keywords\" content=\"%s\"" - (funcall protect-string keywords)) - info) - "\n"))))) + + (apply #'concat + (mapcar + (lambda (form) + (when (functionp form) + (setq form (funcall form title author info))) + (when form + (apply #'org-html--build-meta-entry form))) + org-html-meta-tags))))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.28.0 ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-09-17 13:50 [PATCH] Enhance org-html--build-meta-info TEC 2020-09-17 14:21 ` TEC @ 2020-09-17 15:53 ` Jens Lechtenboerger 2020-09-17 16:14 ` TEC 1 sibling, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2020-09-17 15:53 UTC (permalink / raw) To: TEC; +Cc: org-mode-email [-- Attachment #1: Type: text/plain, Size: 1617 bytes --] On 2020-09-17, TEC wrote: > Hi All, > > This just replaces the current `org-html--build-meta-info' with a > cleaner, more extensible (I also added a new variable) > version. Please give it a look and let me know what you think! Hi Timothy, yes, I agree that org-html--build-meta-info needs work, and the HTML backend would benefit from more documentation. Back then [1], I wondered which parts of meta data need to be treated how. That was continued in thread [2]. As pointed out back then, using org-export-data on the title is wrong as it creates nested elements, leading to invalid HTML. Currently, org-element-interpret-data is applied for author information, while description and keywords are treated differently. Your patch goes for org-html-encode-plain-text in the new function org-html--build-meta-entry, which (if I’m not mistaken) produces author and description. Did you think about using org-element-interpret-data instead? What if that was used? I believe this to be an important question as it might affect backward compatibility and should be documented. Does this really work for you? For the author, first org-html--build-meta-entry gets called from the new defcustom. The result is assigned with setq to form, which then is non-nil so that org-html--build-meta-entry is applied again, leading to an error here. Besides, did you forget keywords or remove them on purpose? Best wishes Jens [1] https://lists.gnu.org/archive/html/emacs-orgmode/2019-09/msg00193.html [2] https://lists.gnu.org/archive/html/emacs-orgmode/2020-02/msg00368.html [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5290 bytes --] ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-09-17 15:53 ` Jens Lechtenboerger @ 2020-09-17 16:14 ` TEC 2020-09-18 8:11 ` Jens Lechtenboerger 0 siblings, 1 reply; 43+ messages in thread From: TEC @ 2020-09-17 16:14 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: org-mode-email Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > Hi Timothy, Hi Jens! Thanks for responding. > yes, I agree that org-html--build-meta-info needs work, and the HTML > backend would benefit from more documentation. Back then [1], I > wondered which parts of meta data need to be treated how. That was > continued in thread [2]. I haven't really considered changing the output of the function (other than removing keywords). Reading the email you've linked to, it looks like a change to `org-html-encode-plain-text' would be a good idea though. > As pointed out back then, using org-export-data on the title is > wrong as it creates nested elements, leading to invalid HTML. > > Currently, org-element-interpret-data is applied for author > information, while description and keywords are treated differently. > Your patch goes for org-html-encode-plain-text in the new function > org-html--build-meta-entry, which (if I’m not mistaken) produces > author and description. Did you think about using > org-element-interpret-data instead? What if that was used? > I believe this to be an important question as it might affect > backward compatibility and should be documented. I was not aware of org-element-interpret-data, and I can't say I can really tell what it does. If you'd care to elaborate that would be helpful. > Does this really work for you? For the author, first > org-html--build-meta-entry gets called from the new defcustom. The > result is assigned with setq to form, which then is non-nil so that > org-html--build-meta-entry is applied again, leading to an error > here. Ooops, I forgot to remove org-html--build-meta-entry from the defcustom. (I didn't notice because I overwrite it anyway in my personal config). > Besides, did you forget keywords or remove them on purpose? This is a deliberate omission. My impression is that the value of keywords in HTML documents has evaporated over the past decade, see: https://yoast.com/meta-keywords/ Let me know if you know otherwise. > Best wishes > Jens Thanks for your feedback! Timothy. ----- Updated patch: From 3a02e4d3bce5f7f0cbdb34c98f4267cea40eec3e Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Subject: [PATCH] lisp/ox-html.el: make html meta func nicer * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated structure extracted to new function `org-html--build-meta-entry'. The opportunity was taken to extract most metadata info to custom variable `org-html-meta-tags', allowing for easy end-user modification. --- lisp/ox-html.el | 111 ++++++++++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 50 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index d2f24f5c6..df7da1a68 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1425,6 +1425,28 @@ not be modified." ;;;; Template :: Styles +(defcustom org-html-meta-tags + '((lambda (_title author _info) + (when (org-string-nw-p author) + (list "name" "author" author))) + (lambda (_title _author info) + (when (org-string-nw-p (plist-get info :description)) + (list "name" "description" + (plist-get info :description)))) + ("name" "generator" "Org Mode")) + "A list of arguments to be passed to `org-html--build-meta-entry'. +Each argument can either be an list which is applied, or a function which +generates such a list with signature (TITLE AUTHOR INFO) where TITLE and AUTHOR +are strings, and INFO a communication plist." + :group 'org-export-html + :package-version '(Org . "9.5") + :type '(repeat + (choice + (list (string :tag "Meta label") + (string :tag "label value") + (string :tag "Content value")) + function))) + (defcustom org-html-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-html-style-default' and @@ -1835,23 +1857,31 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) + "Construct <meta> tag with LABEL=\"IDENTITY\" and content from CONTENT-FORMAT and CONTENT-FORMATTER." + (concat "<meta " + (format "%s=\"%s" label identity) + (when content-format + (concat "\" content=\"" + (replace-regexp-in-string + "\"" """ + (org-html-encode-plain-text + (if content-formatters + (apply #'format content-format content-formatters) + content-format))))) + "\" />\n")) + (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((protect-string - (lambda (str) - (replace-regexp-in-string - "\"" """ (org-html-encode-plain-text str)))) - (title (org-export-data (plist-get info :title) info)) + (let* ((title (org-html-encode-plain-text (plist-get info :title) info)) ;; Set title to an invisible character instead of leaving it ;; empty, which is invalid. (title (if (org-string-nw-p title) title "‎")) (author (and (plist-get info :with-author) (let ((auth (plist-get info :author))) - ;; Return raw Org syntax. + ;; Return raw Org syntax. (and auth (org-element-interpret-data auth))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords)) (charset (or (and org-html-coding-system (fboundp 'coding-system-get) (coding-system-get org-html-coding-system @@ -1863,50 +1893,31 @@ INFO is a plist used as a communication channel." (concat "<!-- " (plist-get info :html-metadata-timestamp-format) " -->\n"))) - (format - (if (org-html-html5-p info) - (org-html-close-tag "meta" "charset=\"%s\"" info) - (org-html-close-tag - "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" - info)) - charset) "\n" + + (if (org-html-html5-p info) + (org-html--build-meta-entry "charset" charset) + (org-html--build-meta-entry "http-equiv" "Content-Type" + (concat "text/html;charset=" charset))) + (let ((viewport-options - (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) - (plist-get info :html-viewport)))) - (and viewport-options - (concat - (org-html-close-tag - "meta" - (format "name=\"viewport\" content=\"%s\"" - (mapconcat - (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) - viewport-options ", ")) - info) - "\n"))) + (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) + (plist-get info :html-viewport)))) + (if viewport-options + (org-html--build-meta-entry "name" "viewport" + (mapconcat + (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) + viewport-options ", ")))) + (format "<title>%s</title>\n" title) - (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info) - "\n" - (and (org-string-nw-p author) - (concat - (org-html-close-tag "meta" - (format "name=\"author\" content=\"%s\"" - (funcall protect-string author)) - info) - "\n")) - (and (org-string-nw-p description) - (concat - (org-html-close-tag "meta" - (format "name=\"description\" content=\"%s\"\n" - (funcall protect-string description)) - info) - "\n")) - (and (org-string-nw-p keywords) - (concat - (org-html-close-tag "meta" - (format "name=\"keywords\" content=\"%s\"" - (funcall protect-string keywords)) - info) - "\n"))))) + + (apply #'concat + (mapcar + (lambda (form) + (when (functionp form) + (setq form (funcall form title author info))) + (when form + (apply #'org-html--build-meta-entry form))) + org-html-meta-tags))))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.28.0 ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-09-17 16:14 ` TEC @ 2020-09-18 8:11 ` Jens Lechtenboerger 2020-09-25 17:48 ` TEC 0 siblings, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2020-09-18 8:11 UTC (permalink / raw) To: TEC; +Cc: org-mode-email On 2020-09-18, TEC wrote: > Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > [...] > I was not aware of org-element-interpret-data, and I can't say I can > really tell what it does. If you'd care to elaborate that would be > helpful. Hi Timothy, I don’t know why that is used. For this test case: #+begin_src org ,#+TITLE: A title with *bold* index_1^2 and characters &ß<" ,#+AUTHOR: An /emphasized/ "anonymous" author_1^2 with [[https://example.org][hyperlink]] and characters &ß<" ,#+DESCRIPTION: A description_1^2 with /emphasis/ and [[https://example.org][hyperlink]] and characters &ß<" Test #+end_src I get this with Org master: #+begin_src html <title>A title with <b>bold</b> index<sub>1</sub><sup>2</sup> and characters &ß<"</title> <meta name="author" content="An /emphasized/ "anonymous" author_1^2 with [[https://example.org][hyperlink]] and characters &ß<"" /> <meta name="description" content="A description_1^2 with /emphasis/ and [[https://example.org][hyperlink]] and characters &ß<"" #+end_src The title is not valid HTML. I suggest to export it with Org syntax. I cannot see a difference between the handling of author and description. So, for this example, org-element-interpret-data is not necessary for author. I don’t know whether others have author information where a difference would be visible. My suggestion would be to go with the handling of description in all cases, including the title. >> Besides, did you forget keywords or remove them on purpose? > > This is a deliberate omission. My impression is that the value of > keywords in HTML documents has evaporated over the past decade, see: > https://yoast.com/meta-keywords/ I added keywords to my OER presentations because some crawlers use them to extract topics for classification of documents. I’d like to keep that. Best wishes Jens ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-09-18 8:11 ` Jens Lechtenboerger @ 2020-09-25 17:48 ` TEC 2020-09-27 15:17 ` Jens Lechtenboerger 0 siblings, 1 reply; 43+ messages in thread From: TEC @ 2020-09-25 17:48 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: org-mode-email @Maintainers I think this is ready for a review. Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > My suggestion would be to go with the handling of description in all > cases, including the title. Currently the only element handled differently to `org-html-encode-plain-text' is "author". I don't know why so I don't want to touch it. > I added keywords to my OER presentations because some crawlers use > them to extract topics for classification of documents. I’d like to > keep that. Re-added. Let me know if there's anything else, Timothy. ----- Updated patch below: From da3878493a8c7097bf44add925696ede86ede661 Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Subject: [PATCH] lisp/ox-html.el: make html meta func nicer * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated structure extracted to new function `org-html--build-meta-entry'. The opportunity was taken to extract most metadata info to custom variable `org-html-meta-tags', allowing for easy end-user modification. --- lisp/ox-html.el | 115 +++++++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 50 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index d2f24f5c6..6efb76e12 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1425,6 +1425,28 @@ not be modified." ;;;; Template :: Styles +(defcustom org-html-meta-tags + '((lambda (_title author _info) + (when (org-string-nw-p author) + (list "name" "author" author))) + (lambda (_title _author info) + (when (org-string-nw-p (plist-get info :description)) + (list "name" "description" + (plist-get info :description)))) + ("name" "generator" "Org Mode")) + "A list of arguments to be passed to `org-html--build-meta-entry'. +Each argument can either be an list which is applied, or a function which +generates such a list with signature (TITLE AUTHOR INFO) where TITLE and AUTHOR +are strings, and INFO a communication plist." + :group 'org-export-html + :package-version '(Org . "9.5") + :type '(repeat + (choice + (list (string :tag "Meta label") + (string :tag "label value") + (string :tag "Content value")) + function))) + (defcustom org-html-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-html-style-default' and @@ -1835,23 +1857,32 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) + "Construct <meta> tag with LABEL=\"IDENTITY\" and content from CONTENT-FORMAT and CONTENT-FORMATTER." + (concat "<meta " + (format "%s=\"%s" label identity) + (when content-format + (concat "\" content=\"" + (replace-regexp-in-string + "\"" """ + (org-html-encode-plain-text + (if content-formatters + (apply #'format content-format content-formatters) + content-format))))) + "\" />\n")) + (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((protect-string - (lambda (str) - (replace-regexp-in-string - "\"" """ (org-html-encode-plain-text str)))) - (title (org-export-data (plist-get info :title) info)) + (let* ((title (org-html-encode-plain-text (plist-get info :title) info)) ;; Set title to an invisible character instead of leaving it ;; empty, which is invalid. (title (if (org-string-nw-p title) title "‎")) (author (and (plist-get info :with-author) (let ((auth (plist-get info :author))) - ;; Return raw Org syntax. + ;; Return raw Org syntax. (and auth (org-element-interpret-data auth))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords)) + (keywords (plist-get info :keywords)) (charset (or (and org-html-coding-system (fboundp 'coding-system-get) (coding-system-get org-html-coding-system @@ -1863,50 +1894,34 @@ INFO is a plist used as a communication channel." (concat "<!-- " (plist-get info :html-metadata-timestamp-format) " -->\n"))) - (format - (if (org-html-html5-p info) - (org-html-close-tag "meta" "charset=\"%s\"" info) - (org-html-close-tag - "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" - info)) - charset) "\n" + + (if (org-html-html5-p info) + (org-html--build-meta-entry "charset" charset) + (org-html--build-meta-entry "http-equiv" "Content-Type" + (concat "text/html;charset=" charset))) + (let ((viewport-options - (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) - (plist-get info :html-viewport)))) - (and viewport-options - (concat - (org-html-close-tag - "meta" - (format "name=\"viewport\" content=\"%s\"" - (mapconcat - (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) - viewport-options ", ")) - info) - "\n"))) + (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) + (plist-get info :html-viewport)))) + (if viewport-options + (org-html--build-meta-entry "name" "viewport" + (mapconcat + (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) + viewport-options ", ")))) + (format "<title>%s</title>\n" title) - (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info) - "\n" - (and (org-string-nw-p author) - (concat - (org-html-close-tag "meta" - (format "name=\"author\" content=\"%s\"" - (funcall protect-string author)) - info) - "\n")) - (and (org-string-nw-p description) - (concat - (org-html-close-tag "meta" - (format "name=\"description\" content=\"%s\"\n" - (funcall protect-string description)) - info) - "\n")) - (and (org-string-nw-p keywords) - (concat - (org-html-close-tag "meta" - (format "name=\"keywords\" content=\"%s\"" - (funcall protect-string keywords)) - info) - "\n"))))) + + (when keywords + (org-html--build-meta-entry "keywords" keywords)) + + (apply #'concat + (mapcar + (lambda (form) + (when (functionp form) + (setq form (funcall form title author info))) + (when form + (apply #'org-html--build-meta-entry form))) + org-html-meta-tags))))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.28.0 ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-09-25 17:48 ` TEC @ 2020-09-27 15:17 ` Jens Lechtenboerger 2020-09-27 17:39 ` TEC 0 siblings, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2020-09-27 15:17 UTC (permalink / raw) To: TEC; +Cc: org-mode-email On 2020-09-26, TEC wrote: > @Maintainers I think this is ready for a review. > > Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > >> My suggestion would be to go with the handling of description in all >> cases, including the title. > > Currently the only element handled differently to > `org-html-encode-plain-text' is "author". I don't know why so I don't > want to touch it. I believe that was also the previous conclusion. However, as this is not documented, maybe now could be the chance to change this? >> I added keywords to my OER presentations because some crawlers use >> them to extract topics for classification of documents. I’d like to >> keep that. > > Re-added. > > Let me know if there's anything else, I must I admit that I do not fully understand your approach. Why do you treat keywords and description differently (with description in org-html-meta-tags and keywords in org-html--build-meta-info)? Why do you pass _title into the lambda expressions in org-html-meta-tags when it is never used? Currently, the variable org-html-meta-tags does not seem user-friendly to me. Also, in org-html--build-meta-info you call org-html-encode-plain-text with two arguments, but it just accepts one. Best wishes Jens ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-09-27 15:17 ` Jens Lechtenboerger @ 2020-09-27 17:39 ` TEC 2020-09-27 18:00 ` Jens Lechtenboerger 0 siblings, 1 reply; 43+ messages in thread From: TEC @ 2020-09-27 17:39 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: org-mode-email Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: >> Currently the only element handled differently to >> `org-html-encode-plain-text' is "author". I don't know why so I >> don't >> want to touch it. > > I believe that was also the previous conclusion. However, as > this > is not documented, maybe now could be the chance to change this? Hmm. Maybe, it sounds like some tests may be in order. > I must I admit that I do not fully understand your approach. > > Why do you treat keywords and description differently (with > description in org-html-meta-tags and keywords in > org-html--build-meta-info)? Ooops, that should have been in org-html-meta-tags as the rest are. [Fixed] > Why do you pass _title into the lambda expressions in > org-html-meta-tags when it is never used? Currently, the > variable > org-html-meta-tags does not seem user-friendly to me. Title and author just seemed like the most likely useful information for customisation. It would be nice if it looked less boiler-plate-y, but I'm not sure what the best approach for that would be, and it's already miles better than the current. If you have any ideas, please let me know. > Also, in org-html--build-meta-info you call > org-html-encode-plain-text with two arguments, but it just > accepts > one. ? No I don't. > Best wishes > Jens Hope that clarifies things a bit, Timothy. ------ Moved the keyword in with the rest. From 889ae918aed267417825d565df9135221dae16b1 Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Subject: [PATCH] lisp/ox-html.el: make html meta func nicer * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated structure extracted to new function `org-html--build-meta-entry'. The opportunity was taken to extract most metadata info to custom variable `org-html-meta-tags', allowing for easy end-user modification. --- lisp/ox-html.el | 114 +++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 50 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index d2f24f5c6..46195b0e0 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1425,6 +1425,31 @@ not be modified." ;;;; Template :: Styles +(defcustom org-html-meta-tags + '((lambda (_title author _info) + (when (org-string-nw-p author) + (list "name" "author" author))) + (lambda (_title _author info) + (when (org-string-nw-p (plist-get info :description)) + (list "name" "description" + (plist-get info :description)))) + (lambda (_title _author info) + (when (org-string-nw-p (plist-get info :keywords)) + (list "keywords" (plist-get info :keywords)))) + ("name" "generator" "Org Mode")) + "A list of arguments to be passed to `org-html--build-meta-entry'. +Each argument can either be an list which is applied, or a function which +generates such a list with signature (TITLE AUTHOR INFO) where TITLE and AUTHOR +are strings, and INFO a communication plist." + :group 'org-export-html + :package-version '(Org . "9.5") + :type '(repeat + (choice + (list (string :tag "Meta label") + (string :tag "label value") + (string :tag "Content value")) + function))) + (defcustom org-html-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-html-style-default' and @@ -1835,23 +1860,31 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) + "Construct <meta> tag with LABEL=\"IDENTITY\" and content from CONTENT-FORMAT and CONTENT-FORMATTER." + (concat "<meta " + (format "%s=\"%s" label identity) + (when content-format + (concat "\" content=\"" + (replace-regexp-in-string + "\"" """ + (org-html-encode-plain-text + (if content-formatters + (apply #'format content-format content-formatters) + content-format))))) + "\" />\n")) + (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((protect-string - (lambda (str) - (replace-regexp-in-string - "\"" """ (org-html-encode-plain-text str)))) - (title (org-export-data (plist-get info :title) info)) + (let* ((title (org-html-encode-plain-text (plist-get info :title) info)) ;; Set title to an invisible character instead of leaving it ;; empty, which is invalid. (title (if (org-string-nw-p title) title "‎")) (author (and (plist-get info :with-author) (let ((auth (plist-get info :author))) - ;; Return raw Org syntax. + ;; Return raw Org syntax. (and auth (org-element-interpret-data auth))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords)) (charset (or (and org-html-coding-system (fboundp 'coding-system-get) (coding-system-get org-html-coding-system @@ -1863,50 +1896,31 @@ INFO is a plist used as a communication channel." (concat "<!-- " (plist-get info :html-metadata-timestamp-format) " -->\n"))) - (format - (if (org-html-html5-p info) - (org-html-close-tag "meta" "charset=\"%s\"" info) - (org-html-close-tag - "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" - info)) - charset) "\n" + + (if (org-html-html5-p info) + (org-html--build-meta-entry "charset" charset) + (org-html--build-meta-entry "http-equiv" "Content-Type" + (concat "text/html;charset=" charset))) + (let ((viewport-options - (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) - (plist-get info :html-viewport)))) - (and viewport-options - (concat - (org-html-close-tag - "meta" - (format "name=\"viewport\" content=\"%s\"" - (mapconcat - (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) - viewport-options ", ")) - info) - "\n"))) + (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) + (plist-get info :html-viewport)))) + (if viewport-options + (org-html--build-meta-entry "name" "viewport" + (mapconcat + (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) + viewport-options ", ")))) + (format "<title>%s</title>\n" title) - (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info) - "\n" - (and (org-string-nw-p author) - (concat - (org-html-close-tag "meta" - (format "name=\"author\" content=\"%s\"" - (funcall protect-string author)) - info) - "\n")) - (and (org-string-nw-p description) - (concat - (org-html-close-tag "meta" - (format "name=\"description\" content=\"%s\"\n" - (funcall protect-string description)) - info) - "\n")) - (and (org-string-nw-p keywords) - (concat - (org-html-close-tag "meta" - (format "name=\"keywords\" content=\"%s\"" - (funcall protect-string keywords)) - info) - "\n"))))) + + (apply #'concat + (mapcar + (lambda (form) + (when (functionp form) + (setq form (funcall form title author info))) + (when form + (apply #'org-html--build-meta-entry form))) + org-html-meta-tags))))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.28.0 ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-09-27 17:39 ` TEC @ 2020-09-27 18:00 ` Jens Lechtenboerger 2020-09-27 18:35 ` TEC 0 siblings, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2020-09-27 18:00 UTC (permalink / raw) To: TEC; +Cc: org-mode-email On 2020-09-28, TEC wrote: > Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: >> Also, in org-html--build-meta-info you call >> org-html-encode-plain-text with two arguments, but it just accepts >> one. > > ? No I don't. Your patch contains this: + (let* ((title (org-html-encode-plain-text (plist-get info :title) info)) Best wishes Jens ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-09-27 18:00 ` Jens Lechtenboerger @ 2020-09-27 18:35 ` TEC 2020-09-28 8:17 ` Jens Lechtenboerger 0 siblings, 1 reply; 43+ messages in thread From: TEC @ 2020-09-27 18:35 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: org-mode-email Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > On 2020-09-28, TEC wrote: > >> Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: >>> Also, in org-html--build-meta-info you call >>> org-html-encode-plain-text with two arguments, but it just >>> accepts >>> one. >> >> ? No I don't. > > Your patch contains this: > > + (let* ((title (org-html-encode-plain-text (plist-get info > :title) > info)) Ohhhh, that's the bit you were referring to. That's just copied from the current state (iirc). Anyway, I dropped the second argument. Thanks, Timothy. ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-09-27 18:35 ` TEC @ 2020-09-28 8:17 ` Jens Lechtenboerger 2020-12-13 16:12 ` TEC 0 siblings, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2020-09-28 8:17 UTC (permalink / raw) To: TEC; +Cc: org-mode-email On 2020-09-28, TEC wrote: > Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > >> On 2020-09-28, TEC wrote: >> >>> Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: >>>> Also, in org-html--build-meta-info you call >>>> org-html-encode-plain-text with two arguments, but it just accepts >>>> one. >>> >>> ? No I don't. >> >> Your patch contains this: >> >> + (let* ((title (org-html-encode-plain-text (plist-get info :title) >> info)) > > Ohhhh, that's the bit you were referring to. That's just copied from > the > current state (iirc). Anyway, I dropped the second argument. Without the second argument I get an error “Wrong type argument: stringp,” when evaluating regular expressions against the cons cell that is returned as title. As I see now, author and title are cons cells, which is why org-element-interpret-data is necessary to produce strings with Org syntax. Also, after fixing the title, I get “wrong-type-argument sequencep utf-8” for “(concat "text/html;charset=" charset)”. Best wishes Jens ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-09-28 8:17 ` Jens Lechtenboerger @ 2020-12-13 16:12 ` TEC 2020-12-14 6:04 ` Bastien 0 siblings, 1 reply; 43+ messages in thread From: TEC @ 2020-12-13 16:12 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: org-mode-email [-- Attachment #1: Type: text/plain, Size: 600 bytes --] Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > Without the second argument I get an error “Wrong type argument: > stringp,” when evaluating regular expressions against the cons cell > that is returned as title. > > As I see now, author and title are cons cells, which is why > org-element-interpret-data is necessary to produce strings with Org > syntax. > > Also, after fixing the title, I get “wrong-type-argument sequencep > utf-8” for “(concat "text/html;charset=" charset)”. Thanks for testing this :) I haven't forgotten about this. Next version! [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-lisp-ox-html.el-make-html-meta-func-nicer.patch --] [-- Type: text/x-patch, Size: 6662 bytes --] From 1289e381aff7562df96945aa58838ad966aa9211 Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Thu, 17 Sep 2020 21:27:18 +0800 Subject: [PATCH] lisp/ox-html.el: make html meta func nicer * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated structure extracted to new function `org-html--build-meta-entry'. The opportunity was taken to extract most metadata info to custom variable `org-html-meta-tags', allowing for easy end-user modification. --- lisp/ox-html.el | 131 +++++++++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 58 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index d2f24f5c6..93014e9c7 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1425,6 +1425,31 @@ not be modified." ;;;; Template :: Styles +(defcustom org-html-meta-tags + '((lambda (_title author _info) + (when (org-string-nw-p author) + (list "name" "author" author))) + (lambda (_title _author info) + (when (org-string-nw-p (plist-get info :description)) + (list "name" "description" + (plist-get info :description)))) + (lambda (_title _author info) + (when (org-string-nw-p (plist-get info :keywords)) + (list "keywords" (plist-get info :keywords)))) + ("name" "generator" "Org Mode")) + "A list of arguments to be passed to `org-html--build-meta-entry'. +Each argument can either be an list which is applied, or a function which +generates such a list with signature (TITLE AUTHOR INFO) where TITLE and AUTHOR +are strings, and INFO a communication plist." + :group 'org-export-html + :package-version '(Org . "9.5") + :type '(repeat + (choice + (list (string :tag "Meta label") + (string :tag "label value") + (string :tag "Content value")) + function))) + (defcustom org-html-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-html-style-default' and @@ -1835,78 +1860,68 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) + "Construct <meta> tag with LABEL=\"IDENTITY\" and content from CONTENT-FORMAT and CONTENT-FORMATTER." + (concat "<meta " + (format "%s=\"%s" label identity) + (when content-format + (concat "\" content=\"" + (replace-regexp-in-string + "\"" """ + (org-html-encode-plain-text + (if content-formatters + (apply #'format content-format content-formatters) + content-format))))) + "\" />\n")) + (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((protect-string - (lambda (str) - (replace-regexp-in-string - "\"" """ (org-html-encode-plain-text str)))) - (title (org-export-data (plist-get info :title) info)) - ;; Set title to an invisible character instead of leaving it - ;; empty, which is invalid. - (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) + (let* ((title (org-html-encode-plain-text (or (car (plist-get info :title)) "Org Export"))) + ;; Set title to an invisible character instead of leaving it + ;; empty, which is invalid. + (title (if (org-string-nw-p title) title "‎")) + (author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) ;; Return raw Org syntax. - (and auth (org-element-interpret-data auth))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords)) - (charset (or (and org-html-coding-system - (fboundp 'coding-system-get) - (coding-system-get org-html-coding-system - 'mime-charset)) - "iso-8859-1"))) + (and auth (org-element-interpret-data auth))))) + (charset (or (and org-html-coding-system + (fboundp 'coding-system-get) + (symbol-name + (coding-system-get org-html-coding-system + 'mime-charset))) + "iso-8859-1"))) (concat (when (plist-get info :time-stamp-file) (format-time-string (concat "<!-- " (plist-get info :html-metadata-timestamp-format) " -->\n"))) - (format - (if (org-html-html5-p info) - (org-html-close-tag "meta" "charset=\"%s\"" info) - (org-html-close-tag - "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" - info)) - charset) "\n" + + (if (org-html-html5-p info) + (org-html--build-meta-entry "charset" charset) + (org-html--build-meta-entry "http-equiv" "Content-Type" + (concat "text/html;charset=" charset))) + (let ((viewport-options (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) (plist-get info :html-viewport)))) - (and viewport-options - (concat - (org-html-close-tag - "meta" - (format "name=\"viewport\" content=\"%s\"" - (mapconcat - (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) - viewport-options ", ")) - info) - "\n"))) + (if viewport-options + (org-html--build-meta-entry "name" "viewport" + (mapconcat + (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) + viewport-options ", ")))) + (format "<title>%s</title>\n" title) - (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info) - "\n" - (and (org-string-nw-p author) - (concat - (org-html-close-tag "meta" - (format "name=\"author\" content=\"%s\"" - (funcall protect-string author)) - info) - "\n")) - (and (org-string-nw-p description) - (concat - (org-html-close-tag "meta" - (format "name=\"description\" content=\"%s\"\n" - (funcall protect-string description)) - info) - "\n")) - (and (org-string-nw-p keywords) - (concat - (org-html-close-tag "meta" - (format "name=\"keywords\" content=\"%s\"" - (funcall protect-string keywords)) - info) - "\n"))))) + + (apply #'concat + (mapcar + (lambda (form) + (when (functionp form) + (setq form (funcall form title author info))) + (when form + (apply #'org-html--build-meta-entry form))) + org-html-meta-tags))))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-13 16:12 ` TEC @ 2020-12-14 6:04 ` Bastien 2020-12-14 6:34 ` TEC 2020-12-14 9:49 ` Jens Lechtenboerger 0 siblings, 2 replies; 43+ messages in thread From: Bastien @ 2020-12-14 6:04 UTC (permalink / raw) To: TEC; +Cc: Jens Lechtenboerger, org-mode-email Hi Timothy, TEC <tecosaur@gmail.com> writes: > Thanks for testing this :) I haven't forgotten about this. Let's wait for Jens feedback on this patch, since he took care of testing it so far. In a nutshell, can you restate what problem is this patch fixing? Is a new option really necessary here? Are there backward compatibility considerations we should take care of? > From 1289e381aff7562df96945aa58838ad966aa9211 Mon Sep 17 00:00:00 2001 > From: TEC <tec@tecosaur.com> > Date: Thu, 17 Sep 2020 21:27:18 +0800 > Subject: [PATCH] lisp/ox-html.el: make html meta func nicer > > * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated > structure extracted to new function `org-html--build-meta-entry'. You need to have a separate changelog entry for any new function or variable. > The opportunity was taken to extract most metadata info to custom > variable `org-html-meta-tags', allowing for easy end-user modification. > --- > lisp/ox-html.el | 131 +++++++++++++++++++++++++++--------------------- > 1 file changed, 73 insertions(+), 58 deletions(-) > > diff --git a/lisp/ox-html.el b/lisp/ox-html.el > index d2f24f5c6..93014e9c7 100644 > --- a/lisp/ox-html.el > +++ b/lisp/ox-html.el > @@ -1425,6 +1425,31 @@ not be modified." > > ;;;; Template :: Styles > > +(defcustom org-html-meta-tags > + '((lambda (_title author _info) > + (when (org-string-nw-p author) > + (list "name" "author" author))) > + (lambda (_title _author info) > + (when (org-string-nw-p (plist-get info :description)) > + (list "name" "description" > + (plist-get info :description)))) > + (lambda (_title _author info) > + (when (org-string-nw-p (plist-get info :keywords)) > + (list "keywords" (plist-get info :keywords)))) > + ("name" "generator" "Org Mode")) > + "A list of arguments to be passed to `org-html--build-meta-entry'. > +Each argument can either be an list which is applied, or a function which > +generates such a list with signature (TITLE AUTHOR INFO) where TITLE and AUTHOR > +are strings, and INFO a communication plist." > + :group 'org-export-html > + :package-version '(Org . "9.5") > + :type '(repeat > + (choice > + (list (string :tag "Meta label") > + (string :tag "label value") > + (string :tag "Content value")) > + function))) > + > (defcustom org-html-head-include-default-style t > "Non-nil means include the default style in exported HTML files. > The actual style is defined in `org-html-style-default' and > @@ -1835,78 +1860,68 @@ INFO is a plist used as a communication channel." > \f > ;;; Template > > +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) > + "Construct <meta> tag with LABEL=\"IDENTITY\" and content from CONTENT-FORMAT and CONTENT-FORMATTER." The first line of this defun is too long. You can try M-x checkdoc RET on your elisp files to catch those issues. Thanks, -- Bastien ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-14 6:04 ` Bastien @ 2020-12-14 6:34 ` TEC 2020-12-14 7:20 ` Bastien 2020-12-14 9:49 ` Jens Lechtenboerger 1 sibling, 1 reply; 43+ messages in thread From: TEC @ 2020-12-14 6:34 UTC (permalink / raw) To: Bastien; +Cc: Jens Lechtenboerger, org-mode-email Bastien <bzg@gnu.org> writes: > Let's wait for Jens feedback on this patch, since he took care of > testing it so far. Assuming Jens responds as he usually has (relatively promptly), this sounds good to me :) > In a nutshell, can you restate what problem is this patch fixing? There are two things I intend to achieve with this patch: 1. DRY* out the existing code. The existing code is quite repetitive in structure, and easily lends itself to being extracted to a function. This is easier to read, and work with IMO. 2. Make use of the DRYer code in (1) to provide a make the meta building function more versatile, and then add in the ability for user customisation at low-cost (again, thanks to (1)). *DRY is an acronym for "Don't Repeat Yourself", in case there's a french equivalent you're more familiar with. > Is a new option really necessary here? Necessary? Not really, I mean the export /works/ without it. I'd argue that it's desirable though, as it provides an easy way for a user (such as myself) to add useful meta tags not included by default. For example I currently make use of this to add information that parsed by a large number of services/apps to create rich embeds for exported Org files I link to (see https://tecosaur.github.io/emacs-config/config.html#extra-header-content,code--2 ). Furthermore, I consider it to be very low cost, since it's basically just taking advantage of the restructuring already performed for code QOL reasons. I expect most users not to have any reason to touch this, but for some to find it handy. > Are there backward compatibility considerations we should take care of? None AFAIK. Barring this errors that Jens raised, and now have hopefully been addressed, this should function /exactly/ as the current implementation does, with a minor (beneficial) caveat, mentioned below. Just with nicer-to-work-with code and a bit more versatility (IMO, of course). These are the two changes to be mentioned: 1. The (or {title} "Org Export") bit I added. I believe the current behaviour when no #+title is given is to have a blank one (""). I think "Org Export" is preferable, as it's more informative than ... nothing. 2. Using org-html-encode-plain-text for formatting the content of the meta tags. From Jens, I take it that the current org-export-data can cause nested HTML tags, which are invalid in this context. Plain text should be safer. >> +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) >> + "Construct <meta> tag with LABEL=\"IDENTITY\" and content from CONTENT-FORMAT and CONTENT-FORMATTER." > > The first line of this defun is too long. You can try M-x checkdoc > RET on your elisp files to catch those issues. > > Thanks, I see, I'm guessing I'll just need to add a line break. I hope that clarifies things! Timothy ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-14 6:34 ` TEC @ 2020-12-14 7:20 ` Bastien 2020-12-14 7:27 ` TEC 0 siblings, 1 reply; 43+ messages in thread From: Bastien @ 2020-12-14 7:20 UTC (permalink / raw) To: TEC; +Cc: Jens Lechtenboerger, org-mode-email Hi Timothy, TEC <tecosaur@gmail.com> writes: >> In a nutshell, can you restate what problem is this patch fixing? > > There are two things I intend to achieve with this patch: > 1. DRY* out the existing code. The existing code is quite repetitive in > structure, and easily lends itself to being extracted to a function. > This is easier to read, and work with IMO. > 2. Make use of the DRYer code in (1) to provide a make the meta building > function more versatile, and then add in the ability for user > customisation at low-cost (again, thanks to (1)). Can we approach this with two patches, one with the refactoring and one with the added functionality? > Necessary? Not really, I mean the export /works/ without it. I'd argue > that it's desirable though, as it provides an easy way for a user (such > as myself) to add useful meta tags not included by default. This sounds useful. >> Are there backward compatibility considerations we should take care of? > > None AFAIK. Barring this errors that Jens raised, and now have hopefully > been addressed, this should function /exactly/ as the current > implementation does, with a minor (beneficial) caveat, mentioned below. > Just with nicer-to-work-with code and a bit more versatility (IMO, of > course). > > These are the two changes to be mentioned: > 1. The (or {title} "Org Export") bit I added. > I believe the current behaviour when no #+title is given is to have a > blank one (""). I think "Org Export" is preferable, as it's more > informative than ... nothing. I think "Org Export" as the default is counter-intuitive, let's stick to the empty string. (Also, this kind of "small" changes should be made with consideration of all exporters.) > 2. Using org-html-encode-plain-text for formatting the content of the > meta tags. From Jens, I take it that the current org-export-data can > cause nested HTML tags, which are invalid in this context. Plain text > should be safer. Yes, this is better. >>> +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) >>> + "Construct <meta> tag with LABEL=\"IDENTITY\" and content from CONTENT-FORMAT and CONTENT-FORMATTER." >> >> The first line of this defun is too long. You can try M-x checkdoc >> RET on your elisp files to catch those issues. >> >> Thanks, > > I see, I'm guessing I'll just need to add a line break. Nope, the first line of a docstring should be a sentence. You'll have to reformulate the beginning of the docstring... Thanks! -- Bastien ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-14 7:20 ` Bastien @ 2020-12-14 7:27 ` TEC 2020-12-14 8:11 ` Bastien 0 siblings, 1 reply; 43+ messages in thread From: TEC @ 2020-12-14 7:27 UTC (permalink / raw) To: Bastien; +Cc: Jens Lechtenboerger, org-mode-email Bastien <bzg@gnu.org> writes: > Can we approach this with two patches, one with the refactoring and > one with the added functionality? Sure :) I'll take care of this when I get home in a few hours. > This sounds useful. Glad to hear! > I think "Org Export" as the default is counter-intuitive, let's stick > to the empty string. (Also, this kind of "small" changes should be > made with consideration of all exporters.) In case of confusion, this isn't replacing the #+title in the document, just the <title>...</title> which is used as the tab content. I just find blank tabs to be quite unhelpful, particularly when nestled among others. I'm not really aware of anything analogous in other exporters. Maybe the metadata in exported PDFs ... but that doesn't exactly show up in browser tabs :P > Nope, the first line of a docstring should be a sentence. You'll have > to reformulate the beginning of the docstring... I'll take care of this with the patch separation. Thanks for the feedback! Timothy. ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-14 7:27 ` TEC @ 2020-12-14 8:11 ` Bastien 2020-12-14 10:01 ` TEC 0 siblings, 1 reply; 43+ messages in thread From: Bastien @ 2020-12-14 8:11 UTC (permalink / raw) To: TEC; +Cc: Jens Lechtenboerger, org-mode-email TEC <tecosaur@gmail.com> writes: > In case of confusion, this isn't replacing the #+title in the document, > just the <title>...</title> which is used as the tab content. Fine then. > I'll take care of this with the patch separation. TIA! -- Bastien ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-14 8:11 ` Bastien @ 2020-12-14 10:01 ` TEC 0 siblings, 0 replies; 43+ messages in thread From: TEC @ 2020-12-14 10:01 UTC (permalink / raw) To: Bastien; +Cc: Jens Lechtenboerger, org-mode-email [-- Attachment #1: Type: text/plain, Size: 460 bytes --] Bastien <bzg@gnu.org> writes: > TEC <tecosaur@gmail.com> writes: > >> In case of confusion, this isn't replacing the #+title in the document, >> just the <title>...</title> which is used as the tab content. > > Fine then. 😅 as it so happens I've revised my thoughts, and I'm just leaving it blank as it currently is. Anyway, here are the revised patches. Let me know if there's anything else you'd like to see tweaked :) -- Timothy [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-lisp-ox-html.el-make-html-meta-tag-builder-nicer.patch --] [-- Type: text/x-patch, Size: 5882 bytes --] From 92b2ab771a1f90f269f20727903c9f42596d32e6 Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:41:33 +0800 Subject: [PATCH 1/2] lisp/ox-html.el: make html meta tag builder nicer * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated structure extracted to new function `org-html--build-meta-entry'. The keyword value formatting is changed from `org-export-data' to `org-html-encode-plain-text' to avoid potentially nesting HTML tags in meta tags and the <title> element, which would violate W3C. --- lisp/ox-html.el | 112 +++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 58 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index d2f24f5c6..e774b53ac 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1835,78 +1835,74 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) + "Construct <meta> tag of form <meta LABEL=\"IDENTITY\" />, or when CONTENT-FORMAT is present: +<meta LABEL=\"IDENTITY\" content=\"{content}\" /> + +Here {content} is determined by applying any CONTENT-FORMATTERS to the CONTENT-FORMAT and encoding +the result as plain text." + (concat "<meta " + (format "%s=\"%s" label identity) + (when content-format + (concat "\" content=\"" + (replace-regexp-in-string + "\"" """ + (org-html-encode-plain-text + (if content-formatters + (apply #'format content-format content-formatters) + content-format))))) + "\" />\n")) + (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((protect-string - (lambda (str) - (replace-regexp-in-string - "\"" """ (org-html-encode-plain-text str)))) - (title (org-export-data (plist-get info :title) info)) - ;; Set title to an invisible character instead of leaving it - ;; empty, which is invalid. - (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) + (let* ((title (org-html-encode-plain-text (or (car (plist-get info :title)) ""))) + ;; Set title to an invisible character instead of leaving it + ;; empty, which is invalid. + (title (if (org-string-nw-p title) title "‎")) + (author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) ;; Return raw Org syntax. - (and auth (org-element-interpret-data auth))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords)) - (charset (or (and org-html-coding-system - (fboundp 'coding-system-get) - (coding-system-get org-html-coding-system - 'mime-charset)) - "iso-8859-1"))) + (and auth (org-element-interpret-data auth))))) + (charset (or (and org-html-coding-system + (fboundp 'coding-system-get) + (symbol-name + (coding-system-get org-html-coding-system + 'mime-charset))) + "iso-8859-1"))) (concat (when (plist-get info :time-stamp-file) (format-time-string (concat "<!-- " (plist-get info :html-metadata-timestamp-format) " -->\n"))) - (format - (if (org-html-html5-p info) - (org-html-close-tag "meta" "charset=\"%s\"" info) - (org-html-close-tag - "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" - info)) - charset) "\n" + + (if (org-html-html5-p info) + (org-html--build-meta-entry "charset" charset) + (org-html--build-meta-entry "http-equiv" "Content-Type" + (concat "text/html;charset=" charset))) + (let ((viewport-options (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) (plist-get info :html-viewport)))) - (and viewport-options - (concat - (org-html-close-tag - "meta" - (format "name=\"viewport\" content=\"%s\"" - (mapconcat - (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) - viewport-options ", ")) - info) - "\n"))) + (if viewport-options + (org-html--build-meta-entry "name" "viewport" + (mapconcat + (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) + viewport-options ", ")))) + (format "<title>%s</title>\n" title) - (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info) - "\n" - (and (org-string-nw-p author) - (concat - (org-html-close-tag "meta" - (format "name=\"author\" content=\"%s\"" - (funcall protect-string author)) - info) - "\n")) - (and (org-string-nw-p description) - (concat - (org-html-close-tag "meta" - (format "name=\"description\" content=\"%s\"\n" - (funcall protect-string description)) - info) - "\n")) - (and (org-string-nw-p keywords) - (concat - (org-html-close-tag "meta" - (format "name=\"keywords\" content=\"%s\"" - (funcall protect-string keywords)) - info) - "\n"))))) + + (when (org-string-nw-p author) + (org-html--build-meta-entry "name" "author" author)) + + (when (org-string-nw-p (plist-get info :description)) + (org-html--build-meta-entry "name" "description" (plist-get info :description))) + + (when (org-string-nw-p (plist-get info :keywords)) + (org-html--build-meta-entry "keywords" (plist-get info :keywords))) + + (org-html--build-meta-entry "name" "generator" "Org Mode")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #3: 0002-lisp-ox-html.el-make-html-meta-tags-customizable.patch --] [-- Type: text/x-patch, Size: 3019 bytes --] From a2fae2c3c7f38ee8d22a4fedbce25d046c8a818d Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:50:15 +0800 Subject: [PATCH 2/2] lisp/ox-html.el: make html meta tags customizable * lisp/ox-html.el (org-html-meta-tags): Introduce this as a new option which can be modified to set the meta tags added in HTML exports. (org-html--build-meta-info): Make use of `org-html-meta-tags' instead of hardcoded meta tags. This is leveraging the earlier restructuring of `org-html--build-meta-info' into a much DRYer form, such that this modification has a negligible impact on complexity and readability. --- lisp/ox-html.el | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index e774b53ac..35e056557 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1425,6 +1425,31 @@ not be modified." ;;;; Template :: Styles +(defcustom org-html-meta-tags + '((lambda (_title author _info) + (when (org-string-nw-p author) + (list "name" "author" author))) + (lambda (_title _author info) + (when (org-string-nw-p (plist-get info :description)) + (list "name" "description" + (plist-get info :description)))) + (lambda (_title _author info) + (when (org-string-nw-p (plist-get info :keywords)) + (list "keywords" (plist-get info :keywords)))) + ("name" "generator" "Org Mode")) + "A list of arguments to be passed to `org-html--build-meta-entry'. +Each argument can either be an list which is applied, or a function which +generates such a list with signature (TITLE AUTHOR INFO) where TITLE and AUTHOR +are strings, and INFO a communication plist." + :group 'org-export-html + :package-version '(Org . "9.5") + :type '(repeat + (choice + (list (string :tag "Meta label") + (string :tag "label value") + (string :tag "Content value")) + function))) + (defcustom org-html-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-html-style-default' and @@ -1893,16 +1918,14 @@ INFO is a plist used as a communication channel." (format "<title>%s</title>\n" title) - (when (org-string-nw-p author) - (org-html--build-meta-entry "name" "author" author)) - - (when (org-string-nw-p (plist-get info :description)) - (org-html--build-meta-entry "name" "description" (plist-get info :description))) - - (when (org-string-nw-p (plist-get info :keywords)) - (org-html--build-meta-entry "keywords" (plist-get info :keywords))) - - (org-html--build-meta-entry "name" "generator" "Org Mode")))) + (apply #'concat + (mapcar + (lambda (form) + (when (functionp form) + (setq form (funcall form title author info))) + (when form + (apply #'org-html--build-meta-entry form))) + org-html-meta-tags))))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-14 6:04 ` Bastien 2020-12-14 6:34 ` TEC @ 2020-12-14 9:49 ` Jens Lechtenboerger 2020-12-15 11:39 ` TEC 1 sibling, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2020-12-14 9:49 UTC (permalink / raw) To: Bastien; +Cc: org-mode-email, TEC Hi everybody, On 2020-12-14, Bastien wrote: > Hi Timothy, > > TEC <tecosaur@gmail.com> writes: > >> Thanks for testing this :) I haven't forgotten about this. > > Let's wait for Jens feedback on this patch, since he took care of > testing it so far. I exported this: #+begin_src org ,#+TITLE: A title with *bold* index_1^2 and characters &ß<" ,#+AUTHOR: An /emphasized/ "anonymous" author_1^2 with [[https://example.org][hyperlink]] and characters &ß<" ,#+DESCRIPTION: A description_1^2 with /emphasis/ and [[https://example.org][hyperlink]] and characters &ß<" ,#+KEYWORDS: key, wörd, *bold*, sub_script Test #+end_src The title now exports follows, which needs fixing: <title>A title with </title> What about treating the title like the author? (Again, Org mode currently produces invalid HTML as nested sub-elements are produced inside the title element.) The keywords export as follows, where the name attribute is missing: <meta keywords="key, wörd, *bold*, sub_script" /> The current lambda functions in org-html-meta-tags all accept three arguments, where the first one is ignored in all cases. The second one is used in exactly one case. Why not add four calls to org-html--build-meta-entry (for author, description, keywords, generator) in org-html--build-meta-info? Best wishes Jens ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-14 9:49 ` Jens Lechtenboerger @ 2020-12-15 11:39 ` TEC 2020-12-16 4:13 ` Tom Gillespie 2020-12-16 6:55 ` Jens Lechtenboerger 0 siblings, 2 replies; 43+ messages in thread From: TEC @ 2020-12-15 11:39 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 1351 bytes --] Thanks for testing Jens. I think I've managed to resolve the issues you've raised. Jens, Bastien, you can find the latest revision of the patches attached :) Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > [title export being dodgy, how about treating like author?] Yep, ~org-element-interpret-data~ is necessary. I found that wrapping it in ~org-html-plain-text~ seems better again though, as it encodes entities like "---" (org) to "—", and doesn't seem to introduce any nested tags. I've also applied this to the author field as a result. Maybe it should be applied to the rest (in ~org-html--build-meta-info~)? I'm not sure. > The keywords export as follows, where the name attribute is missing: > <meta keywords="key, wörd, *bold*, sub_script" /> Fixed. > The current lambda functions in org-html-meta-tags all accept three > arguments, where the first one is ignored in all cases. The second > one is used in exactly one case. Why not add four calls to > org-html--build-meta-entry (for author, description, keywords, > generator) in org-html--build-meta-info? I had an idea on this, I think the new form is cleaner. Either have a list where each item generates a meta entry, or a function that generates such a list. No more mixing of the two. How does this look? Timothy. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-lisp-ox-html.el-make-html-meta-tag-builder-nicer.patch --] [-- Type: text/x-patch, Size: 5934 bytes --] From 9848af808752bc03404befaab7ab5ebb902aa1d0 Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:41:33 +0800 Subject: [PATCH 1/2] lisp/ox-html.el: make html meta tag builder nicer * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated structure extracted to new function `org-html--build-meta-entry'. The keyword value formatting is changed from `org-export-data' to `org-html-encode-plain-text' to avoid potentially nesting HTML tags in meta tags and the <title> element, which would violate W3C. --- lisp/ox-html.el | 114 ++++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index d2f24f5c6..005703f60 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1835,78 +1835,76 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) + "Construct <meta> tag of form <meta LABEL=\"IDENTITY\" />, or when CONTENT-FORMAT is present: +<meta LABEL=\"IDENTITY\" content=\"{content}\" /> + +Here {content} is determined by applying any CONTENT-FORMATTERS to the CONTENT-FORMAT and encoding +the result as plain text." + (concat "<meta " + (format "%s=\"%s" label identity) + (when content-format + (concat "\" content=\"" + (replace-regexp-in-string + "\"" """ + (org-html-encode-plain-text + (if content-formatters + (apply #'format content-format content-formatters) + content-format))))) + "\" />\n")) + (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((protect-string - (lambda (str) - (replace-regexp-in-string - "\"" """ (org-html-encode-plain-text str)))) - (title (org-export-data (plist-get info :title) info)) - ;; Set title to an invisible character instead of leaving it - ;; empty, which is invalid. - (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) + (let* ((title (org-html-plain-text + (org-element-interpret-data (plist-get info :title)) info)) + ;; Set title to an invisible character instead of leaving it + ;; empty, which is invalid. + (title (if (org-string-nw-p title) title "‎")) + (author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) ;; Return raw Org syntax. - (and auth (org-element-interpret-data auth))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords)) - (charset (or (and org-html-coding-system - (fboundp 'coding-system-get) - (coding-system-get org-html-coding-system - 'mime-charset)) - "iso-8859-1"))) + (and auth (org-html-plain-text + (org-element-interpret-data auth) info))))) + (charset (or (and org-html-coding-system + (fboundp 'coding-system-get) + (symbol-name + (coding-system-get org-html-coding-system + 'mime-charset))) + "iso-8859-1"))) (concat (when (plist-get info :time-stamp-file) (format-time-string (concat "<!-- " (plist-get info :html-metadata-timestamp-format) " -->\n"))) - (format - (if (org-html-html5-p info) - (org-html-close-tag "meta" "charset=\"%s\"" info) - (org-html-close-tag - "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" - info)) - charset) "\n" + + (if (org-html-html5-p info) + (org-html--build-meta-entry "charset" charset) + (org-html--build-meta-entry "http-equiv" "Content-Type" + (concat "text/html;charset=" charset))) + (let ((viewport-options (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) (plist-get info :html-viewport)))) - (and viewport-options - (concat - (org-html-close-tag - "meta" - (format "name=\"viewport\" content=\"%s\"" - (mapconcat - (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) - viewport-options ", ")) - info) - "\n"))) + (if viewport-options + (org-html--build-meta-entry "name" "viewport" + (mapconcat + (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) + viewport-options ", ")))) + (format "<title>%s</title>\n" title) - (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info) - "\n" - (and (org-string-nw-p author) - (concat - (org-html-close-tag "meta" - (format "name=\"author\" content=\"%s\"" - (funcall protect-string author)) - info) - "\n")) - (and (org-string-nw-p description) - (concat - (org-html-close-tag "meta" - (format "name=\"description\" content=\"%s\"\n" - (funcall protect-string description)) - info) - "\n")) - (and (org-string-nw-p keywords) - (concat - (org-html-close-tag "meta" - (format "name=\"keywords\" content=\"%s\"" - (funcall protect-string keywords)) - info) - "\n"))))) + + (when (org-string-nw-p author) + (org-html--build-meta-entry "name" "author" author)) + + (when (org-string-nw-p (plist-get info :description)) + (org-html--build-meta-entry "name" "description" (plist-get info :description))) + + (when (org-string-nw-p (plist-get info :keywords)) + (org-html--build-meta-entry "keywords" (plist-get info :keywords))) + + (org-html--build-meta-entry "name" "generator" "Org Mode")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #3: 0002-lisp-ox-html.el-make-html-meta-tags-customizable.patch --] [-- Type: text/x-patch, Size: 3616 bytes --] From 3fdc205a549fe315b3096afb72a87868ef9c57d5 Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:50:15 +0800 Subject: [PATCH 2/2] lisp/ox-html.el: make html meta tags customizable * lisp/ox-html.el (org-html-meta-tags): Introduce this as a new option which can be modified to set the meta tags added in HTML exports. (org-html--build-meta-info): Make use of `org-html-meta-tags' instead of hardcoded meta tags. This is leveraging the earlier restructuring of `org-html--build-meta-info' into a much DRYer form, such that this modification has a negligible impact on complexity and readability. --- lisp/ox-html.el | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 005703f60..6a74cdca8 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1425,6 +1425,22 @@ not be modified." ;;;; Template :: Styles +(defcustom org-html-meta-tags #'org-html-meta-tags-default + "A list where each item is a list of arguments to be passed +to `org-html--build-meta-entry'. Any nil items are ignored. + +Also accept a function which gives such a list when called with with +signature (TITLE AUTHOR INFO) where TITLE and AUTHOR are strings, +and INFO a communication plist." + :group 'org-export-html + :package-version '(Org . "9.5") + :type '(choice + (repeat + (list (string :tag "Meta label") + (string :tag "label value") + (string :tag "Content value"))) + function)) + (defcustom org-html-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-html-style-default' and @@ -1835,6 +1851,22 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html-meta-tags-default (_title author info) + "Generate a list items, each of which is a list of arguments that can +be passed to `org-html--build-meta-entry', to generate meta tags to be +included in the HTML head. + +The documents's TITLE, AUTHOR, and communication plist INFO may be used." + (list + (when (org-string-nw-p author) + (list "name" "author" author)) + (when (org-string-nw-p (plist-get info :description)) + (list "name" "description" + (plist-get info :description))) + (when (org-string-nw-p (plist-get info :keywords)) + (list "name" "keywords" (plist-get info :keywords))) + '("name" "generator" "Org Mode"))) + (defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) "Construct <meta> tag of form <meta LABEL=\"IDENTITY\" />, or when CONTENT-FORMAT is present: <meta LABEL=\"IDENTITY\" content=\"{content}\" /> @@ -1895,16 +1927,11 @@ INFO is a plist used as a communication channel." (format "<title>%s</title>\n" title) - (when (org-string-nw-p author) - (org-html--build-meta-entry "name" "author" author)) - - (when (org-string-nw-p (plist-get info :description)) - (org-html--build-meta-entry "name" "description" (plist-get info :description))) - - (when (org-string-nw-p (plist-get info :keywords)) - (org-html--build-meta-entry "keywords" (plist-get info :keywords))) - - (org-html--build-meta-entry "name" "generator" "Org Mode")))) + (mapconcat + (lambda (args) (apply #'org-html--build-meta-entry args)) + (delq nil (if (functionp org-html-meta-tags) + (funcall org-html-meta-tags title author info) + org-html-meta-tags)) "")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-15 11:39 ` TEC @ 2020-12-16 4:13 ` Tom Gillespie 2020-12-16 5:04 ` Timothy E Chapman 2020-12-16 6:55 ` Jens Lechtenboerger 1 sibling, 1 reply; 43+ messages in thread From: Tom Gillespie @ 2020-12-16 4:13 UTC (permalink / raw) To: TEC; +Cc: Jens Lechtenboerger, Bastien, org-mode-email A question from the slightly uninformed. Why not just use #+html_head: possibly with a macro to fill in variable values? That is fully extensible and doesn't overload keywords. For title, date, author, etc. those can have clearly defined mappings to the html, but everything else seems to be handled more sanely with #+html_head:. Am I missing something? Best, Tom ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-16 4:13 ` Tom Gillespie @ 2020-12-16 5:04 ` Timothy E Chapman 2020-12-16 6:45 ` Tom Gillespie 0 siblings, 1 reply; 43+ messages in thread From: Timothy E Chapman @ 2020-12-16 5:04 UTC (permalink / raw) To: Tom Gillespie; +Cc: Jens Lechtenboerger, Bastien, org-mode-email Hi Tom, > Why not just use #+html_head: > possibly with a macro to fill in variable values? That is fully > extensible and doesn't overload keywords. For title, date, author, > etc. those can have clearly defined mappings to the html, but > everything else seems to be handled more sanely with #+html_head:. Am > I missing something? I doubt the use case that prompted me to make this an option is the only one that would benefit, but it should give you an example of the potential utility of this. There's some metadata I /always/ want added to my exported documents. Some of it is static (e.g. ("name" "theme-color" "#77aa99")), but I also have opengraph metadata which is based on the title/author/etc. See https://tecosaur.github.io/emacs-config/config.html#extra-header-content,code--2 I can't imagine any non-irritating way to have this occur without making use of this exposed functionality, and I doubt I'm the only one who has something they'd like to do which makes use of this. Thanks to the code cleanup / refactoring in the first commit, this option is pretty trivial to expose, so I thought why not! Does this help clarify the purpose to you? Timothy. p.s.I'd rather not have to copy-paste (evern by template expansion) several lines like this into every file I export :cry: #+HTML_HEAD: {{{meta_maybe_description}}} #+MACRO: meta_maybe_description (eval (let ((description (delq nil (org-element-map (org-element-parse-buffer) 'keyword (lambda (kw) (when (string= "SUBTITLE" (org-element-property :key kw)) (org-element-property :value kw))))))) (if description (format "<meta name=\"description\" content=\"%s\" />" (replace-regexp-in-string "\"" """ (org-html-encode-plain-text description)))) "")) When I could just have this in my config: (when (org-string-nw-p (plist-get info :description)) (list "name" "description" (plist-get info :description)) Timothy E Chapman tecosaur@gmail.com tecosaur.com On Wed, 16 Dec 2020 at 12:13, Tom Gillespie <tgbugs@gmail.com> wrote: > > A question from the slightly uninformed. Why not just use #+html_head: > possibly with a macro to fill in variable values? That is fully > extensible and doesn't overload keywords. For title, date, author, > etc. those can have clearly defined mappings to the html, but > everything else seems to be handled more sanely with #+html_head:. Am > I missing something? Best, > Tom ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-16 5:04 ` Timothy E Chapman @ 2020-12-16 6:45 ` Tom Gillespie 0 siblings, 0 replies; 43+ messages in thread From: Tom Gillespie @ 2020-12-16 6:45 UTC (permalink / raw) To: Timothy E Chapman; +Cc: Jens Lechtenboerger, Bastien, org-mode-email Hi Timothy, I understand now. Having a way to implement this in the config is a good thing as it covers a slightly different set of use cases and workflows than always using a common #+setupfile: line. That way if you are working with files that don't have a #+setupfile: specified you can still add metadata without having to modify the files. This would vastly simplify some of my documentation generation code where I modify the first section of a bunch of org files as I process them rather than modifying the config. Thanks! Tom ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-15 11:39 ` TEC 2020-12-16 4:13 ` Tom Gillespie @ 2020-12-16 6:55 ` Jens Lechtenboerger 2020-12-16 7:22 ` TEC 1 sibling, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2020-12-16 6:55 UTC (permalink / raw) To: TEC; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 1121 bytes --] Hello everyone, On 2020-12-15, TEC wrote: > Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > >> [title export being dodgy, how about treating like author?] > > Yep, ~org-element-interpret-data~ is necessary. I found that wrapping it > in ~org-html-plain-text~ seems better again though, as it encodes > entities like "---" (org) to "—", and doesn't seem to introduce > any nested tags. I've also applied this to the author field as a result. I like this! > Maybe it should be applied to the rest (in ~org-html--build-meta-info~)? > I'm not sure. I’m not sure either. Maybe people expect their typed characters, maybe not. This might call for a new variable. I like the new variant much better. However, I still do not understand why you pass the title into org-html-meta-tags-default just to ignore it. The title is already dealt with elsewhere, isn’t it? Some comments raise complaints by checkdoc (lines too long, no sentence in fist line). (Actually, the file has more problems in that regard.) Many thanks for your continued work! Best wishes Jens [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5290 bytes --] ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-16 6:55 ` Jens Lechtenboerger @ 2020-12-16 7:22 ` TEC 2020-12-16 8:37 ` Jens Lechtenboerger 0 siblings, 1 reply; 43+ messages in thread From: TEC @ 2020-12-16 7:22 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: Bastien, org-mode-email Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > I like this! :) >> Maybe it should be applied to the rest (in ~org-html--build-meta-info~)? >> I'm not sure. > > I’m not sure either. Maybe people expect their typed characters, > maybe not. This might call for a new variable. I'm tempted to leave the current behaviour as-is, and then we can introduce a new variable if we want later :) > I like the new variant much better. However, I still do not > understand why you pass the title into org-html-meta-tags-default > just to ignore it. The title is already dealt with elsewhere, isn’t > it? For people who want to customise this to add metadata, the page title is something they're probably interested in. If so, I think it's work giving the title processed by org-html--build-meta-info as it's not so simple as (plist-get info :title). Worst case, the argument just sits there and is ignored :P > Some comments raise complaints by checkdoc (lines too long, no > sentence in fist line). (Actually, the file has more problems in > that regard.) Ooops, I thought I took care of that. Looks like I'll be taking another look... Would be nice my issues weren't one of dozens throughout the file, it makes it a bit harder to notice errors coming from /my/ section. > Many thanks for your continued work! Thanks for your testing and feedback! -- Timothy ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-16 7:22 ` TEC @ 2020-12-16 8:37 ` Jens Lechtenboerger 2020-12-20 5:08 ` TEC 2020-12-20 5:08 ` TEC 0 siblings, 2 replies; 43+ messages in thread From: Jens Lechtenboerger @ 2020-12-16 8:37 UTC (permalink / raw) To: TEC; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 1113 bytes --] On 2020-12-16, TEC wrote: > Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: >>> Maybe it should be applied to the rest (in ~org-html--build-meta-info~)? >>> I'm not sure. >> >> I’m not sure either. Maybe people expect their typed characters, >> maybe not. This might call for a new variable. > > I'm tempted to leave the current behaviour as-is, and then we can > introduce a new variable if we want later :) I agree. >> I like the new variant much better. However, I still do not >> understand why you pass the title into org-html-meta-tags-default >> just to ignore it. The title is already dealt with elsewhere, isn’t >> it? > > For people who want to customise this to add metadata, the page title is > something they're probably interested in. What metadata would you derive from the title? > If so, I think it's work giving the title processed by > org-html--build-meta-info as it's not so simple as > (plist-get info :title). Extracting it from ~info~ might be more flexible as it would not be tied to the current implementation. Best wishes Jens [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5290 bytes --] ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-16 8:37 ` Jens Lechtenboerger @ 2020-12-20 5:08 ` TEC 2020-12-20 5:08 ` TEC 1 sibling, 0 replies; 43+ messages in thread From: TEC @ 2020-12-20 5:08 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: Bastien, org-mode-email Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: >> For people who want to customise this to add metadata, the page title is >> something they're probably interested in. > > What metadata would you derive from the title? In my earlier example, I use the "og:title" property. >> If so, I think it's work giving the title processed by >> org-html--build-meta-info as it's not so simple as >> (plist-get info :title). > > Extracting it from ~info~ might be more flexible as it would not be > tied to the current implementation. My thoughts are just that its seems like title/author may be handy, and we've already worked those out, so why not just pass them along? Could probably reduce to just info, not sure what's best though. Other than this, is there anything else you think might be worth considering before merging? -- Timothy ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-16 8:37 ` Jens Lechtenboerger 2020-12-20 5:08 ` TEC @ 2020-12-20 5:08 ` TEC 2020-12-20 17:59 ` Jens Lechtenboerger 1 sibling, 1 reply; 43+ messages in thread From: TEC @ 2020-12-20 5:08 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: Bastien, org-mode-email Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: >> For people who want to customise this to add metadata, the page title is >> something they're probably interested in. > > What metadata would you derive from the title? In my earlier example, I use the "og:title" property. >> If so, I think it's work giving the title processed by >> org-html--build-meta-info as it's not so simple as >> (plist-get info :title). > > Extracting it from ~info~ might be more flexible as it would not be > tied to the current implementation. My thoughts are just that its seems like title/author may be handy, and we've already worked those out, so why not just pass them along? Could probably reduce to just info, not sure what's best though. Other than this, is there anything else you think might be worth considering before merging? -- Timothy ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-20 5:08 ` TEC @ 2020-12-20 17:59 ` Jens Lechtenboerger 2021-01-02 18:51 ` TEC 0 siblings, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2020-12-20 17:59 UTC (permalink / raw) To: TEC; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 1271 bytes --] On 2020-12-20, TEC wrote: > Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > >>> For people who want to customise this to add metadata, the page title is >>> something they're probably interested in. >> >> What metadata would you derive from the title? > > In my earlier example, I use the "og:title" property. I see. Maybe the doc string could explain such a use case? (I do not understand the benefit of adding that redundantly to an HTML page, but that is not our topic here.) >>> If so, I think it's work giving the title processed by >>> org-html--build-meta-info as it's not so simple as >>> (plist-get info :title). >> >> Extracting it from ~info~ might be more flexible as it would not be >> tied to the current implementation. > > My thoughts are just that its seems like title/author may be handy, and > we've already worked those out, so why not just pass them along? > > Could probably reduce to just info, not sure what's best though. My personal view: If those attributes are present in the default value, they should be used or their use should at least be explained. > Other than this, is there anything else you think might be worth > considering before merging? No suggestions from my side. Thank you for your work! Best wishes Jens [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5290 bytes --] ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2020-12-20 17:59 ` Jens Lechtenboerger @ 2021-01-02 18:51 ` TEC 2021-01-03 13:26 ` Jens Lechtenboerger 0 siblings, 1 reply; 43+ messages in thread From: TEC @ 2021-01-02 18:51 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 244 bytes --] After considering the information passed to a meta info generation function, I'm now in agreement with you that just passing `info' is the most sensible way forward. Attached is a (final?) set of patches, which is as described. -- Timothy. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-lisp-ox-html.el-make-html-meta-tag-builder-nicer.patch --] [-- Type: text/x-patch, Size: 5930 bytes --] From e8c9646ae6c5083417a927bd2b23bb0f837930d2 Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:41:33 +0800 Subject: [PATCH 1/2] lisp/ox-html.el: make html meta tag builder nicer * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated structure extracted to new function `org-html--build-meta-entry'. The keyword value formatting is changed from `org-export-data' to `org-html-encode-plain-text' to avoid potentially nesting HTML tags in meta tags and the <title> element, which would violate W3C. --- lisp/ox-html.el | 114 ++++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 03145e3..f74c6a4 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1835,78 +1835,76 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) + "Construct <meta> tag of form <meta LABEL=\"IDENTITY\" />, or when CONTENT-FORMAT is present: +<meta LABEL=\"IDENTITY\" content=\"{content}\" /> + +Here {content} is determined by applying any CONTENT-FORMATTERS to the CONTENT-FORMAT and encoding +the result as plain text." + (concat "<meta " + (format "%s=\"%s" label identity) + (when content-format + (concat "\" content=\"" + (replace-regexp-in-string + "\"" """ + (org-html-encode-plain-text + (if content-formatters + (apply #'format content-format content-formatters) + content-format))))) + "\" />\n")) + (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((protect-string - (lambda (str) - (replace-regexp-in-string - "\"" """ (org-html-encode-plain-text str)))) - (title (org-export-data (plist-get info :title) info)) - ;; Set title to an invisible character instead of leaving it - ;; empty, which is invalid. - (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) + (let* ((title (org-html-plain-text + (org-element-interpret-data (plist-get info :title)) info)) + ;; Set title to an invisible character instead of leaving it + ;; empty, which is invalid. + (title (if (org-string-nw-p title) title "‎")) + (author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) ;; Return raw Org syntax. - (and auth (org-element-interpret-data auth))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords)) - (charset (or (and org-html-coding-system - (fboundp 'coding-system-get) - (coding-system-get org-html-coding-system - 'mime-charset)) - "iso-8859-1"))) + (and auth (org-html-plain-text + (org-element-interpret-data auth) info))))) + (charset (or (and org-html-coding-system + (fboundp 'coding-system-get) + (symbol-name + (coding-system-get org-html-coding-system + 'mime-charset))) + "iso-8859-1"))) (concat (when (plist-get info :time-stamp-file) (format-time-string (concat "<!-- " (plist-get info :html-metadata-timestamp-format) " -->\n"))) - (format - (if (org-html-html5-p info) - (org-html-close-tag "meta" "charset=\"%s\"" info) - (org-html-close-tag - "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" - info)) - charset) "\n" + + (if (org-html-html5-p info) + (org-html--build-meta-entry "charset" charset) + (org-html--build-meta-entry "http-equiv" "Content-Type" + (concat "text/html;charset=" charset))) + (let ((viewport-options (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) (plist-get info :html-viewport)))) - (and viewport-options - (concat - (org-html-close-tag - "meta" - (format "name=\"viewport\" content=\"%s\"" - (mapconcat - (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) - viewport-options ", ")) - info) - "\n"))) + (if viewport-options + (org-html--build-meta-entry "name" "viewport" + (mapconcat + (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) + viewport-options ", ")))) + (format "<title>%s</title>\n" title) - (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info) - "\n" - (and (org-string-nw-p author) - (concat - (org-html-close-tag "meta" - (format "name=\"author\" content=\"%s\"" - (funcall protect-string author)) - info) - "\n")) - (and (org-string-nw-p description) - (concat - (org-html-close-tag "meta" - (format "name=\"description\" content=\"%s\"\n" - (funcall protect-string description)) - info) - "\n")) - (and (org-string-nw-p keywords) - (concat - (org-html-close-tag "meta" - (format "name=\"keywords\" content=\"%s\"" - (funcall protect-string keywords)) - info) - "\n"))))) + + (when (org-string-nw-p author) + (org-html--build-meta-entry "name" "author" author)) + + (when (org-string-nw-p (plist-get info :description)) + (org-html--build-meta-entry "name" "description" (plist-get info :description))) + + (when (org-string-nw-p (plist-get info :keywords)) + (org-html--build-meta-entry "keywords" (plist-get info :keywords))) + + (org-html--build-meta-entry "name" "generator" "Org Mode")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #3: 0002-lisp-ox-html.el-make-html-meta-tags-customizable.patch --] [-- Type: text/x-patch, Size: 4444 bytes --] From ddb0f73a9e60cdd9fd83a01e8bd0f72716f2bb06 Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:50:15 +0800 Subject: [PATCH 2/2] lisp/ox-html.el: make html meta tags customizable * lisp/ox-html.el (org-html-meta-tags): Introduce this as a new option which can be modified to set the meta tags added in HTML exports. (org-html--build-meta-info): Make use of `org-html-meta-tags' instead of hardcoded meta tags. This is leveraging the earlier restructuring of `org-html--build-meta-info' into a much DRYer form, such that this modification has a negligible impact on complexity and readability. --- lisp/ox-html.el | 57 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index f74c6a4..9446f54 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1425,6 +1425,22 @@ not be modified." ;;;; Template :: Styles +(defcustom org-html-meta-tags #'org-html-meta-tags-default + "A list where each item is a list of arguments to be passed +to `org-html--build-meta-entry'. Any nil items are ignored. + +Also accept a function which gives such a list when called with with +signature (TITLE AUTHOR INFO) where TITLE and AUTHOR are strings, +and INFO a communication plist." + :group 'org-export-html + :package-version '(Org . "9.5") + :type '(choice + (repeat + (list (string :tag "Meta label") + (string :tag "label value") + (string :tag "Content value"))) + function)) + (defcustom org-html-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-html-style-default' and @@ -1835,6 +1851,27 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html-meta-tags-default (info) + "Generate a list items, each of which is a list of arguments that can +be passed to `org-html--build-meta-entry', to generate meta tags to be +included in the HTML head. + +The documents's TITLE, AUTHOR, and communication plist INFO may be used." + (let ((author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) + ;; Return raw Org syntax. + (and auth (org-html-plain-text + (org-element-interpret-data auth) info)))))) + (list + (when (org-string-nw-p author) + (list "name" "author" author)) + (when (org-string-nw-p (plist-get info :description)) + (list "name" "description" + (plist-get info :description))) + (when (org-string-nw-p (plist-get info :keywords)) + (list "name" "keywords" (plist-get info :keywords))) + '("name" "generator" "Org Mode")))) + (defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) "Construct <meta> tag of form <meta LABEL=\"IDENTITY\" />, or when CONTENT-FORMAT is present: <meta LABEL=\"IDENTITY\" content=\"{content}\" /> @@ -1861,11 +1898,6 @@ INFO is a plist used as a communication channel." ;; Set title to an invisible character instead of leaving it ;; empty, which is invalid. (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) - ;; Return raw Org syntax. - (and auth (org-html-plain-text - (org-element-interpret-data auth) info))))) (charset (or (and org-html-coding-system (fboundp 'coding-system-get) (symbol-name @@ -1895,16 +1927,11 @@ INFO is a plist used as a communication channel." (format "<title>%s</title>\n" title) - (when (org-string-nw-p author) - (org-html--build-meta-entry "name" "author" author)) - - (when (org-string-nw-p (plist-get info :description)) - (org-html--build-meta-entry "name" "description" (plist-get info :description))) - - (when (org-string-nw-p (plist-get info :keywords)) - (org-html--build-meta-entry "keywords" (plist-get info :keywords))) - - (org-html--build-meta-entry "name" "generator" "Org Mode")))) + (mapconcat + (lambda (args) (apply #'org-html--build-meta-entry args)) + (delq nil (if (functionp org-html-meta-tags) + (funcall org-html-meta-tags info) + org-html-meta-tags)) "")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2021-01-02 18:51 ` TEC @ 2021-01-03 13:26 ` Jens Lechtenboerger 2021-01-03 14:48 ` TEC 0 siblings, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2021-01-03 13:26 UTC (permalink / raw) To: TEC; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 471 bytes --] On 2021-01-03, TEC wrote: > After considering the information passed to a meta info generation > function, I'm now in agreement with you that just passing `info' is the > most sensible way forward. Hi Timothy, great, thanks :-) > Attached is a (final?) set of patches, which is as described. The doc strings of org-html-meta-tags and org-html-meta-tags-default need to be updated, they still mention author and title. Also, please try checkdoc ;) Best wishes Jens [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5290 bytes --] ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2021-01-03 13:26 ` Jens Lechtenboerger @ 2021-01-03 14:48 ` TEC 2021-01-03 15:41 ` Jens Lechtenboerger 0 siblings, 1 reply; 43+ messages in thread From: TEC @ 2021-01-03 14:48 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 638 bytes --] Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > The doc strings of org-html-meta-tags and org-html-meta-tags-default > need to be updated, they still mention author and title. Ah, yep. Fixed. > Also, please try checkdoc ;) Ahhh yes. Checkdoc, my old ~enemy~ /friend/. I may have shied away from using this because of the litany of issues it raises for the file. How I'd love to see a PR making the Org codebase more consistently follow these guidelines. Then we could potentially do something like integrate CI into the patch acception workflow. Enough of that digression, as before: patches attached :) -- Timothy. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-lisp-ox-html.el-make-html-meta-tag-builder-nicer.patch --] [-- Type: text/x-patch, Size: 5982 bytes --] From de74dcbd51703439faafe96cbc1c60965f064eaa Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:41:33 +0800 Subject: [PATCH 1/2] lisp/ox-html.el: make html meta tag builder nicer * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated structure extracted to new function `org-html--build-meta-entry'. The keyword value formatting is changed from `org-export-data' to `org-html-encode-plain-text' to avoid potentially nesting HTML tags in meta tags and the <title> element, which would violate W3C. --- lisp/ox-html.el | 116 ++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 03145e3..4d277a2 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1835,78 +1835,78 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) + "Build a meta tag using the provided information. + +Construct <meta> tag of form <meta LABEL=\"IDENTITY\" />, or when CONTENT-FORMAT is present: +<meta LABEL=\"IDENTITY\" content=\"{content}\" /> + +Here {content} is determined by applying any CONTENT-FORMATTERS to the CONTENT-FORMAT and encoding +the result as plain text." + (concat "<meta " + (format "%s=\"%s" label identity) + (when content-format + (concat "\" content=\"" + (replace-regexp-in-string + "\"" """ + (org-html-encode-plain-text + (if content-formatters + (apply #'format content-format content-formatters) + content-format))))) + "\" />\n")) + (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((protect-string - (lambda (str) - (replace-regexp-in-string - "\"" """ (org-html-encode-plain-text str)))) - (title (org-export-data (plist-get info :title) info)) - ;; Set title to an invisible character instead of leaving it - ;; empty, which is invalid. - (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) + (let* ((title (org-html-plain-text + (org-element-interpret-data (plist-get info :title)) info)) + ;; Set title to an invisible character instead of leaving it + ;; empty, which is invalid. + (title (if (org-string-nw-p title) title "‎")) + (author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) ;; Return raw Org syntax. - (and auth (org-element-interpret-data auth))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords)) - (charset (or (and org-html-coding-system - (fboundp 'coding-system-get) - (coding-system-get org-html-coding-system - 'mime-charset)) - "iso-8859-1"))) + (and auth (org-html-plain-text + (org-element-interpret-data auth) info))))) + (charset (or (and org-html-coding-system + (fboundp 'coding-system-get) + (symbol-name + (coding-system-get org-html-coding-system + 'mime-charset))) + "iso-8859-1"))) (concat (when (plist-get info :time-stamp-file) (format-time-string (concat "<!-- " (plist-get info :html-metadata-timestamp-format) " -->\n"))) - (format - (if (org-html-html5-p info) - (org-html-close-tag "meta" "charset=\"%s\"" info) - (org-html-close-tag - "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" - info)) - charset) "\n" + + (if (org-html-html5-p info) + (org-html--build-meta-entry "charset" charset) + (org-html--build-meta-entry "http-equiv" "Content-Type" + (concat "text/html;charset=" charset))) + (let ((viewport-options (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) (plist-get info :html-viewport)))) - (and viewport-options - (concat - (org-html-close-tag - "meta" - (format "name=\"viewport\" content=\"%s\"" - (mapconcat - (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) - viewport-options ", ")) - info) - "\n"))) + (if viewport-options + (org-html--build-meta-entry "name" "viewport" + (mapconcat + (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) + viewport-options ", ")))) + (format "<title>%s</title>\n" title) - (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info) - "\n" - (and (org-string-nw-p author) - (concat - (org-html-close-tag "meta" - (format "name=\"author\" content=\"%s\"" - (funcall protect-string author)) - info) - "\n")) - (and (org-string-nw-p description) - (concat - (org-html-close-tag "meta" - (format "name=\"description\" content=\"%s\"\n" - (funcall protect-string description)) - info) - "\n")) - (and (org-string-nw-p keywords) - (concat - (org-html-close-tag "meta" - (format "name=\"keywords\" content=\"%s\"" - (funcall protect-string keywords)) - info) - "\n"))))) + + (when (org-string-nw-p author) + (org-html--build-meta-entry "name" "author" author)) + + (when (org-string-nw-p (plist-get info :description)) + (org-html--build-meta-entry "name" "description" (plist-get info :description))) + + (when (org-string-nw-p (plist-get info :keywords)) + (org-html--build-meta-entry "keywords" (plist-get info :keywords))) + + (org-html--build-meta-entry "name" "generator" "Org Mode")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #3: 0002-lisp-ox-html.el-make-html-meta-tags-customizable.patch --] [-- Type: text/x-patch, Size: 4420 bytes --] From 50e8aacca5c92dcf8b2044cdaf70738e1ba757a5 Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:50:15 +0800 Subject: [PATCH 2/2] lisp/ox-html.el: make html meta tags customizable * lisp/ox-html.el (org-html-meta-tags): Introduce this as a new option which can be modified to set the meta tags added in HTML exports. (org-html--build-meta-info): Make use of `org-html-meta-tags' instead of hardcoded meta tags. This is leveraging the earlier restructuring of `org-html--build-meta-info' into a much DRYer form, such that this modification has a negligible impact on complexity and readability. --- lisp/ox-html.el | 60 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 4d277a2..483ef4f 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1425,6 +1425,23 @@ not be modified." ;;;; Template :: Styles +(defcustom org-html-meta-tags #'org-html-meta-tags-default + "Form that is used to produce meta tags in the HTML head. + +Can be a list where each item is a list of arguments to be passed +to `org-html--build-meta-entry'. Any nil items are ignored. + +Also accept a function which gives such a list when called with with +a single argument (INFO, a communication plist)." + :group 'org-export-html + :package-version '(Org . "9.5") + :type '(choice + (repeat + (list (string :tag "Meta label") + (string :tag "label value") + (string :tag "Content value"))) + function)) + (defcustom org-html-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-html-style-default' and @@ -1835,6 +1852,29 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html-meta-tags-default (info) + "A default value for `org-html-meta-tags'. + +Generate a list items, each of which is a list of arguments that can +be passed to `org-html--build-meta-entry', to generate meta tags to be +included in the HTML head. + +The documents's plist INFO is used to derive relevent information for the tags." + (let ((author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) + ;; Return raw Org syntax. + (and auth (org-html-plain-text + (org-element-interpret-data auth) info)))))) + (list + (when (org-string-nw-p author) + (list "name" "author" author)) + (when (org-string-nw-p (plist-get info :description)) + (list "name" "description" + (plist-get info :description))) + (when (org-string-nw-p (plist-get info :keywords)) + (list "name" "keywords" (plist-get info :keywords))) + '("name" "generator" "Org Mode")))) + (defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) "Build a meta tag using the provided information. @@ -1863,11 +1903,6 @@ INFO is a plist used as a communication channel." ;; Set title to an invisible character instead of leaving it ;; empty, which is invalid. (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) - ;; Return raw Org syntax. - (and auth (org-html-plain-text - (org-element-interpret-data auth) info))))) (charset (or (and org-html-coding-system (fboundp 'coding-system-get) (symbol-name @@ -1897,16 +1932,11 @@ INFO is a plist used as a communication channel." (format "<title>%s</title>\n" title) - (when (org-string-nw-p author) - (org-html--build-meta-entry "name" "author" author)) - - (when (org-string-nw-p (plist-get info :description)) - (org-html--build-meta-entry "name" "description" (plist-get info :description))) - - (when (org-string-nw-p (plist-get info :keywords)) - (org-html--build-meta-entry "keywords" (plist-get info :keywords))) - - (org-html--build-meta-entry "name" "generator" "Org Mode")))) + (mapconcat + (lambda (args) (apply #'org-html--build-meta-entry args)) + (delq nil (if (functionp org-html-meta-tags) + (funcall org-html-meta-tags info) + org-html-meta-tags)) "")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2021-01-03 14:48 ` TEC @ 2021-01-03 15:41 ` Jens Lechtenboerger 2021-01-03 17:17 ` TEC 0 siblings, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2021-01-03 15:41 UTC (permalink / raw) To: TEC; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 654 bytes --] On 2021-01-03, TEC wrote: > Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > >> The doc strings of org-html-meta-tags and org-html-meta-tags-default >> need to be updated, they still mention author and title. > > Ah, yep. Fixed. > >> Also, please try checkdoc ;) > > Ahhh yes. Actually, I use flycheck (https://www.flycheck.org/), which displays warnings right away. org-html--build-meta-entry and org-html--build-meta-info include some long lines. For org-html-meta-tags-default, I suggest this as last line for the doc string (typos, active voice): Use document's plist INFO to derive relevant information for the tags. Best wishes Jens [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5290 bytes --] ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2021-01-03 15:41 ` Jens Lechtenboerger @ 2021-01-03 17:17 ` TEC 2021-01-04 7:11 ` Jens Lechtenboerger 0 siblings, 1 reply; 43+ messages in thread From: TEC @ 2021-01-03 17:17 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 460 bytes --] Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > org-html--build-meta-entry and org-html--build-meta-info include some long lines. Hehe. We've had a lot of back-and-forth haven't we. At least it feels like it's coming to a close now. > For org-html-meta-tags-default, I suggest this as last line for the doc > string (typos, active voice): > Use document's plist INFO to derive relevant information for the tags. Sounds good. Done. -- Timothy [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-lisp-ox-html.el-make-html-meta-tag-builder-nicer.patch --] [-- Type: text/x-patch, Size: 6030 bytes --] From f3f7325ea77cc443387e69f65e899a9537606d80 Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:41:33 +0800 Subject: [PATCH 1/2] lisp/ox-html.el: make html meta tag builder nicer * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated structure extracted to new function `org-html--build-meta-entry'. The keyword value formatting is changed from `org-export-data' to `org-html-encode-plain-text' to avoid potentially nesting HTML tags in meta tags and the <title> element, which would violate W3C. --- lisp/ox-html.el | 118 ++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 03145e3..f18f8a2 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1835,78 +1835,80 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html--build-meta-entry + (label identity &optional content-format &rest content-formatters) + "Build a meta tag using the provided information. + +Construct <meta> tag of form <meta LABEL=\"IDENTITY\" />, or when CONTENT-FORMAT +is present: <meta LABEL=\"IDENTITY\" content=\"{content}\" /> + +Here {content} is determined by applying any CONTENT-FORMATTERS to the +CONTENT-FORMAT and encoding the result as plain text." + (concat "<meta " + (format "%s=\"%s" label identity) + (when content-format + (concat "\" content=\"" + (replace-regexp-in-string + "\"" """ + (org-html-encode-plain-text + (if content-formatters + (apply #'format content-format content-formatters) + content-format))))) + "\" />\n")) + (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((protect-string - (lambda (str) - (replace-regexp-in-string - "\"" """ (org-html-encode-plain-text str)))) - (title (org-export-data (plist-get info :title) info)) - ;; Set title to an invisible character instead of leaving it - ;; empty, which is invalid. - (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) + (let* ((title (org-html-plain-text + (org-element-interpret-data (plist-get info :title)) info)) + ;; Set title to an invisible character instead of leaving it + ;; empty, which is invalid. + (title (if (org-string-nw-p title) title "‎")) + (author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) ;; Return raw Org syntax. - (and auth (org-element-interpret-data auth))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords)) - (charset (or (and org-html-coding-system - (fboundp 'coding-system-get) - (coding-system-get org-html-coding-system - 'mime-charset)) - "iso-8859-1"))) + (and auth (org-html-plain-text + (org-element-interpret-data auth) info))))) + (charset (or (and org-html-coding-system + (fboundp 'coding-system-get) + (symbol-name + (coding-system-get org-html-coding-system + 'mime-charset))) + "iso-8859-1"))) (concat (when (plist-get info :time-stamp-file) (format-time-string (concat "<!-- " (plist-get info :html-metadata-timestamp-format) " -->\n"))) - (format - (if (org-html-html5-p info) - (org-html-close-tag "meta" "charset=\"%s\"" info) - (org-html-close-tag - "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" - info)) - charset) "\n" + + (if (org-html-html5-p info) + (org-html--build-meta-entry "charset" charset) + (org-html--build-meta-entry "http-equiv" "Content-Type" + (concat "text/html;charset=" charset))) + (let ((viewport-options (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) (plist-get info :html-viewport)))) - (and viewport-options - (concat - (org-html-close-tag - "meta" - (format "name=\"viewport\" content=\"%s\"" - (mapconcat - (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) - viewport-options ", ")) - info) - "\n"))) + (if viewport-options + (org-html--build-meta-entry "name" "viewport" + (mapconcat + (lambda (elm) + (format "%s=%s" (car elm) (cadr elm))) + viewport-options ", ")))) + (format "<title>%s</title>\n" title) - (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info) - "\n" - (and (org-string-nw-p author) - (concat - (org-html-close-tag "meta" - (format "name=\"author\" content=\"%s\"" - (funcall protect-string author)) - info) - "\n")) - (and (org-string-nw-p description) - (concat - (org-html-close-tag "meta" - (format "name=\"description\" content=\"%s\"\n" - (funcall protect-string description)) - info) - "\n")) - (and (org-string-nw-p keywords) - (concat - (org-html-close-tag "meta" - (format "name=\"keywords\" content=\"%s\"" - (funcall protect-string keywords)) - info) - "\n"))))) + + (when (org-string-nw-p author) + (org-html--build-meta-entry "name" "author" author)) + + (when (org-string-nw-p (plist-get info :description)) + (org-html--build-meta-entry "name" "description" (plist-get info :description))) + + (when (org-string-nw-p (plist-get info :keywords)) + (org-html--build-meta-entry "keywords" (plist-get info :keywords))) + + (org-html--build-meta-entry "name" "generator" "Org Mode")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #3: 0002-lisp-ox-html.el-make-html-meta-tags-customizable.patch --] [-- Type: text/x-patch, Size: 4414 bytes --] From 7389693850ceb7a20eb38b563e6770ef68fd1196 Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:50:15 +0800 Subject: [PATCH 2/2] lisp/ox-html.el: make html meta tags customizable * lisp/ox-html.el (org-html-meta-tags): Introduce this as a new option which can be modified to set the meta tags added in HTML exports. (org-html--build-meta-info): Make use of `org-html-meta-tags' instead of hardcoded meta tags. This is leveraging the earlier restructuring of `org-html--build-meta-info' into a much DRYer form, such that this modification has a negligible impact on complexity and readability. --- lisp/ox-html.el | 60 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index f18f8a2..ab03046 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1425,6 +1425,23 @@ not be modified." ;;;; Template :: Styles +(defcustom org-html-meta-tags #'org-html-meta-tags-default + "Form that is used to produce meta tags in the HTML head. + +Can be a list where each item is a list of arguments to be passed +to `org-html--build-meta-entry'. Any nil items are ignored. + +Also accept a function which gives such a list when called with with +a single argument (INFO, a communication plist)." + :group 'org-export-html + :package-version '(Org . "9.5") + :type '(choice + (repeat + (list (string :tag "Meta label") + (string :tag "label value") + (string :tag "Content value"))) + function)) + (defcustom org-html-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-html-style-default' and @@ -1835,6 +1852,29 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html-meta-tags-default (info) + "A default value for `org-html-meta-tags'. + +Generate a list items, each of which is a list of arguments that can +be passed to `org-html--build-meta-entry', to generate meta tags to be +included in the HTML head. + +Use document's plist INFO to derive relevant information for the tags." + (let ((author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) + ;; Return raw Org syntax. + (and auth (org-html-plain-text + (org-element-interpret-data auth) info)))))) + (list + (when (org-string-nw-p author) + (list "name" "author" author)) + (when (org-string-nw-p (plist-get info :description)) + (list "name" "description" + (plist-get info :description))) + (when (org-string-nw-p (plist-get info :keywords)) + (list "name" "keywords" (plist-get info :keywords))) + '("name" "generator" "Org Mode")))) + (defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) "Build a meta tag using the provided information. @@ -1864,11 +1904,6 @@ INFO is a plist used as a communication channel." ;; Set title to an invisible character instead of leaving it ;; empty, which is invalid. (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) - ;; Return raw Org syntax. - (and auth (org-html-plain-text - (org-element-interpret-data auth) info))))) (charset (or (and org-html-coding-system (fboundp 'coding-system-get) (symbol-name @@ -1899,16 +1934,11 @@ INFO is a plist used as a communication channel." (format "<title>%s</title>\n" title) - (when (org-string-nw-p author) - (org-html--build-meta-entry "name" "author" author)) - - (when (org-string-nw-p (plist-get info :description)) - (org-html--build-meta-entry "name" "description" (plist-get info :description))) - - (when (org-string-nw-p (plist-get info :keywords)) - (org-html--build-meta-entry "keywords" (plist-get info :keywords))) - - (org-html--build-meta-entry "name" "generator" "Org Mode")))) + (mapconcat + (lambda (args) (apply #'org-html--build-meta-entry args)) + (delq nil (if (functionp org-html-meta-tags) + (funcall org-html-meta-tags info) + org-html-meta-tags)) "")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2021-01-03 17:17 ` TEC @ 2021-01-04 7:11 ` Jens Lechtenboerger 2021-01-10 15:52 ` TEC 0 siblings, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2021-01-04 7:11 UTC (permalink / raw) To: TEC; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 666 bytes --] On 2021-01-04, TEC wrote: > Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > >> org-html--build-meta-entry and org-html--build-meta-info include some long lines. > > Hehe. We've had a lot of back-and-forth haven't we. > At least it feels like it's coming to a close now. On line 1432 I get this suggestion from flycheck: There should be two spaces after a period (emacs-lisp-checkdoc) More importantly, I just realized that for author information, org-html-plain-text is applied twice, leading to "&amp;" when translating "&". (Once inside org-html-meta-tags-default, then in org-html--build-meta-entry.) This should not happen. Best wishes Jens [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5290 bytes --] ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2021-01-04 7:11 ` Jens Lechtenboerger @ 2021-01-10 15:52 ` TEC 2021-01-10 17:02 ` Jens Lechtenboerger 0 siblings, 1 reply; 43+ messages in thread From: TEC @ 2021-01-10 15:52 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 557 bytes --] Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > On line 1432 I get this suggestion from flycheck: > There should be two spaces after a period (emacs-lisp-checkdoc) > > More importantly, I just realized that for author information, > org-html-plain-text is applied twice, leading to "&amp;" when > translating "&". (Once inside org-html-meta-tags-default, then in > org-html--build-meta-entry.) This should not happen. > > Best wishes > Jens Fixed. [exhales] Thanks for consistently getting back to me on this patch Jens :) -- Timothy [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-lisp-ox-html.el-make-html-meta-tag-builder-nicer.patch --] [-- Type: text/x-patch, Size: 6030 bytes --] From 3ab8b4f108c8cfa4b0bf11842907c31846832f1a Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:41:33 +0800 Subject: [PATCH 1/2] lisp/ox-html.el: make html meta tag builder nicer * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated structure extracted to new function `org-html--build-meta-entry'. The keyword value formatting is changed from `org-export-data' to `org-html-encode-plain-text' to avoid potentially nesting HTML tags in meta tags and the <title> element, which would violate W3C. --- lisp/ox-html.el | 118 ++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 03145e3..f18f8a2 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1835,78 +1835,80 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html--build-meta-entry + (label identity &optional content-format &rest content-formatters) + "Build a meta tag using the provided information. + +Construct <meta> tag of form <meta LABEL=\"IDENTITY\" />, or when CONTENT-FORMAT +is present: <meta LABEL=\"IDENTITY\" content=\"{content}\" /> + +Here {content} is determined by applying any CONTENT-FORMATTERS to the +CONTENT-FORMAT and encoding the result as plain text." + (concat "<meta " + (format "%s=\"%s" label identity) + (when content-format + (concat "\" content=\"" + (replace-regexp-in-string + "\"" """ + (org-html-encode-plain-text + (if content-formatters + (apply #'format content-format content-formatters) + content-format))))) + "\" />\n")) + (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((protect-string - (lambda (str) - (replace-regexp-in-string - "\"" """ (org-html-encode-plain-text str)))) - (title (org-export-data (plist-get info :title) info)) - ;; Set title to an invisible character instead of leaving it - ;; empty, which is invalid. - (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) + (let* ((title (org-html-plain-text + (org-element-interpret-data (plist-get info :title)) info)) + ;; Set title to an invisible character instead of leaving it + ;; empty, which is invalid. + (title (if (org-string-nw-p title) title "‎")) + (author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) ;; Return raw Org syntax. - (and auth (org-element-interpret-data auth))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords)) - (charset (or (and org-html-coding-system - (fboundp 'coding-system-get) - (coding-system-get org-html-coding-system - 'mime-charset)) - "iso-8859-1"))) + (and auth (org-html-plain-text + (org-element-interpret-data auth) info))))) + (charset (or (and org-html-coding-system + (fboundp 'coding-system-get) + (symbol-name + (coding-system-get org-html-coding-system + 'mime-charset))) + "iso-8859-1"))) (concat (when (plist-get info :time-stamp-file) (format-time-string (concat "<!-- " (plist-get info :html-metadata-timestamp-format) " -->\n"))) - (format - (if (org-html-html5-p info) - (org-html-close-tag "meta" "charset=\"%s\"" info) - (org-html-close-tag - "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" - info)) - charset) "\n" + + (if (org-html-html5-p info) + (org-html--build-meta-entry "charset" charset) + (org-html--build-meta-entry "http-equiv" "Content-Type" + (concat "text/html;charset=" charset))) + (let ((viewport-options (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) (plist-get info :html-viewport)))) - (and viewport-options - (concat - (org-html-close-tag - "meta" - (format "name=\"viewport\" content=\"%s\"" - (mapconcat - (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) - viewport-options ", ")) - info) - "\n"))) + (if viewport-options + (org-html--build-meta-entry "name" "viewport" + (mapconcat + (lambda (elm) + (format "%s=%s" (car elm) (cadr elm))) + viewport-options ", ")))) + (format "<title>%s</title>\n" title) - (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info) - "\n" - (and (org-string-nw-p author) - (concat - (org-html-close-tag "meta" - (format "name=\"author\" content=\"%s\"" - (funcall protect-string author)) - info) - "\n")) - (and (org-string-nw-p description) - (concat - (org-html-close-tag "meta" - (format "name=\"description\" content=\"%s\"\n" - (funcall protect-string description)) - info) - "\n")) - (and (org-string-nw-p keywords) - (concat - (org-html-close-tag "meta" - (format "name=\"keywords\" content=\"%s\"" - (funcall protect-string keywords)) - info) - "\n"))))) + + (when (org-string-nw-p author) + (org-html--build-meta-entry "name" "author" author)) + + (when (org-string-nw-p (plist-get info :description)) + (org-html--build-meta-entry "name" "description" (plist-get info :description))) + + (when (org-string-nw-p (plist-get info :keywords)) + (org-html--build-meta-entry "keywords" (plist-get info :keywords))) + + (org-html--build-meta-entry "name" "generator" "Org Mode")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #3: 0002-lisp-ox-html.el-make-html-meta-tags-customizable.patch --] [-- Type: text/x-patch, Size: 4414 bytes --] From f3cecaa0db74665a8fe971f3103b2d40874d97c7 Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:50:15 +0800 Subject: [PATCH 2/2] lisp/ox-html.el: make html meta tags customizable * lisp/ox-html.el (org-html-meta-tags): Introduce this as a new option which can be modified to set the meta tags added in HTML exports. (org-html--build-meta-info): Make use of `org-html-meta-tags' instead of hardcoded meta tags. This is leveraging the earlier restructuring of `org-html--build-meta-info' into a much DRYer form, such that this modification has a negligible impact on complexity and readability. --- lisp/ox-html.el | 60 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index f18f8a2..ab03046 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1425,6 +1425,23 @@ not be modified." ;;;; Template :: Styles +(defcustom org-html-meta-tags #'org-html-meta-tags-default + "Form that is used to produce meta tags in the HTML head. + +Can be a list where each item is a list of arguments to be passed +to `org-html--build-meta-entry'. Any nil items are ignored. + +Also accept a function which gives such a list when called with with +a single argument (INFO, a communication plist)." + :group 'org-export-html + :package-version '(Org . "9.5") + :type '(choice + (repeat + (list (string :tag "Meta label") + (string :tag "label value") + (string :tag "Content value"))) + function)) + (defcustom org-html-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-html-style-default' and @@ -1835,6 +1852,29 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html-meta-tags-default (info) + "A default value for `org-html-meta-tags'. + +Generate a list items, each of which is a list of arguments that can +be passed to `org-html--build-meta-entry', to generate meta tags to be +included in the HTML head. + +Use document's plist INFO to derive relevant information for the tags." + (let ((author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) + ;; Return raw Org syntax. + (and auth (org-html-plain-text + (org-element-interpret-data auth) info)))))) + (list + (when (org-string-nw-p author) + (list "name" "author" author)) + (when (org-string-nw-p (plist-get info :description)) + (list "name" "description" + (plist-get info :description))) + (when (org-string-nw-p (plist-get info :keywords)) + (list "name" "keywords" (plist-get info :keywords))) + '("name" "generator" "Org Mode")))) + (defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) "Build a meta tag using the provided information. @@ -1864,11 +1904,6 @@ INFO is a plist used as a communication channel." ;; Set title to an invisible character instead of leaving it ;; empty, which is invalid. (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) - ;; Return raw Org syntax. - (and auth (org-html-plain-text - (org-element-interpret-data auth) info))))) (charset (or (and org-html-coding-system (fboundp 'coding-system-get) (symbol-name @@ -1899,16 +1934,11 @@ INFO is a plist used as a communication channel." (format "<title>%s</title>\n" title) - (when (org-string-nw-p author) - (org-html--build-meta-entry "name" "author" author)) - - (when (org-string-nw-p (plist-get info :description)) - (org-html--build-meta-entry "name" "description" (plist-get info :description))) - - (when (org-string-nw-p (plist-get info :keywords)) - (org-html--build-meta-entry "keywords" (plist-get info :keywords))) - - (org-html--build-meta-entry "name" "generator" "Org Mode")))) + (mapconcat + (lambda (args) (apply #'org-html--build-meta-entry args)) + (delq nil (if (functionp org-html-meta-tags) + (funcall org-html-meta-tags info) + org-html-meta-tags)) "")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2021-01-10 15:52 ` TEC @ 2021-01-10 17:02 ` Jens Lechtenboerger 2021-01-10 20:36 ` TEC 0 siblings, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2021-01-10 17:02 UTC (permalink / raw) To: TEC; +Cc: Bastien, org-mode-email On 2021-01-10, TEC wrote: > Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > >> On line 1432 I get this suggestion from flycheck: >> There should be two spaces after a period (emacs-lisp-checkdoc) >> >> More importantly, I just realized that for author information, >> org-html-plain-text is applied twice, leading to "&amp;" when >> translating "&". (Once inside org-html-meta-tags-default, then in >> org-html--build-meta-entry.) This should not happen. >> >> Best wishes >> Jens > > Fixed. [exhales] Sorry, I still see the flycheck warning and "&amp;" for "&". Please try with: "#+AUTHOR: Foo & Bar" In org-html-meta-tags-default, function org-html-plain-text replaces "&" with "&", and in org-html--build-meta-entry, function org-html-encode-plain-text replaces "&" once more. I suggest to remove org-html-plain-text from org-html-meta-tags-default. Best wishes Jens ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2021-01-10 17:02 ` Jens Lechtenboerger @ 2021-01-10 20:36 ` TEC 2021-01-14 10:36 ` TEC 0 siblings, 1 reply; 43+ messages in thread From: TEC @ 2021-01-10 20:36 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: Bastien, org-mode-email Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > Sorry, I still see the flycheck warning and "&amp;" for "&". Maybe I accidently sent you the old patches? I'll check tomorrow. -- Timothy. ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2021-01-10 20:36 ` TEC @ 2021-01-14 10:36 ` TEC 2021-01-14 15:59 ` Jens Lechtenboerger 2021-01-21 4:05 ` Kyle Meyer 0 siblings, 2 replies; 43+ messages in thread From: TEC @ 2021-01-14 10:36 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 311 bytes --] TEC <tecosaur@gmail.com> writes: >> Sorry, I still see the flycheck warning and "&amp;" for "&". > Maybe I accidently sent you the old patches? I'll check tomorrow. Hah, I check and guess what I see? The changes were unstaged 😂. Sorry about that, here's an actual revision. -- Timothy [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-lisp-ox-html.el-make-html-meta-tag-builder-nicer.patch --] [-- Type: text/x-patch, Size: 6034 bytes --] From 3ab8b4f108c8cfa4b0bf11842907c31846832f1a Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:41:33 +0800 Subject: [PATCH 1/2] lisp/ox-html.el: make html meta tag builder nicer * lisp/ox-html.el (org-html--build-meta-info): Multi-line repeated structure extracted to new function `org-html--build-meta-entry'. The keyword value formatting is changed from `org-export-data' to `org-html-encode-plain-text' to avoid potentially nesting HTML tags in meta tags and the <title> element, which would violate W3C. --- lisp/ox-html.el | 118 ++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 03145e35c..f18f8a2ef 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1835,78 +1835,80 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html--build-meta-entry + (label identity &optional content-format &rest content-formatters) + "Build a meta tag using the provided information. + +Construct <meta> tag of form <meta LABEL=\"IDENTITY\" />, or when CONTENT-FORMAT +is present: <meta LABEL=\"IDENTITY\" content=\"{content}\" /> + +Here {content} is determined by applying any CONTENT-FORMATTERS to the +CONTENT-FORMAT and encoding the result as plain text." + (concat "<meta " + (format "%s=\"%s" label identity) + (when content-format + (concat "\" content=\"" + (replace-regexp-in-string + "\"" """ + (org-html-encode-plain-text + (if content-formatters + (apply #'format content-format content-formatters) + content-format))))) + "\" />\n")) + (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((protect-string - (lambda (str) - (replace-regexp-in-string - "\"" """ (org-html-encode-plain-text str)))) - (title (org-export-data (plist-get info :title) info)) - ;; Set title to an invisible character instead of leaving it - ;; empty, which is invalid. - (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) + (let* ((title (org-html-plain-text + (org-element-interpret-data (plist-get info :title)) info)) + ;; Set title to an invisible character instead of leaving it + ;; empty, which is invalid. + (title (if (org-string-nw-p title) title "‎")) + (author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) ;; Return raw Org syntax. - (and auth (org-element-interpret-data auth))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords)) - (charset (or (and org-html-coding-system - (fboundp 'coding-system-get) - (coding-system-get org-html-coding-system - 'mime-charset)) - "iso-8859-1"))) + (and auth (org-html-plain-text + (org-element-interpret-data auth) info))))) + (charset (or (and org-html-coding-system + (fboundp 'coding-system-get) + (symbol-name + (coding-system-get org-html-coding-system + 'mime-charset))) + "iso-8859-1"))) (concat (when (plist-get info :time-stamp-file) (format-time-string (concat "<!-- " (plist-get info :html-metadata-timestamp-format) " -->\n"))) - (format - (if (org-html-html5-p info) - (org-html-close-tag "meta" "charset=\"%s\"" info) - (org-html-close-tag - "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" - info)) - charset) "\n" + + (if (org-html-html5-p info) + (org-html--build-meta-entry "charset" charset) + (org-html--build-meta-entry "http-equiv" "Content-Type" + (concat "text/html;charset=" charset))) + (let ((viewport-options (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell))) (plist-get info :html-viewport)))) - (and viewport-options - (concat - (org-html-close-tag - "meta" - (format "name=\"viewport\" content=\"%s\"" - (mapconcat - (lambda (elm) (format "%s=%s" (car elm) (cadr elm))) - viewport-options ", ")) - info) - "\n"))) + (if viewport-options + (org-html--build-meta-entry "name" "viewport" + (mapconcat + (lambda (elm) + (format "%s=%s" (car elm) (cadr elm))) + viewport-options ", ")))) + (format "<title>%s</title>\n" title) - (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info) - "\n" - (and (org-string-nw-p author) - (concat - (org-html-close-tag "meta" - (format "name=\"author\" content=\"%s\"" - (funcall protect-string author)) - info) - "\n")) - (and (org-string-nw-p description) - (concat - (org-html-close-tag "meta" - (format "name=\"description\" content=\"%s\"\n" - (funcall protect-string description)) - info) - "\n")) - (and (org-string-nw-p keywords) - (concat - (org-html-close-tag "meta" - (format "name=\"keywords\" content=\"%s\"" - (funcall protect-string keywords)) - info) - "\n"))))) + + (when (org-string-nw-p author) + (org-html--build-meta-entry "name" "author" author)) + + (when (org-string-nw-p (plist-get info :description)) + (org-html--build-meta-entry "name" "description" (plist-get info :description))) + + (when (org-string-nw-p (plist-get info :keywords)) + (org-html--build-meta-entry "keywords" (plist-get info :keywords))) + + (org-html--build-meta-entry "name" "generator" "Org Mode")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #3: 0002-lisp-ox-html.el-make-html-meta-tags-customizable.patch --] [-- Type: text/x-patch, Size: 4357 bytes --] From 6fa5075b04f6996571f8ac5fc19ef8780e9272da Mon Sep 17 00:00:00 2001 From: TEC <tec@tecosaur.com> Date: Mon, 14 Dec 2020 17:50:15 +0800 Subject: [PATCH 2/2] lisp/ox-html.el: make html meta tags customizable * lisp/ox-html.el (org-html-meta-tags): Introduce this as a new option which can be modified to set the meta tags added in HTML exports. (org-html--build-meta-info): Make use of `org-html-meta-tags' instead of hardcoded meta tags. This is leveraging the earlier restructuring of `org-html--build-meta-info' into a much DRYer form, such that this modification has a negligible impact on complexity and readability. --- lisp/ox-html.el | 59 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index f18f8a2ef..bd2ca1753 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1425,6 +1425,23 @@ not be modified." ;;;; Template :: Styles +(defcustom org-html-meta-tags #'org-html-meta-tags-default + "Form that is used to produce meta tags in the HTML head. + +Can be a list where each item is a list of arguments to be passed +to `org-html--build-meta-entry'. Any nil items are ignored. + +Also accept a function which gives such a list when called with with +a single argument (INFO, a communication plist)." + :group 'org-export-html + :package-version '(Org . "9.5") + :type '(choice + (repeat + (list (string :tag "Meta label") + (string :tag "label value") + (string :tag "Content value"))) + function)) + (defcustom org-html-head-include-default-style t "Non-nil means include the default style in exported HTML files. The actual style is defined in `org-html-style-default' and @@ -1835,6 +1852,28 @@ INFO is a plist used as a communication channel." \f ;;; Template +(defun org-html-meta-tags-default (info) + "A default value for `org-html-meta-tags'. + +Generate a list items, each of which is a list of arguments that can +be passed to `org-html--build-meta-entry', to generate meta tags to be +included in the HTML head. + +Use document's plist INFO to derive relevant information for the tags." + (let ((author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) + ;; Return raw Org syntax. + (and auth (org-element-interpret-data auth)))))) + (list + (when (org-string-nw-p author) + (list "name" "author" author)) + (when (org-string-nw-p (plist-get info :description)) + (list "name" "description" + (plist-get info :description))) + (when (org-string-nw-p (plist-get info :keywords)) + (list "name" "keywords" (plist-get info :keywords))) + '("name" "generator" "Org Mode")))) + (defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) "Build a meta tag using the provided information. @@ -1864,11 +1903,6 @@ INFO is a plist used as a communication channel." ;; Set title to an invisible character instead of leaving it ;; empty, which is invalid. (title (if (org-string-nw-p title) title "‎")) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) - ;; Return raw Org syntax. - (and auth (org-html-plain-text - (org-element-interpret-data auth) info))))) (charset (or (and org-html-coding-system (fboundp 'coding-system-get) (symbol-name @@ -1899,16 +1933,11 @@ INFO is a plist used as a communication channel." (format "<title>%s</title>\n" title) - (when (org-string-nw-p author) - (org-html--build-meta-entry "name" "author" author)) - - (when (org-string-nw-p (plist-get info :description)) - (org-html--build-meta-entry "name" "description" (plist-get info :description))) - - (when (org-string-nw-p (plist-get info :keywords)) - (org-html--build-meta-entry "keywords" (plist-get info :keywords))) - - (org-html--build-meta-entry "name" "generator" "Org Mode")))) + (mapconcat + (lambda (args) (apply #'org-html--build-meta-entry args)) + (delq nil (if (functionp org-html-meta-tags) + (funcall org-html-meta-tags info) + org-html-meta-tags)) "")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. -- 2.29.2 ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2021-01-14 10:36 ` TEC @ 2021-01-14 15:59 ` Jens Lechtenboerger 2021-01-14 16:02 ` Ready to merge! " TEC 2021-01-21 4:05 ` Kyle Meyer 1 sibling, 1 reply; 43+ messages in thread From: Jens Lechtenboerger @ 2021-01-14 15:59 UTC (permalink / raw) To: TEC; +Cc: Bastien, org-mode-email [-- Attachment #1: Type: text/plain, Size: 393 bytes --] On 2021-01-14, TEC wrote: > TEC <tecosaur@gmail.com> writes: > >>> Sorry, I still see the flycheck warning and "&amp;" for "&". >> Maybe I accidently sent you the old patches? I'll check tomorrow. > > Hah, I check and guess what I see? The changes were unstaged 😂. > > Sorry about that, here's an actual revision. This looks fine to me. Many thanks! Best wishes Jens [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5290 bytes --] ^ permalink raw reply [flat|nested] 43+ messages in thread
* Ready to merge! Re: [PATCH] Enhance org-html--build-meta-info 2021-01-14 15:59 ` Jens Lechtenboerger @ 2021-01-14 16:02 ` TEC 0 siblings, 0 replies; 43+ messages in thread From: TEC @ 2021-01-14 16:02 UTC (permalink / raw) To: Jens Lechtenboerger; +Cc: Bastien, org-mode-email This thread has dragged on ages, and if no-one else is following this chain I wouldn't blame them in the slightest. To help indicate that this is actually ready (at last) now, I'm just going to add that info the the subject line in the hope it helps Bastien or any others notice that this is actually good to go now :) -- Timothy Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes: > This looks fine to me. Many thanks! > > Best wishes > Jens ^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2021-01-14 10:36 ` TEC 2021-01-14 15:59 ` Jens Lechtenboerger @ 2021-01-21 4:05 ` Kyle Meyer 2021-01-21 5:55 ` TEC 1 sibling, 1 reply; 43+ messages in thread From: Kyle Meyer @ 2021-01-21 4:05 UTC (permalink / raw) To: TEC; +Cc: Jens Lechtenboerger, Bastien, org-mode-email TEC writes: > TEC <tecosaur@gmail.com> writes: > > Sorry about that, here's an actual revision. Thanks, this series is a good improvement as far as I can tell. And thank you Jens for all of the careful reviews. I've applied this (a8df7670c) with two minor changes (shown in the diff at end): s/with with/with/ in a docstring and move an element to its own line to avoid the warning from lisp-mode's lisp--match-hidden-arg. This thread has gone on long enough that I'll avoid requesting changes for convention/style nits, but some things to keep in mind for future patches: * Your changes replace several `and's with `when's as well as a one-armed if. The previous code is following the style/preference of using `and' in cases where the return value is of interest, leaving `when' for side effects. As mentioned in the message below (just the first example I found when searching the list), it's definitely a matter of taste and not a hard rule, but please try to stick with that convention. https://orgmode.org/list/87d23sdtod.fsf@nicolasgoaziou.fr/ * Please avoid adding blank lines within function definitions. * Please follow the project's convention of capitalizing the first word after "<file/area>: " in the commit message subject. Also, it'd be good for this to be accompanied by a NEWS entry. I'd appreciated if that were sent in a separate thread, though. For some reason I haven't debugged, my usual MUA can't load this thread. Thanks again. diff --git a/lisp/ox-html.el b/lisp/ox-html.el index bd2ca1753..11757bb35 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1431,8 +1431,8 @@ (defcustom org-html-meta-tags #'org-html-meta-tags-default Can be a list where each item is a list of arguments to be passed to `org-html--build-meta-entry'. Any nil items are ignored. -Also accept a function which gives such a list when called with with -a single argument (INFO, a communication plist)." +Also accept a function which gives such a list when called with a +single argument (INFO, a communication plist)." :group 'org-export-html :package-version '(Org . "9.5") :type '(choice @@ -1937,7 +1937,8 @@ (defun org-html--build-meta-info (info) (lambda (args) (apply #'org-html--build-meta-entry args)) (delq nil (if (functionp org-html-meta-tags) (funcall org-html-meta-tags info) - org-html-meta-tags)) "")))) + org-html-meta-tags)) + "")))) (defun org-html--build-head (info) "Return information for the <head>..</head> of the HTML output. ^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH] Enhance org-html--build-meta-info 2021-01-21 4:05 ` Kyle Meyer @ 2021-01-21 5:55 ` TEC 0 siblings, 0 replies; 43+ messages in thread From: TEC @ 2021-01-21 5:55 UTC (permalink / raw) To: Kyle Meyer; +Cc: org-mode-email Kyle Meyer <kyle@kyleam.com> writes: > I've applied this (a8df7670c) with two minor changes (shown in the diff > at end): s/with with/with/ in a docstring and move an element to its own > line to avoid the warning from lisp-mode's lisp--match-hidden-arg. Thanks :) > This thread has gone on long enough that I'll avoid requesting changes > for convention/style nits, but some things to keep in mind for future > patches: I'll try to keep these in mind in future. Might there be a Worg page or something listing all of these little things so I don't keep on being told of them a few at a time as I violate them? > Also, it'd be good for this to be accompanied by a NEWS entry. I'd > appreciated if that were sent in a separate thread, though. For some > reason I haven't debugged, my usual MUA can't load this thread. Will do 👍. -- Timothy ^ permalink raw reply [flat|nested] 43+ messages in thread
end of thread, other threads:[~2021-01-21 5:58 UTC | newest] Thread overview: 43+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-09-17 13:50 [PATCH] Enhance org-html--build-meta-info TEC 2020-09-17 14:21 ` TEC 2020-09-17 15:53 ` Jens Lechtenboerger 2020-09-17 16:14 ` TEC 2020-09-18 8:11 ` Jens Lechtenboerger 2020-09-25 17:48 ` TEC 2020-09-27 15:17 ` Jens Lechtenboerger 2020-09-27 17:39 ` TEC 2020-09-27 18:00 ` Jens Lechtenboerger 2020-09-27 18:35 ` TEC 2020-09-28 8:17 ` Jens Lechtenboerger 2020-12-13 16:12 ` TEC 2020-12-14 6:04 ` Bastien 2020-12-14 6:34 ` TEC 2020-12-14 7:20 ` Bastien 2020-12-14 7:27 ` TEC 2020-12-14 8:11 ` Bastien 2020-12-14 10:01 ` TEC 2020-12-14 9:49 ` Jens Lechtenboerger 2020-12-15 11:39 ` TEC 2020-12-16 4:13 ` Tom Gillespie 2020-12-16 5:04 ` Timothy E Chapman 2020-12-16 6:45 ` Tom Gillespie 2020-12-16 6:55 ` Jens Lechtenboerger 2020-12-16 7:22 ` TEC 2020-12-16 8:37 ` Jens Lechtenboerger 2020-12-20 5:08 ` TEC 2020-12-20 5:08 ` TEC 2020-12-20 17:59 ` Jens Lechtenboerger 2021-01-02 18:51 ` TEC 2021-01-03 13:26 ` Jens Lechtenboerger 2021-01-03 14:48 ` TEC 2021-01-03 15:41 ` Jens Lechtenboerger 2021-01-03 17:17 ` TEC 2021-01-04 7:11 ` Jens Lechtenboerger 2021-01-10 15:52 ` TEC 2021-01-10 17:02 ` Jens Lechtenboerger 2021-01-10 20:36 ` TEC 2021-01-14 10:36 ` TEC 2021-01-14 15:59 ` Jens Lechtenboerger 2021-01-14 16:02 ` Ready to merge! " TEC 2021-01-21 4:05 ` Kyle Meyer 2021-01-21 5:55 ` TEC
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.