Files
outline/shared/editor/nodes/Blockquote.ts
2022-01-19 18:43:15 -08:00

59 lines
1.5 KiB
TypeScript

import { wrappingInputRule } from "prosemirror-inputrules";
import { NodeSpec, Node as ProsemirrorNode, NodeType } from "prosemirror-model";
import { EditorState, Transaction } from "prosemirror-state";
import toggleWrap from "../commands/toggleWrap";
import { MarkdownSerializerState } from "../lib/markdown/serializer";
import isNodeActive from "../queries/isNodeActive";
import Node from "./Node";
export default class Blockquote extends Node {
get name() {
return "blockquote";
}
get schema(): NodeSpec {
return {
content: "block+",
group: "block",
defining: true,
parseDOM: [{ tag: "blockquote" }],
toDOM: () => ["blockquote", 0],
};
}
inputRules({ type }: { type: NodeType }) {
return [wrappingInputRule(/^\s*>\s$/, type)];
}
commands({ type }: { type: NodeType }) {
return () => toggleWrap(type);
}
keys({ type }: { type: NodeType }) {
return {
"Ctrl->": toggleWrap(type),
"Mod-]": toggleWrap(type),
"Shift-Enter": (
state: EditorState,
dispatch: (tr: Transaction) => void
) => {
if (!isNodeActive(type)(state)) {
return false;
}
const { tr, selection } = state;
dispatch(tr.split(selection.to));
return true;
},
};
}
toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode) {
state.wrapBlock("> ", undefined, node, () => state.renderContent(node));
}
parseMarkdown() {
return { block: "blockquote" };
}
}