Skip to content
Snippets Groups Projects

Pass a Markdown serializer to the Content Editor

Merged Enrique Alcántara requested to merge content-editor-markdown-serializer into master
3 files
+ 47
3
Compare changes
  • Side-by-side
  • Inline
Files
3
import { isFunction } from 'lodash';
import { isFunction, isString } from 'lodash';
import { Editor } from 'tiptap';
import { Bold, Code } from 'tiptap-extensions';
import { PROVIDE_SERIALIZER_OR_RENDERER_ERROR } from '../constants';
import createMarkdownSerializer from './markdown_serializer';
const createEditor = async ({ content, renderMarkdown, serializer: customSerializer } = {}) => {
if (!customSerializer && !isFunction(renderMarkdown)) {
throw new Error('You have to provide a renderMarkdown function or a custom serializer');
throw new Error(PROVIDE_SERIALIZER_OR_RENDERER_ERROR);
}
const editor = new Editor({
@@ -23,0+24,0 @@
return serializer.serialize({ schema: editor.schema, content: editor.getJSON() });
};
await editor.setSerializedContent(content);
if (isString(content)) {
await editor.setSerializedContent(content);
}
return editor;
};
Loading