How to get the original text from a HTMLText?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Fermin
Posts: 149
Joined: Fri Jun 05, 2015 10:44 pm

How to get the original text from a HTMLText?

Post by Fermin » Sun May 08, 2016 5:28 pm

Hi, one question, please...
Is there any instruction to get the original text (unformatted) from a HTMLText?
Thank you very much.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to get the original text from a HTMLText?

Post by FourthWorld » Sun May 08, 2016 7:04 pm

Set the htmlText of a spare field, then get the field's text. You can use the templateField if you don't have a spare field object.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Fermin
Posts: 149
Joined: Fri Jun 05, 2015 10:44 pm

Re: How to get the original text from a HTMLText?

Post by Fermin » Sun May 08, 2016 7:42 pm

Thank you, FourthWorld...
Well, it is not a critical issue because I had already solved with two fields.

In my test example:

I have a field ("MyField") with a text with words of different colors and need:
1) Save this text
2) Clean the field (or maybe write it any other text, etc. etc...)
3) Recover the original text in the same field with the same format (colors etc.)

I get it using two containers: one named "tP" to the plain text and another named "tH" for the HTML version. I have prepared a button with two options: 'Preserve' and 'Restore' and the system works well. The script is this:
--------------
on menuPick pItemName
   pItemName switch
      case "Preserve"
         put fld "myField" into fld "tP" - Plain Text
         put the htmlText of fld "myField" into fld "tH" - Text HTML
         -
         put "" into fld "MyField"
         -
         break
      case "Restore"
         put fld "tP" into fld "myField" -
         Set the htmlText of fld "myField" to fld "tH"
         break
   end switch
end menuPick
-----------------

It works well but, as the HTMLText format contains all the information, I thought that, maybe, there is an instruction to directly extract the plain text, and thus, use only one field.
Anyway, thanks again, FourthWorld for your quick help. :D

Post Reply