Formatting text saved in an array
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Formatting text saved in an array
Hi everyone,
I just wanted to check if there was a way of 'formatting' text saved in an array?
At present I've got text displayed in a field which is then saved as part of an array and the plain text saves as expected as an array.
However, if I apply say underline or bold to the text in the field, these changes are then lost when I retrieve the text from the array.
Is there a way of maintaining the formatting of the text on saving to an array.
Kind regards,
Glenn
I just wanted to check if there was a way of 'formatting' text saved in an array?
At present I've got text displayed in a field which is then saved as part of an array and the plain text saves as expected as an array.
However, if I apply say underline or bold to the text in the field, these changes are then lost when I retrieve the text from the array.
Is there a way of maintaining the formatting of the text on saving to an array.
Kind regards,
Glenn
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Formatting text saved in an array
Sure, something like?:
Arrays are just variables, after all. Read up on the "htmlText" in the dictionary.
Craig
Code: Select all
on mouseUp
put the htmlText of fld 1 into myArray["x"]
set the htmlText fld 2 to myArray["x"]
end mouseUp
Craig
Re: Formatting text saved in an array
Thanks Craig,
Have now checked the dictionary but not sure I'm understanding it completely in relationship to what I want to achieve!
I guess if I wanted the whole field have a particular formatting, eg bold, applied to it then I'm assuming the htmlText is what's needed.
However, I'm wanting each array element to have its own individual formatting with parts bold and underlined etc.
What I was envisaging was to edit the formatting of the element in a field, and then to have the formatting saved when the element is saved in the array.
Not sure how to achieve this, or even if its possible?
Kind regards,
Glenn
Have now checked the dictionary but not sure I'm understanding it completely in relationship to what I want to achieve!
I guess if I wanted the whole field have a particular formatting, eg bold, applied to it then I'm assuming the htmlText is what's needed.
However, I'm wanting each array element to have its own individual formatting with parts bold and underlined etc.
What I was envisaging was to edit the formatting of the element in a field, and then to have the formatting saved when the element is saved in the array.
Not sure how to achieve this, or even if its possible?
Kind regards,
Glenn
Re: Formatting text saved in an array
The htmlText of the field is a property that includes all the (LC-version) styled html text of the field. If you set the text formatting of a field how you want, the put the htmlText of that field into a variable/custom property/write it out to a text file to save, then clear the field, you will be able to restore it by setting the htmlText of the field to the value you saved. This will include all the formatting you applied before.
For more granularity you can also delve into the "styledText" property and see if that is more applicable to your needs, but the htmlText is not limited to one style run only.
For more granularity you can also delve into the "styledText" property and see if that is more applicable to your needs, but the htmlText is not limited to one style run only.
Re: Formatting text saved in an array
Hi Glenn,
in case you didn't know:
Every element of a field (char, word, item, line etc.) has a HTMLTEXT property, so you can do:
Maybe that helps?
Or do you want to format the contents of the array inside of the array?
Best
Klaus
in case you didn't know:
Every element of a field (char, word, item, line etc.) has a HTMLTEXT property, so you can do:
Code: Select all
...
put the htmltext of word 2 of fld 1 into tArray[1]
put the htmltext of line 1 of fld 1 into tArray[2]
## etc.
...
Or do you want to format the contents of the array inside of the array?
Best
Klaus
Re: Formatting text saved in an array
Thanks Klaus, I hadn't appreciated this!
I guess I'm struggling to implement the suggestions from Craig and yourself as the text of my field is an array element, ie field 1 is the keyword, and field 2 is the element (ie the text that I'm trying to format).
I guess its like a dictionary app, the keyword is the header with the associated definition text as the associated element?
Not sure if this makes what I'm trying to achieve any clearer!
Regards,
Glenn
I guess I'm struggling to implement the suggestions from Craig and yourself as the text of my field is an array element, ie field 1 is the keyword, and field 2 is the element (ie the text that I'm trying to format).
I guess its like a dictionary app, the keyword is the header with the associated definition text as the associated element?
Not sure if this makes what I'm trying to achieve any clearer!
Regards,
Glenn
-
- VIP Livecode Opensource Backer
- Posts: 9823
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Formatting text saved in an array
If field 1 contains the label and field 2 contains the value to be associated with that label...
Code: Select all
put the htmltext of fld 2 into tArray[fld 1]
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Formatting text saved in an array
There is nothing special about an array variable as opposed to an ordinary one, in terms of storing "htmlStyled" text.
If field 1 contains, say "ABC", where "A" is bold, "B" is underlined and "C" is italic, the htmlText of that string is:
Craig
If field 1 contains, say "ABC", where "A" is bold, "B" is underlined and "C" is italic, the htmlText of that string is:
the htmlText will add tags identifying each char. That new string is what is stored in your array. Nothing special, really. When you pull that string out, and set the htmlText of a field to it, that property "resets" all the styles, and you get your original back.<p><b>A</b><u>B</u><i>C</i></p>
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9823
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Formatting text saved in an array
And if you want to get obsessive about performance, arrays can contain arrays, so you could use the styledText of the field instead of the htmlText:
Code: Select all
put the styledText of fld 2 into tArray[fld 1]
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Formatting text saved in an array
Thank you all for the helpful comments, I think I'm starting to get it now!
I now just need to experiment with the syntax to see how I fit it into my code.
Kind regards,
Glenn
I now just need to experiment with the syntax to see how I fit it into my code.
Kind regards,
Glenn
Re: Formatting text saved in an array
Thanks again for all the tips - now able to successfully implement html editing - I think I was previously 'overthinking' the htmlText function and assuming it was more complicated than it actually was!
Am I correct in assuming that the htmlText function simply allow a field to recognise and react to html tags?
Regards,
Glenn
Am I correct in assuming that the htmlText function simply allow a field to recognise and react to html tags?
Regards,
Glenn
-
- VIP Livecode Opensource Backer
- Posts: 9823
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Formatting text saved in an array
Almost.
Htmltext was added as a field property to provide a textual (as opposed to binary) format that retains the contents of the field with complete fidelity. StyledText was added more recently and is more efficient to work with, but sometimes the tagged-text form is useful so htmltext isn't going away.
Where attributes happen to match HTML conventions at the time that feature was added, LC can render that subset of HTML well.
Though htmltext bears some superficial semblance to HTML, they serve fundamentally different purposes. There are tags in each not supported by the other, font sizes are relative in HTML but fixed point sizes in htmltext, many paragraph-level features are implemented differently, etc. And LC has no facility for handling CSS at all, which is where most HTML styling takes place these days.
So if you happen to find HTML that works well imported into a field, consider yourself lucky.
If you need to render modern HTML inside LC use the browser widget.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Formatting text saved in an array
Richard,
Many thanks for the interesting and useful background.
Kind regards,
Glenn
Many thanks for the interesting and useful background.
Kind regards,
Glenn