emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Bernt Hansen <bernt@norang.ca>
Cc: emacs-orgmode@gnu.org
Subject: Re: New exporter problem with #+AUTHOR
Date: Mon, 08 Apr 2013 22:33:45 +0200	[thread overview]
Message-ID: <8738v0vk2e.fsf@gmail.com> (raw)
In-Reply-To: <87zjxa3zal.fsf@norang.ca> (Bernt Hansen's message of "Sun, 07 Apr 2013 15:40:02 -0400")

[-- Attachment #1: Type: text/plain, Size: 649 bytes --]

Hello,

Bernt Hansen <bernt@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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html-Fix-invalid-syntax-in-html-attributes.patch --]
[-- Type: text/x-patch, Size: 3937 bytes --]

From 6d8c48145ffd00ce82f2f19d1fd223a6a1c13a15 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@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
+   "\"" "&quot;"
+   (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


      parent reply	other threads:[~2013-04-08 20:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-07 19:40 New exporter problem with #+AUTHOR Bernt Hansen
2013-04-08  7:01 ` Nicolas Goaziou
2013-04-08 19:27   ` Bastien
2013-04-08 20:33 ` Nicolas Goaziou [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8738v0vk2e.fsf@gmail.com \
    --to=n.goaziou@gmail.com \
    --cc=bernt@norang.ca \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).