tiptap: markdown support for flow

This commit is contained in:
fantasticit 2022-05-19 14:05:19 +08:00
parent 71d3a6342e
commit c8f37fecf9
5 changed files with 18 additions and 1 deletions

View File

@ -16,6 +16,7 @@ import { DocumentChildren } from 'tiptap/core/extensions/document-children';
import { DocumentReference } from 'tiptap/core/extensions/document-reference';
import { Dropcursor } from 'tiptap/core/extensions/dropcursor';
import { Emoji } from 'tiptap/core/extensions/emoji';
import { Flow } from 'tiptap/core/extensions/flow';
import { Focus } from 'tiptap/core/extensions/focus';
import { FontSize } from 'tiptap/core/extensions/font-size';
import { Gapcursor } from 'tiptap/core/extensions/gapcursor';
@ -130,4 +131,5 @@ export const AllExtensions = [
DocumentWithTitle,
Title,
Document,
Flow,
];

View File

@ -0,0 +1,9 @@
import { Node } from './node';
export class Flow extends Node {
type = 'flow';
matching() {
return this.DOMNode.nodeName === 'DIV' && this.DOMNode.classList.contains('flow');
}
}

View File

@ -17,6 +17,7 @@ import { CodeBlockWrapper } from './nodes/code-block-wrapper';
import { Countdown } from './nodes/countdown';
import { DocumentChildren } from './nodes/document-children';
import { DocumentReference } from './nodes/document-reference';
import { Flow } from './nodes/flow';
import { HardBreak } from './nodes/hard-break';
import { Heading } from './nodes/heading';
import { HorizontalRule } from './nodes/horizontal-rule';
@ -61,6 +62,7 @@ export class Renderer {
Mind,
DocumentChildren,
DocumentReference,
Flow,
CodeBlock,
CodeBlockWrapper,

View File

@ -21,6 +21,7 @@ const markdownDocumentChildren = createMarkdownContainer('documentChildren');
const markdownIframe = createMarkdownContainer('iframe');
const markdownMention = createMarkdownContainer('mention');
const markdownMind = createMarkdownContainer('mind');
const markdownFlow = createMarkdownContainer('flow');
const markdown = markdownit('commonmark')
.enable('strikethrough')
@ -42,7 +43,8 @@ const markdown = markdownit('commonmark')
.use(markdownMention)
.use(markdownMind)
.use(markdownDocumentReference)
.use(markdownDocumentChildren);
.use(markdownDocumentChildren)
.use(markdownFlow);
export const markdownToHTML = (rawMarkdown) => {
return sanitize(markdown.render(rawMarkdown), {});

View File

@ -9,6 +9,7 @@ import { CodeBlock } from 'tiptap/core/extensions/code-block';
import { Countdown } from 'tiptap/core/extensions/countdown';
import { DocumentChildren } from 'tiptap/core/extensions/document-children';
import { DocumentReference } from 'tiptap/core/extensions/document-reference';
import { Flow } from 'tiptap/core/extensions/flow';
import { HardBreak } from 'tiptap/core/extensions/hard-break';
import { Heading } from 'tiptap/core/extensions/heading';
import { HorizontalRule } from 'tiptap/core/extensions/horizontal-rule';
@ -125,6 +126,7 @@ const SerializerConfig = {
[Countdown.name]: renderCustomContainer('countdown'),
[DocumentChildren.name]: renderCustomContainer('documentChildren'),
[DocumentReference.name]: renderCustomContainer('documentReference'),
[Flow.name]: renderCustomContainer('flow'),
[HardBreak.name]: renderHardBreak,
[Heading.name]: defaultMarkdownSerializer.nodes.heading,
[HorizontalRule.name]: defaultMarkdownSerializer.nodes.horizontal_rule,