Page 1 of 1
HTMLText question
Posted: Thu Jul 22, 2021 4:17 pm
by dunbarx
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
Re: HTMLText question
Posted: Thu Jul 22, 2021 4:42 pm
by FourthWorld
Code: Select all
replace "cat" with "<u>cat</u>" in tMyFldHtml
Re: HTMLText question
Posted: Thu Jul 22, 2021 4:45 pm
by dunbarx
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
Re: HTMLText question
Posted: Thu Jul 22, 2021 5:24 pm
by FourthWorld
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.
Re: HTMLText question
Posted: Thu Jul 22, 2021 5:32 pm
by dunbarx
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
Re: HTMLText question
Posted: Thu Jul 22, 2021 5:43 pm
by dunbarx
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
Re: HTMLText question
Posted: Thu Jul 22, 2021 5:49 pm
by FourthWorld
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.
Re: HTMLText question
Posted: Thu Jul 22, 2021 5:59 pm
by dunbarx
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