ElementTree addInlineElementAt(ElementTree block, InlineElement inline, Int startpos, Int endpos)
Arguments
block: The element to add toinline: The inline element to addstartpos: The start position for the inline elementendpos: The end position for the inline element
Usage
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 InvalidNesting Exception will be thrown if the element being added to cannot contain inline elements, or an impossible nesting situation would be created. An InvalidRange 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
}
}