HTMLDocument.addInlineElementAt3kaya
Wrap existing text in an inline element
Usage
ElementTree addInlineElementAt( ElementTree block, InlineElement inline, Int startpos, Int endpos )
Arguments
block The element to add to
inline The inline element to add
startpos The start position for the inline element
endpos The end position for the inline element
Overview
Encloses existing text within an element within an inline element. The characters from startpos to endpos inclusive (with a starting index of zero) will be included in the inline element.
-
p = addParagraph(parent,"abcdefghijklmnopqrstuvwxyz");
void(addInlineElementAt(p,Emphasis,5,10));
void(addInlineElementAt(p,StrongEmphasis,6,8));
// <p>abcde<em>f<strong>ghi</strong>jk</em>lmnopqrstuvwxyz</p>
An HTMLDocument.InvalidNesting (3kaya) Exception will be thrown if the element being added to cannot contain inline elements, or an impossible nesting situation would be created. An HTMLDocument.InvalidRange (3kaya) Exception will be thrown if the startpos or endpos are outside the text contents of the block.
-
p = addParagraph(parent,"abcdefghijklmnopqrstuvwxyz");
void(addInlineElementAt(p,Emphasis,5,10));
void(addInlineElementAt(p,StrongEmphasis,6,15));
// exception thrown
The firstOccurs function is useful for highlighting a particular word within a string.
-
haystack = getAllText(element);
npos = firstOccurs(needle,haystack);
if (npos < length(haystack)) {
try {
added = addInlineElementAt(element,Emphasis,npos,npos+length(needle)+1);
} catch(InvalidNesting(details)) {
// probably overlapping elements
}
}
Releases
4 releases since Debian 5.0 (Lenny); the text changed 3 times.