Unicode and HTML for Fields
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 328
- Joined: Mon Dec 05, 2011 5:34 pm
- Contact:
Unicode and HTML for Fields
Hi All,
I have various simple html files translated into asian languages (e.g. Thai) that contain html tags to provide bold, font colours, etc. I would like to be able to load these into a normal Field object on a card. I can get the utf8 text to display fine, but the html tags show (using unicodetext property), or I can show gobbledigook text with bold/colours/etc (using htmltext property).
Is there a way to have the best of both worlds like this? Or am I stuck with messing around with a browser view or something? Has anyone else done anything similar with success?
For further information the html files have extra tags in them that I pre-parse to let the program know things like pictures to use (and where they should appear) and also to tell the program to split the text. These are easy to get via basic text location functions, etc. So I'm not too interested in using RTF formatting (as I don't know how to split that or insert data into the text-stream)
Any ideas would be great.
Cheers,
Dave
I have various simple html files translated into asian languages (e.g. Thai) that contain html tags to provide bold, font colours, etc. I would like to be able to load these into a normal Field object on a card. I can get the utf8 text to display fine, but the html tags show (using unicodetext property), or I can show gobbledigook text with bold/colours/etc (using htmltext property).
Is there a way to have the best of both worlds like this? Or am I stuck with messing around with a browser view or something? Has anyone else done anything similar with success?
For further information the html files have extra tags in them that I pre-parse to let the program know things like pictures to use (and where they should appear) and also to tell the program to split the text. These are easy to get via basic text location functions, etc. So I'm not too interested in using RTF formatting (as I don't know how to split that or insert data into the text-stream)
Any ideas would be great.
Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.
Visit http://electronic-apps.info for released App information.
Re: Unicode and HTML for Fields
Hi Dave,
Not sure but when I use htmlText I get:
input 才出吃
output <p><font face="Heiti SC Light" size="11">才出吃</font></p>
and the reverse works, no gobbelygook.
How does your html look?
Simon
Not sure but when I use htmlText I get:
input 才出吃
output <p><font face="Heiti SC Light" size="11">才出吃</font></p>
and the reverse works, no gobbelygook.
How does your html look?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Livecode Opensource Backer
- Posts: 328
- Joined: Mon Dec 05, 2011 5:34 pm
- Contact:
Re: Unicode and HTML for Fields
Hi.
Sorry for not replying earlier - had a Modem crash!
If I have something like:
<b>才出吃</b>
in my html/text file then I get the same appearing in the field for unicodetext (i.e. - characters are there along with the <b> tags), but I would get a proper bold text, but it is not readable for htmltext.
What I'm wondering is is there a way to convert the raw utf8 to the 才 style on the fly - so as to preserve the original (editable) text, but to then be able to display it in an htmltext field?
At this point in time the translators are simply writing the translations using a text editor - and dropping the basic tags in the appropriate places. They have no knowledge of the numerical codes for the characters they are typing as such.
Cheers,
Dave
Sorry for not replying earlier - had a Modem crash!
If I have something like:
<b>才出吃</b>
in my html/text file then I get the same appearing in the field for unicodetext (i.e. - characters are there along with the <b> tags), but I would get a proper bold text, but it is not readable for htmltext.
What I'm wondering is is there a way to convert the raw utf8 to the 才 style on the fly - so as to preserve the original (editable) text, but to then be able to display it in an htmltext field?
At this point in time the translators are simply writing the translations using a text editor - and dropping the basic tags in the appropriate places. They have no knowledge of the numerical codes for the characters they are typing as such.
Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.
Visit http://electronic-apps.info for released App information.
Re: Unicode and HTML for Fields
As you say they add simple tags I think one way of doing it is:
put the utf into fld1 you get:
<b>才出吃</b>
put the htmlText fld1 into fld2:
<p><b>才出吃</b></p>
then
replace "<" with "<" in fld2
replace ">" with ">" in fld2
result <p><b>才出吃</b></p>
and then set the htmlText of a fld2 to the output fld.
Simon
put the utf into fld1 you get:
<b>才出吃</b>
put the htmlText fld1 into fld2:
<p><b>才出吃</b></p>
then
replace "<" with "<" in fld2
replace ">" with ">" in fld2
result <p><b>才出吃</b></p>
and then set the htmlText of a fld2 to the output fld.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Livecode Opensource Backer
- Posts: 328
- Joined: Mon Dec 05, 2011 5:34 pm
- Contact:
Re: Unicode and HTML for Fields
Simon - that was Perfect - exactly what I needed, and so simple too.
The only thing I added was a replace """ with quote - to handle some <font color="red"> bits.
I really hope that this can help others too, who may be having difficulty with utf8/unicode/html.
Thanks again.
Cheers,
Dave
The only thing I added was a replace """ with quote - to handle some <font color="red"> bits.
Code: Select all
// tdat contains html tags and raw utf8 data
set the unicodetext of field "textField" to uniEncode(tdat,"utf8")
put the htmltext of field "textField" into tagged
replace "<" with "<" in tagged
replace ">" with ">" in tagged
replace """ with quote in tagged
set the htmltext of field "textfield" to tagged
Thanks again.
Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.
Visit http://electronic-apps.info for released App information.
Re: Unicode and HTML for Fields
Great, I'm glad it worked for you.
A couple of weeks ago I went through double byte terror so it was all still fresh in my mind.
Simon
A couple of weeks ago I went through double byte terror so it was all still fresh in my mind.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!