Kaya 0.5.2 reference for HTMLDocument::addInlineElementAt

List of functions and data types in HTMLDocument

ElementTree addInlineElementAt(ElementTree block, InlineElement inline, Int startpos, Int endpos)

Arguments

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
    }
}

Related

kaya@kayalang.org | Last modified 29 November 2011 | Supported by Durham CompSoc | Powered by Kaya