File
Blob: src/shared/editor/schema/callout.ts
| 1 | import { mergeAttributes, Node } from "@tiptap/core"; |
| 2 | import { DEFAULT_CALLOUT_KIND, normalizeCalloutKind } from "./callout-model"; |
| 3 | export { |
| 4 | CALLOUT_KINDS, |
| 5 | DEFAULT_CALLOUT_KIND, |
| 6 | isCalloutKind, |
| 7 | normalizeCalloutKind, |
| 8 | type CalloutKind, |
| 9 | } from "./callout-model"; |
| 10 | |
| 11 | export const SharedCalloutExtension = Node.create({ |
| 12 | name: "callout", |
| 13 | group: "block", |
| 14 | content: "block+", |
| 15 | defining: true, |
| 16 | isolating: true, |
| 17 | |
| 18 | addAttributes() { |
| 19 | return { |
| 20 | kind: { |
| 21 | default: DEFAULT_CALLOUT_KIND, |
| 22 | parseHTML: (element) => normalizeCalloutKind(element.getAttribute("data-callout-kind")), |
| 23 | renderHTML: (attributes) => ({ |
| 24 | "data-callout-kind": normalizeCalloutKind(attributes.kind), |
| 25 | }), |
| 26 | }, |
| 27 | }; |
| 28 | }, |
| 29 | |
| 30 | parseHTML() { |
| 31 | return [{ tag: "div[data-callout]" }]; |
| 32 | }, |
| 33 | |
| 34 | renderHTML({ HTMLAttributes }) { |
| 35 | return ["div", mergeAttributes(HTMLAttributes, { "data-callout": "", class: "tiptap-callout" }), 0]; |
| 36 | }, |
| 37 | }); |