The sections from the cursor's selection start to the selection end
The editor's instance of a post node builder.
Register a callback that will be run before toggleMarkup is applied.
If any callback returns literal false
, the toggling of markup will be canceled.
Note this only applies to calling editor#toggleMarkup
. Using editor.run
and
modifying markup with the postEditor
will skip any beforeToggleMarkup
callbacks.
Convenience for PostEditor#deleteAtPosition. Deletes and puts the cursor in the new position.
Inserts an atom at the current cursor position. If the editor has no current cursor position, nothing will be inserted. If the editor's range is not collapsed, it will be deleted before insertion.
The inserted atom.
Inserts a card at the section after the current cursor position. If the editor has no current cursor position, nothing will be inserted. If the editor's range is not collapsed, it will be deleted before insertion. If the cursor is in a blank section, it will be replaced with a card section. The editor's cursor will be placed at the end of the inserted card.
The inserted Card section.
Whether the card should be inserted in edit mode.
Called when the post has changed, either via user input or programmatically. Use with serialize to retrieve the post in portable mobiledoc format.
Run a new post editing session. Yields a block with a new PostEditor instance. This instance can be used to interact with the post abstract. Rendering will be deferred until after the callback is completed.
Usage:
let markerRange = this.range;
editor.run((postEditor) => {
postEditor.deleteRange(markerRange);
// editing surface not updated yet
postEditor.schedule(() => {
console.log('logs during rerender flush');
});
// logging not yet flushed
});
// editing surface now updated.
// logging now flushed
The return value of callback
.
Called with an instance of PostEditor as its argument.
Serialize the editor's post to the requested format. Note that only mobiledoc format is lossless. If cards or atoms are present in the post, the html and text formats will omit them in output because the editor does not have access to the html and text versions of the cards/atoms.
The editor's post, serialized to format
The format to serialize ('mobiledoc', 'text', 'html')
Toggles the given markup at the editor's current Range. If the range is collapsed this changes the editor's state so that the next characters typed will be affected. If there is text selected (aka a non-collapsed range), the selections' markup will be toggled. If the editor is not focused and has no active range, nothing happens. Hooks added using #beforeToggleMarkup will be run before toggling, and if any of them returns literal false, toggling the markup will be canceled and no change will be applied.
PostEditor#toggleMarkup
e.g. { href: "https://bdg.com" }
Toggles the tagName for the current active section(s). This will skip non-markerable sections. E.g. if the editor's range includes a "P" MarkupSection and a CardSection, only the MarkupSection will be toggled.
PostEditor#toggleSection
The new tagname to change to.
Generated using TypeDoc
The Editor is a core component of mobiledoc-kit. After instantiating an editor, use render to display the editor on the web page.
An editor uses a Post internally to represent the displayed document. The post can be serialized as mobiledoc using serialize. Mobiledoc is the transportable "over-the-wire" format (JSON) that is suited for persisting and sharing between editors and renderers (for display, e.g.), whereas the Post model is better suited for programmatic editing.
The editor will call registered callbacks for certain state changes. These are: