Re: [PATCH] Enhance org-html--build-meta-info

2021-01-20 Thread TEC


Kyle Meyer  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



Re: [PATCH] Enhance org-html--build-meta-info

2021-01-20 Thread Kyle Meyer
TEC writes:

> TEC  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@nicolasgoaziou.fr/

  * Please avoid adding blank lines within function definitions.

  * Please follow the project's convention of capitalizing the first
word after ": " 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 .. of the HTML output.




Re: [PATCH] Enhance org-html--build-meta-info

2021-01-14 Thread Jens Lechtenboerger
On 2021-01-14, TEC wrote:

> TEC  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


smime.p7s
Description: S/MIME cryptographic signature


Ready to merge! Re: [PATCH] Enhance org-html--build-meta-info

2021-01-14 Thread TEC


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  writes:

> This looks fine to me.  Many thanks!
>
> Best wishes
> Jens




Re: [PATCH] Enhance org-html--build-meta-info

2021-01-14 Thread TEC

TEC  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

>From 3ab8b4f108c8cfa4b0bf11842907c31846832f1a 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 | 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."
 
 ;;; Template
 
+(defun org-html--build-meta-entry
+(label identity  content-format  content-formatters)
+  "Build a meta tag using the provided information.
+
+Construct  tag of form , or when CONTENT-FORMAT
+is present: 
+
+Here {content} is determined by applying any CONTENT-FORMATTERS to the
+CONTENT-FORMAT and encoding the result as plain text."
+  (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-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 "\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"))
- 

Re: [PATCH] Enhance org-html--build-meta-info

2021-01-10 Thread TEC


Jens Lechtenboerger  writes:

> Sorry, I still see the flycheck warning and "amp;" for "&".

Maybe I accidently sent you the old patches? I'll check tomorrow.

--
Timothy.



Re: [PATCH] Enhance org-html--build-meta-info

2021-01-10 Thread Jens Lechtenboerger
On 2021-01-10, TEC wrote:

> Jens Lechtenboerger  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



Re: [PATCH] Enhance org-html--build-meta-info

2021-01-10 Thread TEC

Jens Lechtenboerger  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

>From 3ab8b4f108c8cfa4b0bf11842907c31846832f1a 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 | 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."
 
 ;;; Template
 
