HTMLText question

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
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

HTMLText question

Post by dunbarx » Thu Jul 22, 2021 4:17 pm

I can replace a word in a variable string with its capitalized version:

Code: Select all

replace "section" with "SECTION" in myVariable
But I want to replace a word in a field with the underlined version of that word. I assume that one cannot do this sort of thing in a variable, since no styled text can live there, only ASCII chars, which is why capitalization is possible.

This can be done easily in a field by setting the textStyle of the word, but one has to know the chunk that the word of interest "lives" in:

Code: Select all

set the textStyle of word 2 of fld 2 to "underline"
So my question is this: in a field, do I have to FIND the word of interest to get its chunk reference and then change its textStyle? Is there no way to kludge a "replace-type" gadget to do that? In other words, if I had an underlined "cat" in fld 1, something like:

Code: Select all

put "dog cat fish"  into fld 2
   replace "cat" with fld 1 in fld 2 --just "cat" appears, not the underlined "cat" of fld 1
   replace "cat" with the  htmlText of fld 1 in fld 2 --the minimally tagged "cat" appears
   replace "cat" with the effective htmlText of fld 1 in fld 2  --the fully tagged "cat" appears
Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: HTMLText question

Post by FourthWorld » Thu Jul 22, 2021 4:42 pm

Code: Select all

replace "cat" with "<u>cat</u>" in tMyFldHtml
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: HTMLText question

Post by dunbarx » Thu Jul 22, 2021 4:45 pm

Interestingly (or not), if I have an underlined "cat" in a field 1:

Code: Select all

answer fld 1 -- gives "cat"
   answer the  htmlText of fld 1 -- gives "cat"
   answer the effective htmlText of fld 1-- gives underlined "cat"
It seems you cannot add style tags inside the code tags

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: HTMLText question

Post by FourthWorld » Thu Jul 22, 2021 5:24 pm

Is "cat" the only word in the field, and the underline assigned to the field rather than the content within the field?

If that's not the case, and you have applied the text style only to the specific run within the field, I don't understand your reply.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: HTMLText question

Post by dunbarx » Thu Jul 22, 2021 5:32 pm

Richard.

Thanks. I had this, and likely did not explain what I wanted very well:

Code: Select all

on mouseUp
   put "dog cat fish"  into fld 2   
   
   put the htmltext of  field 1 into tText -- contains "cat"
   replace "p" with "u" in tText
   
   get fld 2
   replace "cat" with tText in it
   set the htmltext of word 2 of field 2 to tText
end mouseUp
I really wanted to know if it was possible to "replace" directly into the field, not to have to prepare a variable string first:

Code: Select all

replace "cat" with "<u>cat</u>" in fld 2
Unless I could escape the quotes, perhaps this is really not possible.

The target field has lots of text, and I wanted to directly replace all instances of "cat" with "cat"

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: HTMLText question

Post by dunbarx » Thu Jul 22, 2021 5:43 pm

As an aside, if I have a fld 1 with only the word "CAT" in it, (underlined) and I:
get the htmlText of word 1 of fld 1, I get:
<p>CAT</p>
Why? That single word is underlined. It does not matter if I set the textStyle of the entire field to "bold".

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: HTMLText question

Post by FourthWorld » Thu Jul 22, 2021 5:49 pm

A lot of the work I've done over the last 20 years depends on parsing and modifying htmlText.

The only times I've seen what you're describing is when the style is applied to the field rather than the content within the field.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9655
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: HTMLText question

Post by dunbarx » Thu Jul 22, 2021 5:59 pm

The only times I've seen what you're describing is when the style is applied to the field rather than the content within the field.
I get that. I almost never have to deal with styled text in anything I do. Anyway, now, after making a new field and setting the style of the text, not the field, the htmltext comes out correctly. I did that before, though, I swear.

Oh well.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”