Name: HTMLText

Type: property

Syntax: set the HTMLText of [<chunk> of] <field> to <htmlString>

Syntax: get the [effective] HTMLText of [<chunk> of] <field>

Summary:
Specifies the contents of a <field>, including all text
<textStyle|styles> and paragraph <format|formatting>, represented as
<HTML> tags and special characters represented as <HTML> entities.

Associations: field

Introduced: 1.0

OS: mac, windows, linux, ios, android

Platforms: desktop, server, mobile

Example:
set the HTMLText of field "White Paper" to "&lt;b&gt;&lt;i&gt;Click here!&lt;/i&gt;&lt;/b&gt;"

Example:
set the HTMLText of field "Dest" to the HTMLText of field "Source"

Example:
write the HTMLText of field "Story" to file myWebFile

Example:
put the effective htmlText of field "description"

Example:
set the HTMLText of field "display" to URL "http://www.server.com/somepage.html"

Description:
Use the <HTMLText> <property> to copy or export a
<field(object)|field's> contents with the text and paragraph
<format|formatting> intact. Setting the <HTMLText> of a field can also
be a way of displaying simple <HTML>-formatted text from a web page or
external file. It should be emphasized that the <HTMLText> property is
not a complete <HTML> rendering engine. Instead, it can be understood as
a way to faithfully represent the entire contents of a field, including
text and paragraph formatting, using HTML-style tags and attributes.

The <HTMLText> of a <field(object)> or <chunk> is a <string>.
If the <effective> keyword is specified the <HTMLText> property returns
the <HTML> of the field with explicit formatting. For example if the
<textFont> of the stack is set this is not included in the <HTMLText>
but is included in the <effective> <HTMLText>.

The <HTMLText> <property> is a representation of the styled text and
paragraph formatting of the <field(object)>. LiveCode uses a subset of
<HTML> tags that includes font, size, style, and text color information,
along with paragraph alignment, indentation, spacing, padding and other
information. 

<set(command)|Setting> the <HTMLText> of a <field(object)> (or a <chunk>
of a <field(object)>) sets both the text contents and the style
attributes corresponding to the tags listed below. (Other tags are
ignored.) 

<get(command)|Getting> the <HTMLText> <property> reports a <string>
consisting of the text of the <field(object)> (or <chunk> of a
<field(object)>), with any font, size, style, or color <properties>
embedded in the text in the form of the tags listed below.

The tags translate as follows:

&lt;p&gt; &lt;/p&gt;
Encloses a line of text. (Blank lines are also enclosed in &lt;p&gt;
&lt;/p&gt;.) These properties are represented as attributes of the
&lt;p&gt; tag:

* align="left|center|right" appears if an <textAlign|alignment> has been
  applied to the line.
* firstindent="N" (where N is an integer representing number of pixels)
  appears if the <firstIndent> has been set for the line.
* leftindent="N" appears if the <leftIndent> has been set for the line.
* rightindent="N" appears if the <rightIndent> has been set for the
  line. 
* spaceabove="N" appears if the <spaceAbove> has been set for the line.
* spacebelow="N" appears if the <spaceBelow> has been set for the line.
* tabstops="N" appears if <tabStops> have been set for the line.
* tabAlign="left|center|right[,left|center|right...]" appears if <tabAlign> has been set for the line.
* borderwidth="N" if a <borderWidth> has been set for the line.
* hgrid="true|false" if the <vGrid> property has been set for the line.
* vgrid="true|false" if the <hGrid> property has been set for the line.
* dontwrap="true|false" if the <dontWrap> property has been set for the
  line. 
* padding="N" if the <padding> has been set for the line.
* hidden="true|false" if the <hidden> property has been set for the
  line. 
* bgcolor="#NNNNNN" if a <backgroundColor> has been set for the line.
* bordercolor="#NNNNNN" if a <borderColor> has been set for the line.