+(defun org-html--build-meta-entry
+(label identity  content-format  content-formatters)
+  "Build a meta tag using the provided information.
+
+Construct  tag of form , or when CONTENT-FORMAT
+is present: 
+
+Here {content} is determined by applying any CONTENT-FORMATTERS to the
+CONTENT-FORMAT and encoding the result as plain text."
+  (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-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 "\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))
-			   

Re: [PATCH] Enhance org-html--build-meta-info

2021-01-03 Thread Jens Lechtenboerger
On 2021-01-04, TEC wrote:

> Jens Lechtenboerger  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


smime.p7s
Description: S/MIME cryptographic signature


Re: [PATCH] Enhance org-html--build-meta-info

2021-01-03 Thread TEC

Jens Lechtenboerger  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

>From f3f7325ea77cc443387e69f65e899a9537606d80 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 | 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."
 
 ;;; Template
 
+(defun org-html--build-meta-entry
+(label identity  content-format  content-formatters)
+  "Build a meta tag using the provided information.
+
+Construct  tag of form , or when CONTENT-FORMAT
+is present: 
+
+Here {content} is determined by applying any CONTENT-FORMATTERS to the
+CONTENT-FORMAT and encoding the result as plain text."
+  (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-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 "\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
-	   

Re: [PATCH] Enhance org-html--build-meta-info

2021-01-03 Thread Jens Lechtenboerger
On 2021-01-03, TEC wrote:

> 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.

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


smime.p7s
Description: S/MIME cryptographic signature


Re: [PATCH] Enhance org-html--build-meta-info

2021-01-03 Thread TEC

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.

>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  content-format  content-formatters)
+  "Build a meta tag using the provided information.
+
+Construct  tag of form , or when CONTENT-FORMAT is present:
+
+
+Here {content} is determined by applying any CONTENT-FORMATTERS to the CONTENT-FORMAT and encoding
+the result as plain text."
+  (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-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 "\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\""
-   

Re: [PATCH] Enhance org-html--build-meta-info

2021-01-03 Thread Jens Lechtenboerger
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


smime.p7s
Description: S/MIME cryptographic signature


Re: [PATCH] Enhance org-html--build-meta-info

2021-01-02 Thread TEC

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.

>From e8c9646ae6c5083417a927bd2b23bb0f837930d2 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 | 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."
 
 ;;; Template
 
+(defun org-html--build-meta-entry (label identity  content-format  content-formatters)
+  "Construct  tag of form , or when CONTENT-FORMAT is present:
+
+
+Here {content} is determined by applying any CONTENT-FORMATTERS to the CONTENT-FORMAT and encoding
+the result as plain text."
+  (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-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 "\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\""
-			

Re: [PATCH] Enhance org-html--build-meta-info

2020-12-20 Thread Jens Lechtenboerger
On 2020-12-20, TEC wrote:

> Jens Lechtenboerger  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


smime.p7s
Description: S/MIME cryptographic signature


Re: [PATCH] Enhance org-html--build-meta-info

2020-12-19 Thread TEC


Jens Lechtenboerger  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



Re: [PATCH] Enhance org-html--build-meta-info

2020-12-19 Thread TEC


Jens Lechtenboerger  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



Re: [PATCH] Enhance org-html--build-meta-info

2020-12-16 Thread Jens Lechtenboerger
On 2020-12-16, TEC wrote:

> Jens Lechtenboerger  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


smime.p7s
Description: S/MIME cryptographic signature


Re: [PATCH] Enhance org-html--build-meta-info

2020-12-15 Thread TEC


Jens Lechtenboerger  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



Re: [PATCH] Enhance org-html--build-meta-info

2020-12-15 Thread Jens Lechtenboerger
Hello everyone,

On 2020-12-15, TEC wrote:

> Jens Lechtenboerger  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


smime.p7s
Description: S/MIME cryptographic signature


Re: [PATCH] Enhance org-html--build-meta-info

2020-12-15 Thread Tom Gillespie
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



Re: [PATCH] Enhance org-html--build-meta-info

2020-12-15 Thread Timothy E Chapman
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 "" (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
tecos...@gmail.com
tecosaur.com


On Wed, 16 Dec 2020 at 12:13, Tom Gillespie  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



Re: [PATCH] Enhance org-html--build-meta-info

2020-12-15 Thread Tom Gillespie
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



Re: [PATCH] Enhance org-html--build-meta-info

2020-12-15 Thread TEC

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  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:
> 

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.

>From 9848af808752bc03404befaab7ab5ebb902aa1d0 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 | 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."
 
 ;;; Template
 
+(defun org-html--build-meta-entry (label identity  content-format  content-formatters)
+  "Construct  tag of form , or when CONTENT-FORMAT is present:
+
+
+Here {content} is determined by applying any CONTENT-FORMATTERS to the CONTENT-FORMAT and encoding
+the result as plain text."
+  (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-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 "\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 

Re: [PATCH] Enhance org-html--build-meta-info

2020-12-14 Thread Jens Lechtenboerger
Hi everybody,

On 2020-12-14, Bastien wrote:

> Hi Timothy,
>
> TEC  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:
A title with 

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:


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



Re: [PATCH] Enhance org-html--build-meta-info

2020-12-13 Thread TEC


Bastien  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 ... 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.



Re: [PATCH] Enhance org-html--build-meta-info

2020-12-13 Thread Bastien
Hi Timothy,

TEC  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  content-format 
>>>  content-formatters)
>>> +  "Construct  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



Re: [PATCH] Enhance org-html--build-meta-info

2020-12-13 Thread TEC


Bastien  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  content-format 
>>  content-formatters)
>> +  "Construct  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



Re: [PATCH] Enhance org-html--build-meta-info

2020-12-13 Thread Bastien
Hi Timothy,

TEC  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 
> 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."
>  
>  ;;; Template
>  
> +(defun org-html--build-meta-entry (label identity  content-format 
>  content-formatters)
> +  "Construct  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



Re: [PATCH] Enhance org-html--build-meta-info

2020-12-13 Thread TEC

Jens Lechtenboerger  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!

>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  content-format  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=" 

Re: [PATCH] Enhance org-html--build-meta-info

2020-09-28 Thread Jens Lechtenboerger
On 2020-09-28, TEC wrote:

> Jens Lechtenboerger  writes:
>
>> On 2020-09-28, TEC wrote:
>>
>>> Jens Lechtenboerger  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))
>
> O, 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



Re: [PATCH] Enhance org-html--build-meta-info

2020-09-27 Thread TEC



Jens Lechtenboerger  writes:


On 2020-09-28, TEC wrote:


Jens Lechtenboerger  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))


O, 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.



Re: [PATCH] Enhance org-html--build-meta-info

2020-09-27 Thread Jens Lechtenboerger
On 2020-09-28, TEC wrote:

> Jens Lechtenboerger  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



Re: [PATCH] Enhance org-html--build-meta-info

2020-09-27 Thread TEC



Jens Lechtenboerger  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 
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."


;;; Template

+(defun org-html--build-meta-entry (label identity  
content-format  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))
+  (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 "\n")))
- (format
-  (if (org-html-html5-p info)
- 

Re: [PATCH] Enhance org-html--build-meta-info

2020-09-27 Thread Jens Lechtenboerger
On 2020-09-26, TEC wrote:

> @Maintainers I think this is ready for a review.
>
> Jens Lechtenboerger  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



Re: [PATCH] Enhance org-html--build-meta-info

2020-09-25 Thread TEC


@Maintainers I think this is ready for a review.

Jens Lechtenboerger  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 
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."

 ;;; Template
 
+(defun org-html--build-meta-entry (label identity  content-format 
 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))
+  (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 "\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)
-

Re: [PATCH] Enhance org-html--build-meta-info

2020-09-18 Thread Jens Lechtenboerger
On 2020-09-18, TEC wrote:

> Jens Lechtenboerger  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
A title with bold index12 and characters 
ß"
https://example.org][hyperlink]] and characters ß" />
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



Re: [PATCH] Enhance org-html--build-meta-info

2020-09-17 Thread TEC


Jens Lechtenboerger  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 
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."

 ;;; Template

+(defun org-html--build-meta-entry (label identity  content-format 
 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))
+  (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 

Re: [PATCH] Enhance org-html--build-meta-info

2020-09-17 Thread Jens Lechtenboerger
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


smime.p7s
Description: S/MIME cryptographic signature


Re: [PATCH] Enhance org-html--build-meta-info

2020-09-17 Thread TEC


TEC  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 
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."

 ;;; Template

+(defun org-html--build-meta-entry (label identity  content-format 
 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))
+  (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 "\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"
+