From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id EQn4KWXa8V9WLwAA0tVLHw (envelope-from ) for ; Sun, 03 Jan 2021 14:53:25 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 0O1JJWXa8V81dQAAbx9fmQ (envelope-from ) for ; Sun, 03 Jan 2021 14:53:25 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 57519940481 for ; Sun, 3 Jan 2021 14:53:20 +0000 (UTC) Received: from localhost ([::1]:41236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kw4kw-0005wP-Lu for larch@yhetil.org; Sun, 03 Jan 2021 09:53:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kw4k7-0005vy-C4 for emacs-orgmode@gnu.org; Sun, 03 Jan 2021 09:52:27 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:32809) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kw4k5-0004N6-5r; Sun, 03 Jan 2021 09:52:27 -0500 Received: by mail-pl1-x634.google.com with SMTP id b8so13070393plx.0; Sun, 03 Jan 2021 06:52:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:date:in-reply-to :message-id:mime-version; bh=703IL/J3dHfuPoljMcETmGQRMORVXAzy9TTkMAL6D5I=; b=DP50XyfR1J3OjrdCeCjHXviHrkYyTDKvi+lQlydXieJ2c6PfXA/YLSTEZgupQ6ZgbY 1fTREhzfztaTr6WGltM66TG9gEPIvurjFebOtoyLIwN+994QSkXnUwPEgekVEuR+lsdK ErY6ZES1aVNogU6zelPDTjokhLBENd5vD0wE2HgSMp0UUmTXBVGlJ8B1ztQvBFNBYPpD k2i1nZHDooXf0u1fiB5wyFsJq5dZH9D05Yu1Rn1g5PGBD4tmDtLPH61Xcon7b4fz/X93 qyBvlsmFDD1/E0pqVUBsp4XtfV3KFWpAKP/CwedxtAQrFk0qqycb0NCINuEjCbGw0Ejg IbNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject:date :in-reply-to:message-id:mime-version; bh=703IL/J3dHfuPoljMcETmGQRMORVXAzy9TTkMAL6D5I=; b=sKde7uataDkJ42aqOU7ENo6E8T9mqo7GZ0YJwU9D50hDl1UWmP2l3sTE6DlZ5zD+RY wCBMRroSMKm+2ctB/rVSs2W3PKnxHwfo+plswnqI0F/O+M75vmslOGEm9ltohpEeSbka vZqNxGB7Ih74sip+4Hu+fRPLXc3ektVflgEPlgRIZHu6VoAFf+cOEh4pKhoXsxesCimd 9SnWu1+Mb8COT0sv9toJUkMDc1ZgyfO29KRCVXICMW86riWtymgJImqUiHcuFN4tr3gh 6Zd3pN5dhQ2Hj4zKxhnOiQFkF/ZuekC83U/lAlzkq8I9FWi6xhmdvRZCSi2LMn0ooiwz iVhQ== X-Gm-Message-State: AOAM531yvh5ahyOftadYGyjRwiVg+Qcs93wqfk/vWaEU1mdcydRFraMz joHhG8q7gtzFy6KOL+aieXPK32UjeJI= X-Google-Smtp-Source: ABdhPJzif+e60uY0Th74cnvQhuHlJRev4NRj8yINwMnen9i2vsGR95U/tqLoiW69diaVSRnBbCYydg== X-Received: by 2002:a17:90b:3907:: with SMTP id ob7mr25893907pjb.70.1609685543234; Sun, 03 Jan 2021 06:52:23 -0800 (PST) Received: from localhost (180-150-91-8.b4965b.per.nbn.aussiebb.net. [180.150.91.8]) by smtp.gmail.com with ESMTPSA id u189sm52208638pfb.51.2021.01.03.06.52.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Jan 2021 06:52:22 -0800 (PST) References: <87pn6kfr19.fsf@gmail.com> <87v9gcz9ge.fsf@wi.uni-muenster.de> <87lfh8fkj1.fsf@gmail.com> <87zh5n1p3s.fsf@wi.uni-muenster.de> <87tuvl3fyc.fsf@gmail.com> <878scvs0z7.fsf@wi.uni-muenster.de> <87wo0fktjs.fsf@gmail.com> <874knjrtg9.fsf@wi.uni-muenster.de> <87tuvjkqzl.fsf@gmail.com> <87sgb28gd8.fsf@wi.uni-muenster.de> <87blexel9f.fsf@gmail.com> <87im94ordh.fsf@gnu.org> <87tusolntx.fsf@wi.uni-muenster.de> <873607uw3y.fsf@gmail.com> <87im928ck3.fsf@wi.uni-muenster.de> <87k0tidxcf.fsf@gmail.com> <875z5287v1.fsf@wi.uni-muenster.de> <877dpdukkp.fsf@gmail.com> <84wnxccqa3.fsf@wi.uni-muenster.de> <874kjzb25d.fsf@gmail.com> <8735ziup6f.fsf@wi.uni-muenster.de> User-agent: mu4e 1.4.13; emacs 27.1 From: TEC To: Jens Lechtenboerger Subject: Re: [PATCH] Enhance org-html--build-meta-info Date: Sun, 03 Jan 2021 22:48:21 +0800 In-reply-to: <8735ziup6f.fsf@wi.uni-muenster.de> Message-ID: <87czymt6n1.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=tecosaur@gmail.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bastien , org-mode-email Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -1.23 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=gmail.com header.s=20161025 header.b=DP50XyfR; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 57519940481 X-Spam-Score: -1.23 X-Migadu-Scanner: scn0.migadu.com X-TUID: ZJrC3GFS3gbi --=-=-= Content-Type: text/plain Jens Lechtenboerger 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-ox-html.el-make-html-meta-tag-builder-nicer.patch >From de74dcbd51703439faafe96cbc1c60965f064eaa Mon Sep 17 00:00:00 2001 From: TEC 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 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." ;;; 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\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 .. of the HTML output. -- 2.29.2 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-lisp-ox-html.el-make-html-meta-tags-customizable.patch >From 50e8aacca5c92dcf8b2044cdaf70738e1ba757a5 Mon Sep 17 00:00:00 2001 From: TEC 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." ;;; 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 "%s\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 .. of the HTML output. -- 2.29.2 --=-=-=--