Howdy textmaters. (that does sound kinda naughty, doesn't it?)
As I live in Denmark I commonly use the special danish characters æøå, and has tried to make a command to the php htmlentities(9 command on the selected text:
php -r "echo htmlentities('$TM_SELECTED_TEXT', ENT_QUOTES);"
But, alas, as in the terminal æøå gets mangled into \303\246\303\270\303\245 before being entitized. <, &, ", ' and other "normal" special chars gets converted just fine. Is there a workaround for the brutal mangling of the innocent danish characters?
I know there is already a "Convert to entities" command, but it converts every character, not just the special ones. And its a bit of a chore to select every instance of a special character and running a command on it.
Any thoughts? Anyone?
Nis "Have-a-nice-day" Sarup.
-- BTW: I have 5 Gmail invites. Write me at nis.sarup@gmail.com if you are in desperate need of a new and fancy email.
On 23. Oct 2004, at 23:13, Nis Sarup wrote:
But, alas, as in the terminal æøå gets mangled into \303\246\303\270\303\245 before being entitized. <, &, ", ' and other "normal" special chars gets converted just fine. Is there a workaround for the brutal mangling of the innocent danish characters?
TextMate "exports" all text as utf-8. So æ, ø, and å would be "mangled" as such (I've been wanting to put that in the manual! ;) ).
If you only work with latin-1 characters, you could make the command like this (two lines):
TM_LATIN_1=`echo $TM_SELECTED_TEXT | iconv -f utf-8 -t iso-8859-1` php -r "echo htmlentities('$TM_LATIN_1', ENT_QUOTES);"
For me that turns: Æblegrød og rød grød med fløde er godt! Into: Æblegrød og rød grød med fløde er godt!
There's also a php version of iconv, but I do not think it's in the version shipped by Apple.
Kind regards Allan
On 24. Oct 2004, at 0:57, Allan Odgaard wrote:
TextMate "exports" all text as utf-8. So æ, ø, and å would be "mangled" as such (I've been wanting to put that in the manual! ;) ).
If you only work with latin-1 characters, you could make the command like this (two lines):
I just read the PHP manual for htmlentities, and it turns out that the encoding can be given as a third argument, so instead let the command be: php -r "echo htmlentities('$TM_SELECTED_TEXT', ENT_QUOTES, 'UTF-8');"
Then it'll work for all characters.
Kind regards Allan
On 24. Oct 2004, at 16:00, Allan Odgaard wrote:
If you only work with latin-1 characters, you could make the command like this (two lines):
I just read the PHP manual for htmlentities [...]
I knew I couldn't leave this one alone... the command I gave has a problem if the selected text has an apostrophe due to quoting, here's a command that should work:
php -r 'echo htmlentities(stripslashes($_ENV["TM_SELECTED_TEXT"]), ENT_QUOTES, "UTF-8");'
Not sure why you want the ENT_QUOTES option?
Kind regards Allan
On Sun, 24 Oct 2004 16:14:27 +0200, Allan Odgaard allan@macromates.com wrote:
php -r 'echo htmlentities(stripslashes($_ENV["TM_SELECTED_TEXT"]),
ENT_QUOTES, "UTF-8");'
The above code didnt work for me. For some reason my $_ENV array was empty, and the only site on the net with an answer to that, wanted me to register to get it. So I messed around with the other variables and found that $_SERVER also holds the TM_SELECTED_TEXT variable. So this works for me, quotes and all:
php -r 'echo htmlentities(stripslashes($_SERVER["TM_SELECTED_TEXT"]), ENT_QUOTES, "UTF-8");'
Not sure why you want the ENT_QUOTES option?
Well, Im not exactly sure either. I have just always used that option and have never had any problems with it. It might not be strictly necesarry, but whats the hurt?
Oh, and by the way, I just pay for Textmate. It really is worth the money. Even after the first of November.