Expand all

ve.dm.ModelFromDomConverter

Constructor

new ve.dm.ModelFromDomConverter(modelRegistry, nodeFactory, annotationFactory) #

Provides VisualEditor linear data to HTML DOM conversion functionality to ve.dm.Converter.

Parameters:

Name Type Description
modelRegistry ve.dm.ModelRegistry
nodeFactory ve.dm.NodeFactory
annotationFactory ve.dm.AnnotationFactory
Source:

Provides VisualEditor linear data to HTML DOM conversion functionality to ve.dm.Converter.

Methods

canCloseWrapper() → {boolean|null} #

Whether the active wrapper can be closed. Note that this is specific to the current recursion level. If there is no active wrapper, this returns false.

Source:

Returns:

Boolean indicating whether the wrapper can be closed, or null if not converting

Type
boolean | null
Whether the active wrapper can be closed.

createDataElements(modelClass, domElements) → {ve.dm.LinearData.Element|Array.<ve.dm.LinearData.Item>|null}private #

Create a data element from a DOM element.

Parameters:

Name Type Description
modelClass ve.dm.Model

Model class to use for conversion

domElements Array.<Node>

DOM elements to convert

Source:

Returns:

Data element or array of linear model data, or null to alienate

Type
ve.dm.LinearData.Element | Array.<ve.dm.LinearData.Item> | null
Create a data element from a DOM element.

getCurrentContext() → {Object|null} #

Get the current conversion context. This is the recursion state of getDataFromDomSubtree().

Source:

Returns:

Context object, or null if not converting

Type
Object | null
Get the current conversion context.

getDataFromDomClean(domElement, [wrapperElement], [annotationSet]) → {Array.<ve.dm.LinearData.Item>} #

Wrapper for getDataFromDom which resets contextStack before the call and then set it back after the call.

TODO: This is kind of a hack, better implementation would be more appropriate in near future.

Parameters:

Name Type Attributes Description
domElement HTMLElement

HTML element to convert

wrapperElement Object optional

Data element to wrap the returned data in

annotationSet ve.dm.AnnotationSet optional

Override the set of annotations to use

Source:

Returns:

Linear model data

Type
Array.<ve.dm.LinearData.Item>

Wrapper for getDataFromDom which resets contextStack before the call and then set it back after the call.

getDataFromDomSubtree(domElement, [wrapperElement], [annotationSet]) → {Array.<ve.dm.LinearData.Item>} #

Get linear model data from a DOM node. Called recursively. For internal use and ve.dm.Model.static.toDataElement() implementations.

Parameters:

Name Type Attributes Description
domElement HTMLElement

HTML element to convert

wrapperElement Object optional

Data element to wrap the returned data in

annotationSet ve.dm.AnnotationSet optional

Override the set of annotations to use

Source:

Returns:

Linear model data

Type
Array.<ve.dm.LinearData.Item>
Get linear model data from a DOM node.

getHtmlDocument() → {HTMLDocument|null} #

Get the HTML document currently being converted

Source:

Returns:

HTML document being converted, or null if not converting

Type
HTMLDocument | null
Get the HTML document currently being converted

getInnerWhitespace(data) → {Array.<(string|undefined)>}private #

Get inner whitespace from linear data

Parameters:

Name Type Description
data ve.dm.LinearData

Linear model data

Source:

Returns:

Sparse array of whitespace strings: [ innerLeft, innerRight ]

Type
Array.<(string|undefined)>
Get inner whitespace from linear data

getModelFromDom(doc, [options], [store]) → {ve.dm.Document} #

Convert an HTML document to a document model.

Parameters:

Name Type Attributes Default Description
doc HTMLDocument

HTML document to convert

options Object optional

Conversion options

Properties:
Name Type Attributes Default Description
targetDoc HTMLDocument optional
doc

Target HTML document we are converting for, if different from doc

fromClipboard boolean optional
false

Conversion is from clipboard

lang string optional

Document language code

dir string optional

Document directionality (ltr/rtl)

store ve.dm.HashValueStore optional
new ve.dm.HashValueStore()

Hash value store

Source:

Returns:

Document model

Type
ve.dm.Document
Convert an HTML document to a document model.

getStore() → {ve.dm.HashValueStore|null} #

Get the HashValueStore used for the current conversion.

Source:

Returns:

Current store, or null if not converting

Type
ve.dm.HashValueStore | null
Get the HashValueStore used for the current conversion.

getTargetHtmlDocument() → {HTMLDocument|null} #

Get the HTML document we are converting data for

Source:

Returns:

HTML document being converted for, or null if not converting

Type
HTMLDocument | null
Get the HTML document we are converting data for

isExpectingContent() → {boolean|null} #

Whether the converter is currently expecting content. Note that this is specific to the current recursion level.

Source:

Returns:

Boolean indicating whether content is expected, or null if not converting

Type
boolean | null
Whether the converter is currently expecting content.

isFromClipboard() → {boolean|null} #

Is the current conversion from the clipboard

Source:

Returns:

The conversion is from the clipboard, or null if not converting

Type
boolean | null
Is the current conversion from the clipboard

isInWrapper() → {boolean|null} #

Whether the conversion is currently inside a wrapper paragraph generated by the converter. Note that this is specific to the current recursion level.

Source:

Returns:

Boolean indicating whether we're wrapping, or null if not converting

Type
boolean | null
Whether the conversion is currently inside a wrapper paragraph generated by the converter.

isValidChildNodeType(nodeType) → {boolean|null} #

Whether the converter can currently accept a child node with the given type.

Parameters:

Name Type Description
nodeType string
Source:

Returns:

Whether the node type is valid, or null if not converting

Type
boolean | null
Whether the converter can currently accept a child node with the given type.

getDataContentFromText(text, [annotations]) → {Array.<ve.dm.LinearData.Item>}privatestatic #

Get linear model data from a string optionally applying annotations

Parameters:

Name Type Attributes Description
text string

Plain text to convert

annotations ve.dm.AnnotationSet optional

Annotations to apply

Source:

Returns:

Linear model data, one element per character

Type
Array.<ve.dm.LinearData.Item>
Get linear model data from a string optionally applying annotations

moveInlineMetaItems(data)privatestatic #

Modify linear model data in-place to move inline meta items out of content context

All branch node start items must have item.internal.metaItems = [] All inline meta items must have item.internal.isInlineMeta set to true

After the method completes, each inline meta item will be moved downward to the nearest legal block position (i.e. just after the close meta parent item), and has these properties: item.internal.loadMetaParentHash - corresponding meta parent's item.originalDomElementsHash item.internal.loadMetaParentOffset - offset at load time within the meta parent (0 for start). Each meta item is appended to the corresponding meta parent's item.internal.metaItems .

Parameters:

Name Type Description
data Array.<ve.dm.LinearData.Item>

Linear model data to modify in place

Source:

Modify linear model data in-place to move inline meta items out of content context

All branch node start items must have item.internal.metaItems = [] All inline meta items must have item.internal.isInlineMeta set to true

After the method completes, each inline meta item will be moved downward to the nearest legal block position (i.e.