• 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: Ready made OSAX or script for a lazy programmer [HTML encoding]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ready made OSAX or script for a lazy programmer [HTML encoding]


  • Subject: Re: Ready made OSAX or script for a lazy programmer [HTML encoding]
  • From: has <email@hidden>
  • Date: Fri, 20 Sep 2002 22:56:33 +0100

Steve Thompson wrote:

>Does anyone have an OSAX or a ready made script that will go through a piece
>of text looking for "special" characters and replacing them with their HTML
>equivalent? For example
>
>[ becomes & # 091 ;

Not special, so doesn't need encoded. Only 4 ASCII characters have to be
escaped: <>&".

You can find a library, htmlConverterBuilder, on my site that can create
custom encoder libraries for converting MacRoman text. Highly customisable;
the only catch is that it's a pretty honking interface, but this shouldn't
be a problem if you're happy with the defaults.

To create an encoder library:

======================================================================

set htmlConverterBuilder to load script (alias "path to
[NO-BREAK]htmlConverterBuilder")

set newEncoder to htmlConverterBuilder's buildEncoderLib({})

set pathToEncoderScript to choose file name with prompt "Save new
[NO-BREAK]encoder library as:" default name "htmlEncoderLib"

store script newEncoder in pathToEncoderScript

======================================================================

If you want to leave the <>&" characters unconverted (to allow users to use
HTML tags) then modify the second line:

set newEncoder to htmlConverterBuilder's
[NO-BREAK]buildEncoderLib({allowHTML:true})


To use the encoder library, first load it into a property in your script.
You can then call its encodeString() handler to convert your string:

======================================================================

prop htmlEncoderLib : load script (alias "path to htmlEncoderLib")

...

set newString to htmlEncoderLib's encodeString(theString)

======================================================================

HTH

has

--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Unicode to plain text
  • Next by Date: Re: String to multiple-item list coercion
  • Previous by thread: Fitting text into a field
  • Next by thread: Sending Control-T to Terminal
  • Index(es):
    • Date
    • Thread