• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: High performance way to encode HTML entities
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: High performance way to encode HTML entities


  • Subject: Re: High performance way to encode HTML entities
  • From: has <email@hidden>
  • Date: Sat, 21 Oct 2006 22:13:52 +0100

Brennan Young wrote:

Was I dreaming or is there not a built-in scripting addition to encode
text (to) HTML entities?

Built-in, no. As Emmanuel says, you can avoid a lot of the hassle by using UTF8 (if that's an option); then you only have to encode &<> (plus " and/or ' within attribute values). That said, you should still use an osax/awk shell script/whatever to do the substitutions, rather than a TID-based find-and-replace routine, since AS's list-to- unicode-text coercions are buggy and frequently fail silently on non- ASCII characters. e.g. For awk:


awk '{ gsub("&", "&amp;"); gsub("<", "&lt;"); gsub(">", "&gt;"); print }'

Not particularly fast if you're calling it lots of times via 'do shell script', but will do for modest use. If you also need to encode non-ASCII characters you should probably call into a Unicode-aware language like Perl or Python and use that, although the additional overhead will make it slower still.

On the osax/scriptable FBA front, you could use something like TextCommands <http://osaxen.com/files/textcommands1.0.1.html>, which includes a Unicode-aware 'encode HTML' command. Much faster than using 'do shell script', though it's an FBA so not quite as fast as an osax. I don't know of any Unicode-aware osaxen for converting text to HTML entities, however, so if TextCommands isn't fast enough for you then [unless you can find one] you might want to consider using a different language - powerful, efficient text/markup munging is not one of AS's fortes, unfortunately.

HTH

has
--
http://freespace.virgin.net/hamish.sanderson/
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org


_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: High performance way to encode HTML entities
      • From: Tim Mansour <email@hidden>
  • Prev by Date: Re: High performance way to encode HTML entities
  • Next by Date: Re: High performance way to encode HTML entities
  • Previous by thread: Re: High performance way to encode HTML entities
  • Next by thread: Re: High performance way to encode HTML entities
  • Index(es):
    • Date
    • Thread