[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: |
Mon, 29 Nov 2010 19:39:17 +0100 |
On Mon, Nov 29, 2010 at 7:33 PM, Deniz Dogan <address@hidden> wrote:
> 2010/11/29 Lennart Borgman <address@hidden>:
>> On Mon, Nov 29, 2010 at 7:08 PM, Andreas Schwab <address@hidden> wrote:
>>> Lennart Borgman <address@hidden> writes:
>>>
>>>> Do we have a function somewhere for converting a string to a valid XHTML
>>>> id:
>>>
>>> (replace-regexp-in-string "\\`[^A-Za-z]" "X"
>>> (replace-regexp-in-string "[^A-Za-z0-9_:.-]" "_" string))
>>
>> Thanks, that seems good.
>>
>> Could we please add something like that in an appropriate library in Emacs?
>>
>>
>
> 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)))