Constructor
new ve.dm.Converter(modelRegistry, nodeFactory, annotationFactory)
#
DataModel converter.
Converts between HTML DOM and VisualEditor linear data.
Parameters:
Name | Type | Description |
---|---|---|
modelRegistry |
ve.dm.ModelRegistry | |
nodeFactory |
ve.dm.NodeFactory | |
annotationFactory |
ve.dm.AnnotationFactory |
- Source:
Properties
computedAttributes :Array.<string>static
#
List of HTML attribute names that {#renderHtmlAttributeList} should use computed values for.
Type:
- Array.<string>
- Source:
whitespaceList :RegExpstatic
#
Pattern matching 'white space characters' as defined by the HTML spec only.
All other whitespace should be treated as text, e.g. non-breaking spaces.
Type:
- Source:
Methods
canCloseWrapper() → {boolean|null
}
#
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
createDataElements(modelClass, domElements) → {Object|Array|null
}
#
null
}
#
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
doesModeNeedRendering() → {boolean}
#
Checks if the current mode needs a full view rendering in the HTML
- Source:
Returns:
Mode needs a rendering
- Type
- boolean
getActiveAnnotations() → {ve.dm.AnnotationSet|null
}
#
null
}
#
Get the annotations currently being applied by the converter. Note that this is specific to the current recursion level.
- Source:
Returns:
Annotation set, or null if not converting
- Type
-
ve.dm.AnnotationSet
|
null
getCurrentContext() → {Object|null
}
#
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
getDataFromDomClean(domElement, [wrapperElement], [annotationSet]) → {Array}
#
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
Wrapper for getDataFromDom which resets contextStack before the call and then set it back after the call.
getDataFromDomSubtree(domElement, [wrapperElement], [annotationSet]) → {Array}
#
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
getDomElementFromDataAnnotation(dataAnnotation, doc) → {HTMLElement}
#
Build an HTML DOM node for a linear model annotation.
Parameters:
Name | Type | Description |
---|---|---|
dataAnnotation |
Object | |
doc |
HTMLDocument | HTML document to create element with |
- Source:
Returns:
HTML DOM node
- Type
- HTMLElement
getDomElementsFromDataElement(dataElements, doc, [childDomElements]) → {Array.<Node>|boolean}
#
Get the DOM element for a given linear model element.
This invokes the toDomElements function registered for the element type.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dataElements |
Object | Array | Linear model element or data slice |
|
doc |
HTMLDocument | Document to create DOM elements in |
|
childDomElements |
Array.<Node> |
optional |
Array of child DOM elements to pass in (annotations only) |
- Source:
Returns:
DOM elements, or false if the element cannot be converted. If the first DOMelement has a 'handledOwnChildren' property set, the converter treats it as if it were a handlesOwnChildren node.
getDomFromModel(model, [mode]) → {HTMLDocument}
#
Convert document model to an HTML DOM
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
model |
ve.dm.Document | Document model |
||
mode |
number |
optional |
PARSER_MODE | Conversion mode, defaults to PARSER_MODE |
- Source:
Returns:
Document containing the resulting HTML
- Type
- HTMLDocument
getDomFromNode(node, [mode]) → {HTMLDocument}
#
Convert model node to an HTML DOM
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
node |
ve.dm.Node | Model node |
||
mode |
number |
optional |
PARSER_MODE | Conversion mode, defaults to PARSER_MODE |
- Source:
Returns:
Document containing the resulting HTML
- Type
- HTMLDocument
getDomSubtreeFromData(data, container, [innerWhitespace])
#
Convert linear model data to an HTML DOM subtree and add it to a container element.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Array | Linear model data |
|
container |
HTMLElement | DOM element to add the generated elements to. Should be empty. |
|
innerWhitespace |
Array.<(string|undefined)> |
optional |
Inner whitespace if the container is the body |
- Source:
Throws:
Unbalanced data: looking for closing /type
getDomSubtreeFromModel(model, container, [mode])
#
Convert document model to an HTML DOM subtree and add it to a container element.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
model |
ve.dm.Document | Document model |
||
container |
HTMLElement | DOM element to add the generated elements to. Should be empty. |
||
mode |
number |
optional |
PARSER_MODE | Conversion mode, defaults to PARSER_MODE |
- Source:
getHtmlDocument() → {HTMLDocument|null
}
#
null
}
#
Get the HTML document currently being converted
- Source:
Returns:
HTML document being converted, or null if not converting
- Type
-
HTMLDocument
|
null
getInnerWhitespace(data) → {Array.<(string|undefined)>}
#
Get inner whitespace from linear data
Parameters:
Name | Type | Description |
---|---|---|
data |
ve.dm.ElementLinearData | Linear model data |
- Source:
Returns:
Sparse array of whitespace strings: [ innerLeft, innerRight ]
- Type
- Array.<(string|undefined)>
getMode() → {number}
#
Get the converter mode, one of PARSER_MODE, CLIPBOARD_MODE or PREVIEW_MODE
- Source:
Returns:
Converter mode
- Type
- number
getModelFromDom(doc, [options], [store]) → {ve.dm.Document}
#
Convert an HTML document to a document model.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
doc |
HTMLDocument | HTML document to convert |
||||||||||||||||||||||||||
options |
Object |
optional |
Conversion options Properties:
|
|||||||||||||||||||||||||
store |
ve.dm.HashValueStore |
optional |
Hash value store |
- Source:
Returns:
Document model
- Type
- ve.dm.Document
getStore() → {ve.dm.HashValueStore|null
}
#
null
}
#
Get the HashValueStore used for the current conversion.
- Source:
Returns:
Current store, or null if not converting
- Type
-
ve.dm.HashValueStore
|
null
getTargetHtmlDocument() → {HTMLDocument|null
}
#
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
isConverting() → {boolean}
#
Check whether this converter instance is currently inside a getModelFromDom() conversion.
- Source:
Returns:
Whether we're converting
- Type
- boolean
isExpectingContent() → {boolean|null
}
#
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
isForClipboard() → {boolean}
#
Is the current conversion for the clipboard
- Source:
Returns:
The conversion is for the clipboard
- Type
- boolean
isForParser() → {boolean}
#
Is the current conversion for the parser
- Source:
Returns:
The conversion is for the paser
- Type
- boolean
isForPreview() → {boolean}
#
Is the current conversion for the preview
- Source:
Returns:
The conversion is for the preview
- Type
- boolean
isFromClipboard() → {boolean|null
}
#
null
}
#
Is the current conversion from the clipboard
- Source:
Returns:
The conversion is from the clipboard, or null if not converting
- Type
-
boolean
|
null
isInWrapper() → {boolean|null
}
#
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
isValidChildNodeType(nodeType) → {boolean|null
}
#
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
getDataContentFromText(text, [annotations]) → {Array}static
#
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
moveInlineMetaItems(data)static
#
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 | 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.
openAndCloseAnnotations(currentSet, targetSet, open, close)static
#
Utility function for annotation rendering. Transforms one set of annotations into another by opening and closing annotations. Each time an annotation is opened or closed, the associated callback is called with the annotation passed as a parameter.
Note that currentSet will be modified, and will be equal to targetSet once this function returns.
Parameters:
Name | Type | Description |
---|---|---|
currentSet |
ve.dm.AnnotationSet | The set of annotations currently opened. Will be modified. |
targetSet |
ve.dm.AnnotationSet | The set of annotations we want to have. |
open |
function | Callback called when an annotation is opened. Passed a |
close |
function | Callback called when an annotation is closed. Passed a |
- Source:
renderHtmlAttributeList(originalDomElements, targetDomElements, [filter], [computed], [deep])static
#
Copy attributes from one set of DOM elements to another.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
originalDomElements |
Array.<HTMLElement> | Array of DOM elements to render from |
||
targetDomElements |
Array.<HTMLElement> | Array of DOM elements to render onto |
||
filter |
boolean | function |
optional |
true | Attribute filter |
computed |
boolean |
optional |
false | If true, use the computed values of attributes where available |
deep |
boolean |
optional |
false | Recurse into child nodes |
- Source: