[Top][All Lists]

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

Re: Converting a string to valid XHTML id?

From: Lennart Borgman
Subject: Re: Converting a string to valid XHTML id?
Date: Thu, 2 Dec 2010 18:47:19 +0100

On Thu, Dec 2, 2010 at 4:50 PM, Lawrence Mitchell <address@hidden> wrote:
> Or use Davis' solution which works in a similar way, and as a
> bonus you can map back to the original id easily.
> Recall his solution:
> (defun org-newhtml-escape-id (str)
>  "Return a valid xhtml id attribute string.
> See URL `http://xhtml.com/en/xhtml/reference/attribute-data-types/#id'."
>  (replace-regexp-in-string
>   "[^-.a-zA-Z0-9]" (lambda (c)
>                      (mapconcat (lambda (d) (format "_%02x" d))
>                                 (string-as-unibyte c) "")) str))
> Notice that the output uses "_" which is a /valid/ char in an
> xhtml id.  However, it is not considered valid in an input
> string.
> So (org-newhtml-escape-id "foo_5fbar") => foo_5f5fbar
> But (org-newhtml-escape-id "foo_bar") => foo_5fbar
> So notice that valid ids /without/ an underscore in them are left
> as is, but ids with an underscore are encoded under this scheme,
> so you can't generate a collision.

Ah, thanks, now I understand. I missed that detail.

reply via email to

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