all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* HTML and URL escaping functions
@ 2010-06-13 19:26 Aaron Maxwell
  2010-06-13 19:31 ` Deniz Dogan
  2010-06-14 12:38 ` Mark A. Hershberger
  0 siblings, 2 replies; 7+ messages in thread
From: Aaron Maxwell @ 2010-06-13 19:26 UTC (permalink / raw)
  To: emacs-devel

Hi all,

I wrote a few functions for escaping text with HTML entities, and back; and 
for quoting strings for inclusion in HTTP URLs, and back.  The code is here:

http://gist.github.com/436913

Examples (there are equivalents that work on regions too):
; (html-escape-str "<whoah> nelly")
; "&lt;whoah&gt; nelly"
; (html-unescape-str "&lt;whoah&gt; nelly")
; "<whoah> nelly"
; (url-quote-str "ab/c de/f")
; "ab/c%20de/f"
; (url-unquote-str "ab/c%20de/f")
; "ab/c de/f"

It needs some work, but is probably far enough along to be useful.

Do you know if this exists already, in some free software library?  I haven't 
been able to find equivalents anywhere.  I partly wrote this to practice 
elisp, so it's okay if this is reinventing a wheel.  If not, I'd like to 
clean it up so others can use it.

Thanks,
Aaron

-- 
Aaron Maxwell
http://redsymbol.net/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: HTML and URL escaping functions
  2010-06-13 19:26 HTML and URL escaping functions Aaron Maxwell
@ 2010-06-13 19:31 ` Deniz Dogan
  2010-06-15 15:39   ` Aaron Maxwell
  2010-06-14 12:38 ` Mark A. Hershberger
  1 sibling, 1 reply; 7+ messages in thread
From: Deniz Dogan @ 2010-06-13 19:31 UTC (permalink / raw)
  To: Aaron Maxwell; +Cc: emacs-devel

2010/6/13 Aaron Maxwell <amax@redsymbol.net>:
> Hi all,
>
> I wrote a few functions for escaping text with HTML entities, and back; and
> for quoting strings for inclusion in HTTP URLs, and back.  The code is here:
>
> http://gist.github.com/436913
>
> Examples (there are equivalents that work on regions too):
> ; (html-escape-str "<whoah> nelly")
> ; "&lt;whoah&gt; nelly"
> ; (html-unescape-str "&lt;whoah&gt; nelly")
> ; "<whoah> nelly"
> ; (url-quote-str "ab/c de/f")
> ; "ab/c%20de/f"
> ; (url-unquote-str "ab/c%20de/f")
> ; "ab/c de/f"
>
> It needs some work, but is probably far enough along to be useful.
>
> Do you know if this exists already, in some free software library?  I haven't
> been able to find equivalents anywhere.  I partly wrote this to practice
> elisp, so it's okay if this is reinventing a wheel.  If not, I'd like to
> clean it up so others can use it.
>
> Thanks,
> Aaron
>
> --
> Aaron Maxwell
> http://redsymbol.net/
>
>

About the HTML entities: I'm not sure how you implemented it, but e.g.
sgml-mode.el has `sgml-char-names' (along with sgml-name-8bit-mode)
and I'm pretty sure nxhtml has something for it as well. I don't know
about the "URL quoting".

-- 
Deniz Dogan



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: HTML and URL escaping functions
  2010-06-13 19:26 HTML and URL escaping functions Aaron Maxwell
  2010-06-13 19:31 ` Deniz Dogan
@ 2010-06-14 12:38 ` Mark A. Hershberger
  2010-06-15 15:45   ` Aaron Maxwell
  1 sibling, 1 reply; 7+ messages in thread
From: Mark A. Hershberger @ 2010-06-14 12:38 UTC (permalink / raw)
  To: emacs-devel; +Cc: Aaron Maxwell

Aaron Maxwell <amax@redsymbol.net> writes:

> ; (url-quote-str "ab/c de/f")
> ; "ab/c%20de/f"
> ; (url-unquote-str "ab/c%20de/f")
> ; "ab/c de/f"

Check out url-hexify-string in mediawiki-el
<http://launchpad.net/mediawiki-el>  I'm planning on adding the url-*
functions there to Emacs' url.el libraries soon.

For HTML-escaping a string, see xml.el or nxml.el.

Mark.

-- 
http://hexmode.com/

Embrace Ignorance.  Just don't get too attached.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: HTML and URL escaping functions
  2010-06-13 19:31 ` Deniz Dogan
