Skip to the content
v1.0.1-beta.17

Moving from other editors

Documents saved by another editor load into Scriviamo through an importer add-on for that editor. Each is free and on its own, so an application loads only the ones it needs:

Add-onReadsWhat the other editor saves
editorjsEditor.jsThe JSON editor.save() returns: {time, blocks, version}
tiptapTipTap and ProseMirrorThe JSON editor.getJSON() or doc.toJSON() returns: {type: "doc", content}
quillQuillA Delta from quill.getContents(): {ops}, or the ops alone
lexicalLexicalThe editor state's JSON from editor.getEditorState().toJSON(): {root}
suneditorSunEditorThe HTML editor.getContents() returns
ckeditorCKEditor 5 and 4The HTML editor.getData() returns
import {Editor} from "scriviamo"
import {EditorJSImport} from "scriviamo/addons/editorjs"

let editor = new Editor(element)
EditorJSImport.load(editor, savedDocument)   // the JSON, as an object or as text
let json = editor.toJSON()                     // save it as Scriviamo's own from here on

Each add-on has the same four methods, on EditorJSImport, TipTapImport, QuillImport, LexicalImport, SunEditorImport and CKEditorImport:

MethodDoes
load(editor, data)Replaces the editor's document with the other editor's. False when data isn't one.
insert(editor, data, target?)Inserts it where the user is working, or after target
toHTML(data)The document as HTML, which editor.fromHTML loads
recognizes(data)True when data looks like that editor's, for telling saved documents apart

What comes across

Every importer brings over paragraphs, headings, bulleted, numbered and nested lists, checklists, quotes, code with its language, horizontal rules, tables (with header rows and merged cells), pictures with their captions, links, and text in bold, italic, underline, strikethrough and code. Where the other editor has them, highlights, colors, fonts and sizes, sub- and superscript, alignment, right-to-left text, formulas, mentions (as their text) and collapsible sections come too.

FromAlso
Editor.jsWarnings as alerts (with the callouts add-on), embeds, raw HTML, link and file blocks as links; a block type of your own through EditorJSImport.blocks
TipTap and ProseMirrorTask lists, YouTube and other frames, details, math; node types of your own through TipTapImport.nodes
QuillIndents as nested lists, checked and unchecked list items, image, video and formula embeds; embeds of your own through QuillImport.embeds
LexicalChecklists, equations, collapsible containers, YouTube videos; node types of your own through LexicalImport.nodes
SunEditorIts picture and video containers, tables, and lines saved as div elements
CKEditorTo-do lists as checklists, media as embeds, table captions as a paragraph after the table, formulas, highlight markers and font sizes

A video or other embedded frame becomes an embed block when the editor has the linkcards add-on. The importer turns a video page's address, such as a YouTube watch address, into its player's. Without that add-on, the frame becomes a link, so nothing is lost. Formulas need the math add-on and alerts the callouts add-on; without them, their text comes across as paragraphs.

What Scriviamo has no block for comes across as its text, or is left out when it has none, such as Lexical's page breaks. A numbered list that starts at a number other than 1 starts at 1.

Converting stored documents

To move an application's stored documents in one go, convert them on the server. toHTML works anywhere for the four editors that save JSON: Editor.js, TipTap and ProseMirror, Quill and Lexical. Loading the HTML into a headless editor needs a DOM, which Node doesn't have; give it one with a library such as linkedom, then save Scriviamo's JSON:

import {parseHTML} from "linkedom"
let {window} = parseHTML("<!doctype html><html><body></body></html>")
globalThis.DOMParser = window.DOMParser
globalThis.document = window.document

import {Editor} from "scriviamo"
import {QuillImport} from "scriviamo/addons/quill"

let editor = new Editor(null)
editor.fromHTML(QuillImport.toHTML(delta))
await database.save(id, editor.toJSON())

SunEditor and CKEditor save HTML, so their importers need the DOM for toHTML too. A schema can check the converted documents before they're saved.