[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting a string to valid XHTML id?

From: Ralf Mattes
Subject: Re: Converting a string to valid XHTML id?
Date: Tue, 30 Nov 2010 14:50:16 +0000 (UTC)
User-agent: Pan/0.132 (Waxed in Black)

On Mon, 29 Nov 2010 19:39:17 +0100, Lennart Borgman wrote:

> On Mon, Nov 29, 2010 at 7:33 PM, Deniz Dogan <address@hidden>
> wrote:
>> ...
>> What is this for? Just curious.
> I need something like this for exporting org-mode to html (Jambunathan
> and I are rewriting the export routines to cover export to odt too).
> BTW, I came up with this for the moment:
> ;; (org-newhtml-escape-id "fig:5")
> ;; (org-newhtml-escape-id "56")
> (defun org-newhtml-escape-id (id)
>   "Return a valid id string.
> See URL http://www.w3schools.com/tags/att_standard_id.asp";
>   (setq id (replace-regexp-in-string "\\`\\([^A-Za-z]\\)" "ANON-\\1" id
>   nil)) (setq id (replace-regexp-in-string "[^A-Za-z0-9_.-]" "-" id t)))

But this is wrong - it'll possibly generate invalid html. 
Consider the following:

 (org-newhtml-escape-id "this is cool!")

⇒ "this-is-cool-"
 (org-newhtml-escape-id "this is cool?")
⇒ "this-is-cool-"

collapsing two different strings to the same ID, resulting in
invalid html.

 Cheers, Ralf Mattes

reply via email to

[Prev in Thread] Current Thread [Next in Thread]