HTMLText | |||||||||||||||
Type | property | ||||||||||||||
Dictionary | LCS | ||||||||||||||
Library | LiveCode Script | ||||||||||||||
Syntax |
| ||||||||||||||
Associations | field | ||||||||||||||
Summary | Specifies the contents of a field, including all text styles and paragraph formatting, represented as HTML tags and special characters represented as HTML entities. | ||||||||||||||
Introduced | 1.0 | ||||||||||||||
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 was added for <strong> and <em> tags in version 6.0. Support for the tabAlign property was added in version 8.1.2 | ||||||||||||||
OS | mac, windows, linux, ios, android | ||||||||||||||
Platforms | desktop, server, mobile | ||||||||||||||
Example |
| ||||||||||||||
Related | Keyword: effective, field, URL Property: backgroundColor, borderColor, borderWidth, dontWrap, dragData, firstIndent, foregroundColor, hGrid, hidden, HTMLText, imageSource, leftIndent, linkText, listStyle, metadata, mimeText, padding, rightIndent, RTFText, spaceAbove, spaceBelow, tabAlign, tabStops, textAlign, textFont, textShift, textSize, textStyle, unicodeText, vGrid Command: get, set Function: charToNum, colorNames, format, numToChar, fontLanguage Glossary: character set, chunk, default, encode, format, hexadecimal, HTML, integer, negative, property, string, Windows Object: field | ||||||||||||||
Description | Use the HTMLText property to copy or export a field's contents with the text and paragraph 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 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. 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. Setting the HTMLText of a field (or a chunk of a field) sets both the text contents and the style attributes corresponding to the tags listed below. (Other tags are ignored.) Getting the HTMLText property reports a string consisting of the text of the field (or chunk of a field), 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: <p> </p> Encloses a line of text. (Blank lines are also enclosed in <p> </p>.) These properties are represented as attributes of the <p> tag:
<sub> </sub> Encloses text whose textShift is a positive integer. (The <sub> 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.)
<sup> </sup> Encloses text whose textShift is a negative integer. (The <sup> 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.)
<i> </i> Encloses text whose textStyle is "italic". *Note:* If a field is set to HTML text that includes text enclosed by <em> </em>, the tag will be converted to <i> </i>. <b> </b> Encloses text whose textStyle is "bold". *Note:* If a field is set to HTML text that includes text enclosed by <strong> </strong>, the tag will be converted to <b> </b>. <strike> </strike> Encloses text whose textStyle is "strikeout". <u> </u> Encloses text whose textStyle is "underline". <box> </box> Encloses text whose textStyle is "box". <threedbox> </threedbox> Encloses text whose textStyle is "threeDBox". <font> </font> Encloses text whose textFont, textSize, foregroundColor, or backgroundColor is different from the field's default. These five properties are represented as attributes of the <font> tag.
<ol type="lower latin|upper latin|lower roman|upper roman"> </ol> Encloses lines of text whose listStyle property is one of the following:
<ul type="disc|circle|square|skip"> </ul> Encloses lines of text whose listStyle property is one of the following:
<li> </li> Encloses a line of text whose listStyle property has been set to one of the listStyles listed above. <a> </a> 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. <img src="imageSpecifier"> Replaces a character whose imageSource property is not empty. The value of the imageSource property is included as the value of the "src" attribute. <span metadata="string"> </span> Encloses a run of text whose metadata property is set to the string indicated. When you set the HTMLText of a field, all tags other than those above are ignored, except heading tags (<h1>--<h6>), which change the size of the text in the heading element:
When 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 "<u><b>Flail</b></u>". 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. à for à and € for €. 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:っ.
| ||||||||||||||
Tags | text processing |