tinymce.Formatter
Text formatter engine class. This class is used to apply formats like bold, italic, font size etc to the current selection or specific nodes. This engine was built to replace the browser’s default formatting logic for execCommand due to its inconsistent and buggy behavior.
Examples
tinymce.activeEditor.formatter.register('mycustomformat', {
inline: 'span',
styles: {color: '#ff0000'}
});
tinymce.activeEditor.formatter.apply('mycustomformat');
Summary
Methods
Name | Summary | Defined by |
---|---|---|
Applies the specified format to the current selection or specified node. |
||
Returns true/false if the specified format can be applied to the current selection or not. It will currently only check the state for selector formats, it returns true on all other format types. |
||
Finds the closest matching format from a set of formats for the current selection. Added in TinyMCE 5.6 |
||
Executes the specified callback when the current selection matches the formats or not. |
||
Returns the format by name or all formats if no name is specified. |
||
Returns a preview css text for the specified format. |
||
Returns true or false if a format is registered for the specified name. |
||
Matches the current selection or specified node against the specified format name. |
||
Matches the current selection against the array of formats and returns a new array with matching formats. |
||
Return true/false if the specified node has the specified format. |
||
Registers a specific format by name. |
||
Removes the specified format from the current selection or specified node. |
||
Toggles the specified format on/off. |
||
Unregister a specific format by name. |
Methods
apply()
apply(name: String, vars: Object, node: Node)
Applies the specified format to the current selection or specified node.
canApply()
canApply(name: String): boolean
Returns true/false if the specified format can be applied to the current selection or not. It will currently only check the state for selector formats, it returns true on all other format types.
closest()
closest(names: Array): String
Finds the closest matching format from a set of formats for the current selection.
Added in TinyMCE 5.6
formatChanged()
formatChanged(formats: String, callback: function, similar: Boolean, vars: Object)
Executes the specified callback when the current selection matches the formats or not.
Parameters
-
formats (String)
- Comma separated list of formats to check for. -
callback (function)
- Callback with state and args when the format is changed/toggled on/off. -
similar (Boolean)
- True/false state if the match should handle similar or exact formats. -
vars (Object)
- Restrict the format being watched to only match if the variables applied are equal to vars.
get()
get(name: String): Array | Object
Returns the format by name or all formats if no name is specified.
getCssText()
getCssText(format: String | Object): String
Returns a preview css text for the specified format.
has()
has(name: String): boolean
Returns true or false if a format is registered for the specified name.
match()
match(name: String, vars: Object, node: Node, similar: Boolean): boolean
Matches the current selection or specified node against the specified format name.
matchAll()
matchAll(names: Array, vars: Object): Array
Matches the current selection against the array of formats and returns a new array with matching formats.
matchNode()
matchNode(node: Node, name: String, vars: Object, similar: Boolean): Object
Return true/false if the specified node has the specified format.
register()
register(name: Object | String, format: Object | Array)
Registers a specific format by name.
remove()
remove(name: String, vars: Object, node: Node | Range)
Removes the specified format from the current selection or specified node.