@blocknote/core
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
75 lines (66 loc) • 1.93 kB
text/typescript
import { updateBlockCommand } from "../../api/blockManipulation/commands/updateBlock/updateBlock.js";
import { getBlockInfoFromSelection } from "../../api/getBlockInfoFromPos.js";
import {
createBlockSpecFromStronglyTypedTiptapNode,
createStronglyTypedTiptapNode,
} from "../../schema/index.js";
import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers.js";
import { defaultProps } from "../defaultProps.js";
export const paragraphPropSchema = {
...defaultProps,
};
export const ParagraphBlockContent = createStronglyTypedTiptapNode({
name: "paragraph",
content: "inline*",
group: "blockContent",
addKeyboardShortcuts() {
return {
"Mod-Alt-0": () => {
const blockInfo = getBlockInfoFromSelection(this.editor.state);
if (
!blockInfo.isBlockContainer ||
blockInfo.blockContent.node.type.spec.content !== "inline*"
) {
return true;
}
return this.editor.commands.command(
updateBlockCommand(this.options.editor, blockInfo.bnBlock.beforePos, {
type: "paragraph",
props: {},
})
);
},
};
},
parseHTML() {
return [
{ tag: "div[data-content-type=" + this.name + "]" },
{
tag: "p",
priority: 200,
getAttrs: (element) => {
if (typeof element === "string" || !element.textContent?.trim()) {
return false;
}
return {};
},
node: "paragraph",
},
];
},
renderHTML({ HTMLAttributes }) {
return createDefaultBlockDOMOutputSpec(
this.name,
"p",
{
...(this.options.domAttributes?.blockContent || {}),
...HTMLAttributes,
},
this.options.domAttributes?.inlineContent || {}
);
},
});
export const Paragraph = createBlockSpecFromStronglyTypedTiptapNode(
ParagraphBlockContent,
paragraphPropSchema
);