Re: XML beginner question (about special characters display)
Re: XML beginner question (about special characters display)
- Subject: Re: XML beginner question (about special characters display)
- From: John Delacour <email@hidden>
- Date: Fri, 11 Oct 2002 10:19:24 +0100
- Mac-eudora-version: 5.3 alpha
At 9:14 pm +0200 10/10/02, JJ wrote:
My goal is display correctly some special characters at browser (eg, html
entity á), but I don't know how to do it!
I've seen that it works properly when it is written as UTF-8 (I can't
reproduce the characters at this list, but I'm talking about ASCII number
135 or á translated to UTF-8). Then, it displays correctly as (ASCII
character 135) in my browser...
Any magical routine to convert a string to UTF-8? I've been playing a little
with TEC osax, but I can't find the propper syntax to make it work right.
Also, can't I convert the special character to hex or different ascii
character to get it rigth displayed?
Some samples with [á or ASCII character 135 or "accented a"] or
[©] or [ñ] would be appreciated...
The perl script below will convert all Mac characters from #128 in
$macstring to the proper html equivalents and open a browser window
showing the result. I have not catered for "=%<>" etc.
You can use perl to convert to UTF8, but you can also use TextEdit.
Type the text in TextEdit, save the file with UTF-8 encoding and then
run
read file "path:to"saved:file"
The syntax for TEC osax is
set macstring to "some macroman text"
set UTF8_ to TECConvertText macstring fromCode "macintosh" toCode "UTF-8"
To use the perl table,
1. Save the perl script below in your user directory as "mac2html.pl".
2. Save some Mac text there in an _ASCII_ text file named "mac.txt"
** Do not use TextEdit to save mac.txt unless you understand it **
3. Run the following AS script:
do shell script "cd; perl mac2html.pl mac.txt"
JD
______________________
#!/usr/bin/perl
$macstring = <ARGV> ;
!$macstring and $macstring = "no files!" ;
table();
$f = "$ENV{HOME}/mac.html" ;
open F, ">$f" or die $! ;
print F "<html>" ;
for ($macstring) {
s~([\x80-\xFF])~$macToUnicode{$1}~g;
print F;
}
`open $f` ;
sub table {
%macToUnicode = (
"\x80"=>'Ä',"\x81"=>'Å',"\x82"=>'Ç',
"\x83"=>'É',"\x84"=>'Ñ',"\x85"=>'Ö',
"\x86"=>'Ü',"\x87"=>'á',"\x88"=>'à',
"\x89"=>'â',"\x8A"=>'ä',"\x8B"=>'ã',
"\x8C"=>'å',"\x8D"=>'ç',"\x8E"=>'é',
"\x8F"=>'è',"\x90"=>'ê',"\x91"=>'ë',
"\x92"=>'í',"\x93"=>'ì',"\x94"=>'î',
"\x95"=>'ï',"\x96"=>'ñ',"\x97"=>'ó',
"\x98"=>'ò',"\x99"=>'ô',"\x9A"=>'ö',
"\x9B"=>'õ',"\x9C"=>'ú',"\x9D"=>'ù',
"\x9E"=>'û',"\x9F"=>'ü',"\xA0"=>'†',
"\xA1"=>'°',"\xA2"=>'¢',"\xA3"=>'£',
"\xA4"=>'§',"\xA5"=>'•',"\xA6"=>'¶',
"\xA7"=>'ß',"\xA8"=>'®',"\xA9"=>'©',
"\xAA"=>'™',"\xAB"=>'´',"\xAC"=>'¨',
"\xAD"=>'≠',"\xAE"=>'Æ',"\xAF"=>'Ø',
"\xB0"=>'∞',"\xB1"=>'±',"\xB2"=>'≤',
"\xB3"=>'≥',"\xB4"=>'¥',"\xB5"=>'µ',
"\xB6"=>'∂',"\xB7"=>'∑',"\xB8"=>'∏',
"\xB9"=>'π',"\xBA"=>'∫',"\xBB"=>'ª',
"\xBC"=>'º',"\xBD"=>'Ω',"\xBE"=>'æ',
"\xBF"=>'ø',"\xC0"=>'¿',"\xC1"=>'¡',
"\xC2"=>'¬',"\xC3"=>'√',"\xC4"=>'ƒ',
"\xC5"=>'≈',"\xC6"=>'∆',"\xC7"=>'«',
"\xC8"=>'»',"\xC9"=>'…',"\xCA"=>' ',
"\xCB"=>'À',"\xCC"=>'Ã',"\xCD"=>'Õ',
"\xCE"=>'Œ',"\xCF"=>'œ',"\xD0"=>'–',
"\xD1"=>'—',"\xD2"=>'“',"\xD3"=>'”',
"\xD4"=>'‘',"\xD5"=>'’',"\xD6"=>'÷',
"\xD7"=>'◊',"\xD8"=>'ÿ',"\xD9"=>'Ÿ',
"\xDA"=>'⁄',"\xDB"=>'€',"\xDC"=>'‹',
"\xDD"=>'›',"\xDE"=>'fi',"\xDF"=>'fl',
"\xE0"=>'‡',"\xE1"=>'·',"\xE2"=>'‚',
"\xE3"=>'„',"\xE4"=>'‰',"\xE5"=>'Â',
"\xE6"=>'Ê',"\xE7"=>'Á',"\xE8"=>'Ë',
"\xE9"=>'È',"\xEA"=>'Í',"\xEB"=>'Î',
"\xEC"=>'Ï',"\xED"=>'Ì',"\xEE"=>'Ó',
"\xEF"=>'Ô',"\xF0"=>'',"\xF1"=>'Ò',
"\xF2"=>'Ú',"\xF3"=>'Û',"\xF4"=>'Ù',
"\xF5"=>'ı',"\xF6"=>'ˆ',"\xF7"=>'˜',
"\xF8"=>'¯',"\xF9"=>'˘',"\xFA"=>'˙',
"\xFB"=>'˚',"\xFC"=>'¸',"\xFD"=>'˝',
"\xFE"=>'˛',"\xFF"=>'ˇ'
);
}
END_
_______________________________________________
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.