HTML muddle

Richard Gaskin ambassador at fourthworld.com
Wed Feb 18 19:08:50 CET 2015


Graham Samuel wrote:

 > I just tried it and of course it works, but I can’t quite see
 > what’s happening inside LC. I mean, I can select the field
 > within my stack which has the formatted text in it, copy it
 > and paste it into Word, and bingo! it looks the same. There
 > is no obvious sign that Word thinks it was formatted in HTML.

When text is rendered on screen (in LC, Word, or even a Web browser), 
it's a binary structure of text and style runs.

None of the formatting per se is in html/htmlText.  Those are just 
plain-text ways to *describe* formatting, but not the formatting itself.

Any renderer, such as LiveCode or a browser, will need to interpret 
those html/htmlText descriptions into text with style runs.

HtmlText is simply an intermediary format generated from the binary 
style run data when obtained from a field, and interpreted into binary 
style run data when applied to a field.

If this isn't confusing enough, take some time to experiment with the 
relatively new styledText field property.  It returns an array of the 
text and style runs within a field object in a way that more closely 
reflects how the engine handles these things under the hood.

Not only will styledText give you a new appreciation for how programs 
render styled text, but once you get the hang of working with it you'll 
find it's often much faster for identifying and manipulating style info 
in field contents than htmlText.

For example, last week I needed to find runs of text in a field that had 
linkText values.  In htmlText the performance wasn't bad, but when I 
rewrote that to use a styledText array it took only half as long.

Getting close to the engine is rarely a bad thing.

Know the engine.
Trust the engine.
Use the engine.

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com



More information about the use-livecode mailing list