@ 2010-06-15 15:39   ` Aaron Maxwell
  2010-06-15 21:37     ` Juri Linkov
  0 siblings, 1 reply; 7+ messages in thread
From: Aaron Maxwell @ 2010-06-15 15:39 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: emacs-devel

On Sunday 13 June 2010 12:31:17 pm you wrote:
> About the HTML entities: I'm not sure how you implemented it, but e.g.
> sgml-mode.el has `sgml-char-names' (along with sgml-name-8bit-mode)
> and I'm pretty sure nxhtml has something for it as well. I don't know
> about the "URL quoting".

Thanks, wasn't familiar with that (it's actually named sgml-name-char). 

One difference I see is that sgml-name-char works on a single character, while 
html-escape-region finds all non-html-safe characters in a region, and 
escapes them.

I couldn't find anything in nxml, anyone know of a specific command or 
function?

Cheers,
Aaron

-- 
Aaron Maxwell
http://redsymbol.net/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: HTML and URL escaping functions
  2010-06-14 12:38 ` Mark A. Hershberger
@ 2010-06-15 15:45   ` Aaron Maxwell
  2010-06-15 17:37     ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Aaron Maxwell @ 2010-06-15 15:45 UTC (permalink / raw)
  To: emacs-devel

On Monday 14 June 2010 05:38:31 am Mark A. Hershberger wrote:
> Aaron Maxwell <amax@redsymbol.net> writes:
> > ; (url-quote-str "ab/c de/f")
> > ; "ab/c%20de/f"
> > ; (url-unquote-str "ab/c%20de/f")
> > ; "ab/c de/f"
>
> Check out url-hexify-string in mediawiki-el
> <http://launchpad.net/mediawiki-el>  I'm planning on adding the url-*
> functions there to Emacs' url.el libraries soon.

url-hexify-string, right?  Good, I see that.  Succinct implementation too.

Cheers,
Aaron


-- 
Aaron Maxwell
http://redsymbol.net/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: HTML and URL escaping functions
  2010-06-15 15:45   ` Aaron Maxwell
@ 2010-06-15 17:37     ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2010-06-15 17:37 UTC (permalink / raw)
  To: Aaron Maxwell; +Cc: emacs-devel

> url-hexify-string, right?  Good, I see that.  Succinct implementation too.

There's already an url-hexify-string in lisp/url/url-util.el.


        Stefan



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: HTML and URL escaping functions
  2010-06-15 15:39   ` Aaron Maxwell
@ 2010-06-15 21:37     ` Juri Linkov
  0 siblings, 0 replies; 7+ messages in thread
From: Juri Linkov @ 2010-06-15 21:37 UTC (permalink / raw)
  To: Aaron Maxwell; +Cc: emacs-devel, Deniz Dogan

> One difference I see is that sgml-name-char works on a single
> character, while html-escape-region finds all non-html-safe characters
> in a region, and escapes them.

And `sgml-quote'.

> I couldn't find anything in nxml, anyone know of a specific command or
> function?

`rng-escape-string'.

-- 
Juri Linkov
http://www.jurta.org/emacs/



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-06-15 21:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-13 19:26 HTML and URL escaping functions Aaron Maxwell
2010-06-13 19:31 ` Deniz Dogan
2010-06-15 15:39   ` Aaron Maxwell
2010-06-15 21:37     ` Juri Linkov
2010-06-14 12:38 ` Mark A. Hershberger
2010-06-15 15:45   ` Aaron Maxwell
2010-06-15 17:37     ` Stefan Monnier

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.