Hello, Bernt Hansen <be...@norang.ca> writes:
> I have the following line in my org-mode document > > #+AUTHOR: Bernt Hansen (IRC:BerntH on freenode) > > On the old exporter this became > > <meta name="author" content="Bernt Hansen (IRC:BerntH on freenode)"/> > > I just tried exporting this with the new exporter and I get this > > <meta name="author" content="Bernt Hansen (<a href="BerntH">BerntH</a> > on freenode)"/> > > which isn't legal HTML. The quotes on the href="BerntH" close the > previous context= quote. Here is a suggested patch to fix export of data meant to appear as an attribute value. WDYT? Regards, -- Nicolas Goaziou
>From 6d8c48145ffd00ce82f2f19d1fd223a6a1c13a15 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou <n.goaz...@gmail.com> Date: Mon, 8 Apr 2013 22:24:29 +0200 Subject: [PATCH] ox-html: Fix invalid syntax in html attributes * lisp/ox-html.el (org-html--export-attribute): New function. (org-html--build-meta-info): Use new function. --- lisp/ox-html.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 39b0ec9..6b964da 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1265,6 +1265,48 @@ ELEMENT is either a src block or an example block." (or (plist-get attr :height) (org-count-lines code)) code))) +(defun org-html--export-attribute (data info) + "Export DATA as a string suitable for an attribute value. + +DATA is an object, a secondary string or a string. INFO is +a plist used as a communication channel. + +To make output suitable as an attribute value, every markup is +removed and special characters, including quotes, are escaped." + (replace-regexp-in-string + "\"" """ + (org-export-data + (org-export-data-with-translations + data + (append + (mapcar + (lambda (type) + (cond ((eq type 'link) + (cons type + (lambda (link contents info) + (or (org-string-nw-p contents) + (org-element-property :raw-link link))))) + ((eq type 'subscript) + (cons type + (lambda (super contents info) (format "_%s" contents)))) + ((eq type 'superscript) + (cons type + (lambda (super contents info) (format "^%s" contents)))) + ((eq type 'plain-text) (cons type (lambda (text info) text))) + ((memq type '(code verbatim)) + (cons type (lambda (obj contents info) + (org-element-property :value obj)))) + ((memq type org-element-recursive-objects) + (cons type (lambda (obj contents info) contents))) + ((memq type '(export-snippet + footnote-reference latex-fragment line-break + statistics-cookie target)) + (cons type 'ignore)))) + org-element-all-objects) + (org-export-backend-translate-table 'html)) + info) + info))) + ;;;; Bibliography (defun org-html-bibliography () @@ -1423,12 +1465,13 @@ INFO is a plist used as a communication channel." (defun org-html--build-meta-info (info) "Return meta tags for exported document. INFO is a plist used as a communication channel." - (let* ((title (org-export-data (plist-get info :title) info)) - (author (and (plist-get info :with-author) - (let ((auth (plist-get info :author))) - (and auth (org-export-data auth info))))) - (description (plist-get info :description)) - (keywords (plist-get info :keywords))) + (let ((title (org-export-data (plist-get info :title) info)) + (author (and (plist-get info :with-author) + (let ((auth (plist-get info :author))) + (and auth (org-html--export-attribute auth info))))) + (description (org-html--export-attribute + (plist-get info :description) info)) + (keywords (org-html--export-attribute (plist-get info :keywords) info))) (concat (format "<title>%s</title>\n" title) (format @@ -1442,10 +1485,11 @@ INFO is a plist used as a communication channel." (coding-system-get org-html-coding-system 'mime-charset)) "iso-8859-1")) (format "<meta name=\"generator\" content=\"Org-mode\"/>\n") - (and author (format "<meta name=\"author\" content=\"%s\"/>\n" author)) - (and description + (and (org-string-nw-p author) + (format "<meta name=\"author\" content=\"%s\"/>\n" author)) + (and (org-string-nw-p description) (format "<meta name=\"description\" content=\"%s\"/>\n" description)) - (and keywords + (and (org-string-nw-p keywords) (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords))))) (defun org-html--build-head (info) -- 1.8.2.1