Class: RichTextUtils

Kekule.Render. RichTextUtils

new RichTextUtils()

Methods to manipulate rich format text. A rich format text is consists of a array of objects. For example: { role: 'seq', anchorItem: itemRef, // or default first item, must be the direct child of group or seq items: [ { role: 'lines', // this special role is used in multiline text items: [ { role: 'section', text: 'Text1', //font: 'arial bold italic 10px', textType: 'subscript', refItem: anRichTextItem, // the subscript or superscript is attached to which one? If not set, regard prev one as refItem horizontalAlign: 1, // value from Kekule.Render.TextAlign verticalAlign: 1, charDirection: 1, overhang: 0.1, oversink: 0.1, _noAlignRect: true, // a special property to tell the drawer that this item should not be considered into align box. // super/subscript defaultly has noAlign = true }, { role: 'section' text: 'Text2', fontSize: '20px', textType: 'normal' }, { role: 'group', anchorItem: itemRef, items: [...] } ] ] }
Source:

Methods

(static) append(destGroup, groupOrSection) → {Object}

Append a group or section to tail in destGroup.
Parameters:
Name Type Description
destGroup Object
groupOrSection Object
Source:
Returns:
Type
Object

(static) appendItems(destGroup, items) → {Object}

Append a set of groups or sections to tail in destGroup.
Parameters:
Name Type Description
destGroup Object
items Array
Source:
Returns:
Type
Object

(static) appendText(richTextGroup, text, style, isAnchor) → {Object}

Append a styled text to richText group and returns the whole group.
Parameters:
Name Type Description
richTextGroup Object
text String
style Hash Can be null.
isAnchor Bool Whether the newly insert section will become the anchorItem.
Source:
Returns:
richTextGroup
Type
Object

(static) appendText2(richTextGroup, text, style, isAnchor) → {Object}

Append a styled text to richText group and returns the new section created.
Parameters:
Name Type Description
richTextGroup Object
text String
style Hash Can be null.
isAnchor Bool Whether the newly insert section will become the anchorItem.
Source:
Returns:
New section appended to richTextGroup.
Type
Object

(static) clone(richText) → {Object}

Clone source rich text.
Parameters:
Name Type Description
richText Object
Source:
Returns:
Type
Object

(static) create()

Create a new and empty rich text object.
Source:

(static) createGroup(role)

Create a new group.
Parameters:
Name Type Description
role String Role of group, if not set, a normal role of 'group' will be created.
Source:

(static) createSection(text, style)

Create a section object of richText (an item in richtext array).
Parameters:
Name Type Description
text String
style Hash
Source:

(static) fromHtml(htmlElement) → {Object}

Create new rich text from HTML element.
Parameters:
Name Type Description
htmlElement Element
Source:
Returns:
Created richtext object.
Type
Object

(static) getActualRefItem(item, parent) → {Object}

Returns the actual refItem of item. Generally this function returns item.refItem, however, if that value is not set, function will return item's nearest sibling.
Parameters:
Name Type Description
item Object
parent Object item's parent group.
Source:
Returns:
Type
Object

(static) getFinalAnchorItem(richText) → {Object}

Find the real anchor item in richText cascadely.
Parameters:
Name Type Description
richText Object
Source:
Returns:
Type
Object

(static) getFirstNormalTextSection(richTextGroup) → {Object}

Returns the first normal text (nor sub/superscript) in rich text.
Parameters:
Name Type Description
richTextGroup Object
Source:
Returns:
Type
Object

(static) getItemRole(item) → {String}

Returns role (normal, sup or sub) of item.
Parameters:
Name Type Description
item Object
Source:
Returns:
Constant value from Kekule.Render.RichText
Type
String

(static) getItemTextType(item) → {String}

Return text type (normal, superscript or subscript) of item.
Parameters:
Name Type Description
item Object
Source:
Returns:
Constant value from Kekule.Render.RichText
Type
String

(static) getItemType(item) → {String}

Returns type (section or group) of item.
Parameters:
Name Type Description
item Object
Source:
Returns:
Constant value from Kekule.Render.RichText.
Type
String

(static) insert(destGroup, index, groupOrSection) → {Object}

Insert a group or section to a special position in destGroup.
Parameters:
Name Type Description
destGroup Object
index Int
groupOrSection Object
Source:
Returns:
Type
Object

(static) insertText(richTextGroup, index, text, style, isAnchor) → {Object}

Insert a styled text to a special position of richText group.
Parameters:
Name Type Description
richTextGroup Object
index Int
text String
style Hash Can be null.
isAnchor Bool Whether the newly insert section will become the anchorItem.
Source:
Returns:
Type
Object

(static) isGroup(item) → {Bool}

Check if an item is a rich text group.
Parameters:
Name Type Description
item Object
Source:
Returns:
Type
Bool

(static) isSection(item) → {Bool}

Check if an item is a rich text section.
Parameters:
Name Type Description
item Object
Source:
Returns:
Type
Bool

(static) isSubscript(item) → {Bool}

Check if item is a superscript.
Parameters:
Name Type Description
item Object
Source:
Returns:
Type
Bool

(static) isSuperscript(item) → {Bool}

Check if item is a superscript.
Parameters:
Name Type Description
item Object
Source:
Returns:
Type
Bool

(static) strToRichText(str, style) → {Object}

Convert a plain string to rich format text. Multiline is supported.
Parameters:
Name Type Description
str String
style Hash Can be null
Source:
Returns:
Type
Object

(static) tidy(richText) → {Object}

Tidy the rich text and merge groups with same style.
Parameters:
Name Type Description
richText Object
Source:
Returns:
Type
Object

(static) toHtml(doc, richText, reversedDirection) → {HTMLElement}

Convert rich text to HTML element. Note: in the conversion, vertical lines are all turned into horizontal lines
Parameters:
Name Type Description
doc Document Owner document of result element.
richText Object
reversedDirection Bool
Source:
Returns:
Type
HTMLElement

(static) toSimpleHtmlCode(richText) → {HTMLElement}

Convert rich text to HTML code in a simple way.
Parameters:
Name Type Description
richText Object
Source:
Returns:
Type
HTMLElement

(static) toText(richText) → {String}

Extract text in rich text and returns a pure string.
Parameters:
Name Type Description
richText Object
Source:
Returns:
Type
String