From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id ccgIN1A+1l/QbgAA0tVLHw (envelope-from ) for ; Sun, 13 Dec 2020 16:16:16 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 0IlfMlA+1l/bCAAAB5/wlQ (envelope-from ) for ; Sun, 13 Dec 2020 16:16:16 +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 2F4689402A5 for ; Sun, 13 Dec 2020 16:16:16 +0000 (UTC) Received: from localhost ([::1]:51760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koU2f-0000FB-5a for larch@yhetil.org; Sun, 13 Dec 2020 11:16:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koU0z-0000Do-EJ for emacs-orgmode@gnu.org; Sun, 13 Dec 2020 11:14:29 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:40340) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1koU0v-00048d-Rn for emacs-orgmode@gnu.org; Sun, 13 Dec 2020 11:14:29 -0500 Received: by mail-pl1-x62e.google.com with SMTP id q4so1598704plr.7 for ; Sun, 13 Dec 2020 08:14:25 -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=zdtBfVwCdxijQ8Vn8hgTzQoH/G9hEOCLRSaHWZZQqMs=; b=kJlW1Br/qVVSVqoDS37j6fsy2GfA76765vV5nRc6uOFet0m7h6vFwRy98/CP/su4Cr rCHHsHH5sHNAXBkMM9KW1fLEYT50oQX0GuPItgtvloqHcOy3Gywp0R41vXc4EF9yDk5U TMCg9LPwX/gipBkjDjSoNefFbn/+L22jAZxVNeSMWhB5R3jvwDb93o0tmTeA/csQikHe N7BwzYsCoQ4vk5XfpR2nL7Fo08P8pP5HoRaakA5CiBiw+eVRZ6JAqKj6t+phG7BWnMHU ur1T/eJkAKJp3kPb2aLVYcyIPGMwRwe/Wjx1mP/3L0Tb1vXNsFI2ThyLkSeO+BTjp2EN isnw== 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=zdtBfVwCdxijQ8Vn8hgTzQoH/G9hEOCLRSaHWZZQqMs=; b=OMtJp3lSGGlKU1Fn4A4RiYfv7trbmIuldFQMI2cLruWV0c8ZwUE4XUZWxkQJmTd3lq 7JQeZCv/ci2krP0P9OE+iKKOrpIJBzGkC3ildwgpXXubWXTtuCpSFfX4M5VDJlcHqCUq +rsVj/Fdl2GLFOxtBJXICDz0fNmtpZ1f68M/+p+JtGCBvtF0woxIWQrXE2qxrxmMFQy3 gVVynb/oRXBFfCFw0QsQ7GgL8ML/dZGwQ7DihZ1JWFxyCKYi4ZoPnNvYp0TCU4M4bn0x je2f71nVgymMEtMQDBUpUywjD6T1AWAAoKae5Md5X/fM9NriFnbGslmGZpqiFYEgRE5G TcbA== X-Gm-Message-State: AOAM533G3oB/+yFkouCjJF4QV6956B4Suq+OssUuNpLKek3Z6TAVnVyH MX0uWHB22i/W+CKOl0ECyQlvu4Oj/kU= X-Google-Smtp-Source: ABdhPJw/qiTD5t7ct8XLK4sRxq9vLyoW4SPw0tG+k93mAMKAdHxOJH1BIAZHz8z8NarAxpotdGsp5g== X-Received: by 2002:a17:902:fe02:b029:db:c7fd:3c2c with SMTP id g2-20020a170902fe02b02900dbc7fd3c2cmr19237421plj.31.1607876064349; Sun, 13 Dec 2020 08:14:24 -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 c2sm16742826pfa.59.2020.12.13.08.14.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Dec 2020 08:14:23 -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> User-agent: mu4e 1.4.13; emacs 27.1 From: TEC To: Jens Lechtenboerger Subject: Re: [PATCH] Enhance org-html--build-meta-info Date: Mon, 14 Dec 2020 00:12:28 +0800 In-reply-to: <87sgb28gd8.fsf@wi.uni-muenster.de> Message-ID: <87blexel9f.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=tecosaur@gmail.com; helo=mail-pl1-x62e.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: 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.20 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=gmail.com header.s=20161025 header.b=kJlW1Br/; 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: 2F4689402A5 X-Spam-Score: -1.20 X-Migadu-Scanner: scn1.migadu.com X-TUID: aVjwO6q7axON --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Jens Lechtenboerger writes: > Without the second argument I get an error =E2=80=9CWrong type argument: > stringp,=E2=80=9D when evaluating regular expressions against the cons ce= ll > 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 =E2=80=9Cwrong-type-argument sequencep > utf-8=E2=80=9D for =E2=80=9C(concat "text/html;charset=3D" charset)=E2=80= =9D. Thanks for testing this :) I haven't forgotten about this. Next version! --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-ox-html.el-make-html-meta-func-nicer.patch >From 1289e381aff7562df96945aa58838ad966aa9211 Mon Sep 17 00:00:00 2001 From: TEC 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." ;;; Template +(defun org-html--build-meta-entry (label identity &optional content-format &rest content-formatters) + "Construct tag with LABEL=\"IDENTITY\" and content from CONTENT-FORMAT and CONTENT-FORMATTER." + (concat "\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 "\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 "%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"))))) + + (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 .. of the HTML output. -- 2.29.2 --=-=-=--