>*Note:* An <HTML>-style color definition can take one of the two forms.
> The first consists of a hash mark (#) followed by three 2-digit 
> hexadecimal numbers, one each for red, green, and blue. E.g., 
> "#FF9900" represents an orange color. The second form consists of 
> three comma delimited integers between 0 and 255. E.g. "255,153,0" 
> represents an orange color. 

&lt;sub&gt; &lt;/sub&gt;
Encloses text whose <textShift> is a positive <integer>. 
(The &lt;sub&gt; tag is not nested for additional levels of
subscription: it appears once for a run of subscripted text, regardless
of the value of the <textShift>.)

* shift="N" where N is the number of pixels text is subscripted.


&lt;sup&gt; &lt;/sup&gt;
Encloses text whose <textShift> is a <negative> <integer>. (The
&lt;sup&gt; tag is not nested for additional levels of superscription:
it appears once for a run of superscripted text, regardless of the value
of the <textShift>.)

* shift="-N" where N is the number of pixels text is superscripted.


&lt;i&gt; &lt;/i&gt;
Encloses text whose <textStyle> is "italic".
>*Note:* If a field is set to <HTML> text that includes text enclosed by
> &lt;em&gt; &lt;/em&gt;,
the tag will be converted to &lt;i&gt; &lt;/i&gt;.

&lt;b&gt; &lt;/b&gt;
Encloses text whose <textStyle> is "bold".
>*Note:* If a field is set to <HTML> text that includes text enclosed by
> &lt;strong&gt; &lt;/strong&gt;,
the tag will be converted to &lt;b&gt; &lt;/b&gt;.

&lt;strike&gt; &lt;/strike&gt;
Encloses text whose <textStyle> is "strikeout".

&lt;u&gt; &lt;/u&gt;
Encloses text whose <textStyle> is "underline".

&lt;box&gt; &lt;/box&gt;
Encloses text whose <textStyle> is "box".

&lt;threedbox&gt; &lt;/threedbox&gt;
Encloses text whose <textStyle> is "threeDBox".

&lt;font&gt; &lt;/font&gt;
Encloses text whose <textFont>, <textSize>, <foregroundColor>, or
<backgroundColor> is different from the <field(object)|field's>
<default>. These five <property|properties> are represented as
attributes of the &lt;font&gt; tag.

* face="fontName" appears in the &lt;font&gt; tag if the <textFont> is
  not the <default>.
* size="N" (where N is the point size of the font) appears if the
  <textSize> is not the <default>.
* lang="languageName" appears if the <textFont> includes a
  <fontLanguage|language> specification.
* color="#NNNNNN" appears if the <foregroundColor> is not the <default>.
* bgcolor="#NNNNNN" appears if the <backgroundColor> is not the
  <default>. 

>*Note:* An <HTML>-style color definition consists of a hash mark (#)
> followed by three 2-digit hexadecimal numbers,
one each for red, green, and blue. E.g., "#FF9900" represents an orange
color. 

&lt;ol type="lower latin|upper latin|lower roman|upper roman"&gt;
&lt;/ol&gt; Encloses lines of text whose <listStyle> <property> is one
of the following:

* lower latin
* upper latin
* lower roman
* upper roman


&lt;ul type="disc|circle|square|skip"&gt; &lt;/ul&gt; 
Encloses lines of text whose <listStyle> <property> is one of the
following: 

* "disc"
* "circle"
* "square"
* "skip"


&lt;li&gt; &lt;/li&gt;
Encloses a line of text whose <listStyle> <property> has been set to one
of the <listStyle|listStyles> listed above.

&lt;a&gt; &lt;/a&gt;
Encloses text whose <textStyle> is "link" or whose <linkText> <property>
is not empty. If the <textStyle> of the text contains "link", the
<linkText> is included as the value of the "href" attribute. Otherwise,
it is included as the value of the "name" attribute.

&lt;img src="imageSpecifier"&gt;
Replaces a character whose <imageSource> <property> is not empty. The
value of the <imageSource> <property> is included as the value of the
"src" attribute.

&lt;span metadata="string"&gt; &lt;/span&gt; 
Encloses a run of text whose <metadata> property is set to the string
indicated. 

When you set the <HTMLText> of a <field(object)>, all tags other than
those above are ignored, except heading tags (&lt;h1&gt;--&lt;h6&gt;),
which change the size of the text in the heading element:

tag | textSize
:----:|:---------:
&lt;h1&gt; | 34 point
&lt;h2&gt; | 24 point
&lt;h3&gt; | 18 point
&lt;h4&gt; | 14 point
&lt;h5&gt; | 12 point
&lt;h6&gt; | 10 point

When <set|setting> the <HTMLText> of a <field(object) to an
<HTML>-formatted string, you can use LiveCode color references for the
"color" and "bgcolor" attributes. LiveCode translates these into
standard HTML-style color specifications.

If a chunk of text includes more than one of the above styles, LiveCode
encloses the text in the tags corresponding to each style, from the
inside out. For example, if the word "Flail" in a field is underlined
and bold, its corresponding <HTMLText> is
"&lt;u&gt;&lt;b&gt;Flail&lt;/b&gt;&lt;/u&gt;". 

Special characters (whose ASCII value is greater than 127) are encoded
as <HTML> entities. Named <HTML> entities are enclosed by a leading
ampersand and trailing semicolon; e.g. &amp;agrave; for &agrave; and
&amp;euro; for &euro;. LiveCode recognizes all 253 entities defined in
the XHTML specification at
<http://www.w3.org/TR/html4/sgml/entities.html>. 

Unicode characters whose decimal numeric value is greater than 255 are
encoded as "bignum" entities, with a leading ampersand and trailing
semicolon. For example, the Japanese character whose numeric value is
12387 is encoded as an entity like this:&amp;#12387;.

>*Note:* The <HTMLText> of a <field(object)> or <chunk> includes
> formatting information for the text, but does not include information
about the text <properties> of the <field(object)> itself. If you use
the <HTMLText> <property> to transfer text between
<field(object)|fields>, you must make sure that the destination
<field(object)|field's> <textFont> and other text <properties> match the
settings of the source field, if you want the text in both
<field(object)|fields> to look identical.

>*Important:* The <HTMLText> <property> uses a tag structure that is
> HTML-like, but is not completely standard <HTML>,
in order to accommodate the full range of text styling available in
LiveCode. Specifically:

* The link, box and threedbox tags, as well as the bgColor attribute of
  the font tag, have been added to accommodate styles that don't exist
  in standard HTML.
* The size attribute of the font tag can encode the font's point size,
  in addition to the standard 7 HTML sizes.
* The <HTMLText> reports entities whose <ASCII|ASCII value> is between
  129 and 159. These correspond to characters in the <Windows>
  <character set> (Code Page 1252) that are not legal <HTML> entities.


Changes:
The lang attribute, and the ability to encode Unicode characters, was
added in version 2.0.

The following enhancements were added in version 5.5: 

* Support for fully representing paragraph formatting by means of
  &lt;p&gt; tag attributes;
* Support for representing ordered and unordered lists and list styles
  by means of &lt;ul&gt; and &lt;ol&gt; tags, and list items by means of
  &lt;li&gt; tag attributes;
* Support for representing metadata in text runs by means of a
  &lt;span&gt; tag and metadata attribute;
* Complete support for HTML entities;
* Complete support for representing all LiveCode text styles in HTML
  tags; 
* Improved representation of linkText and imageSource by means of
  &lt;a&gt; tag attributes and &lt;img&gt; tag attributes respectively.


Support was added for &lt;strong&gt; and &lt;em&gt; tags in version 6.0.

Support for the <tabAlign> property was added in version 8.1.2

References: get (command), set (command), charToNum (function),
colorNames (function), format (function), numToChar (function),
fontLanguage (function)
ASCII (glossary), character set (glossary), chunk (glossary),
default (glossary), encode (glossary), format (glossary),
hexadecimal (glossary), HTML (glossary), integer (glossary),
negative (glossary), property (glossary), string (glossary),
Windows (glossary), effective (keyword), field (keyword), URL (keyword),
field (object), backgroundColor (property), borderColor (property),
borderWidth (property), dontWrap (property), dragData (property),
firstIndent (property),
foregroundColor (property), hGrid (property), hidden (property),
HTMLText (property), imageSource (property), leftIndent (property),
linkText (property), listStyle (property), metadata (property),
mimeText (property), padding (property), rightIndent (property),
RTFText (property), spaceAbove (property), spaceBelow (property),
tabAlign (property),
tabStops (property), textAlign (property), textFont (property),
textShift (property), textSize (property), textStyle (property),
unicodeText (property), vGrid (property)

Tags: text processing

