|
| 1 | +/** |
| 2 | + * Server-safe extensions for generateHTML() - no React/DOM dependencies |
| 3 | + * Use this for server-side rendering of Tiptap content (e.g., article pages) |
| 4 | + * For the editor, use TiptapExtensions from index.tsx instead |
| 5 | + */ |
| 6 | +import StarterKit from "@tiptap/starter-kit"; |
| 7 | +import HorizontalRule from "@tiptap/extension-horizontal-rule"; |
| 8 | +import TiptapLink from "@tiptap/extension-link"; |
| 9 | +import Link from "@tiptap/extension-link"; |
| 10 | +import TextStyle from "@tiptap/extension-text-style"; |
| 11 | +import { Markdown } from "tiptap-markdown"; |
| 12 | +import { InputRule } from "@tiptap/core"; |
| 13 | +import UpdatedImage from "./updated-image"; |
| 14 | +import Document from "@tiptap/extension-document"; |
| 15 | +import Paragraph from "@tiptap/extension-paragraph"; |
| 16 | +import Text from "@tiptap/extension-text"; |
| 17 | +import Youtube from "@tiptap/extension-youtube"; |
| 18 | + |
| 19 | +const CustomDocument = Document.extend({ |
| 20 | + content: "heading block*", |
| 21 | +}); |
| 22 | + |
| 23 | +export const RenderExtensions = [ |
| 24 | + CustomDocument, |
| 25 | + Paragraph, |
| 26 | + Text, |
| 27 | + StarterKit.configure({ |
| 28 | + document: false, |
| 29 | + bulletList: { |
| 30 | + HTMLAttributes: { |
| 31 | + class: "list-disc list-outside leading-3 -mt-2", |
| 32 | + }, |
| 33 | + }, |
| 34 | + orderedList: { |
| 35 | + HTMLAttributes: { |
| 36 | + class: "list-decimal list-outside leading-3 -mt-2", |
| 37 | + }, |
| 38 | + }, |
| 39 | + listItem: { |
| 40 | + HTMLAttributes: { |
| 41 | + class: "leading-normal -mb-2", |
| 42 | + }, |
| 43 | + }, |
| 44 | + blockquote: { |
| 45 | + HTMLAttributes: { |
| 46 | + class: "border-l-4 border-stone-700", |
| 47 | + }, |
| 48 | + }, |
| 49 | + codeBlock: { |
| 50 | + HTMLAttributes: { |
| 51 | + class: |
| 52 | + "rounded-sm bg-stone-100 p-5 font-mono font-medium text-stone-800", |
| 53 | + }, |
| 54 | + }, |
| 55 | + code: { |
| 56 | + HTMLAttributes: { |
| 57 | + class: |
| 58 | + "rounded-md bg-stone-200 px-1.5 py-1 font-mono font-medium text-stone-900", |
| 59 | + spellcheck: "false", |
| 60 | + }, |
| 61 | + }, |
| 62 | + horizontalRule: false, |
| 63 | + dropcursor: { |
| 64 | + color: "#DBEAFE", |
| 65 | + width: 4, |
| 66 | + }, |
| 67 | + gapcursor: false, |
| 68 | + }), |
| 69 | + HorizontalRule.extend({ |
| 70 | + addInputRules() { |
| 71 | + return [ |
| 72 | + new InputRule({ |
| 73 | + find: /^(?:---|—-|___\s|\*\*\*\s)$/, |
| 74 | + handler: ({ state, range }) => { |
| 75 | + const { tr } = state; |
| 76 | + const start = range.from; |
| 77 | + const end = range.to; |
| 78 | + |
| 79 | + tr.insert(start - 1, this.type.create({})).delete( |
| 80 | + tr.mapping.map(start), |
| 81 | + tr.mapping.map(end), |
| 82 | + ); |
| 83 | + }, |
| 84 | + }), |
| 85 | + ]; |
| 86 | + }, |
| 87 | + }).configure({ |
| 88 | + HTMLAttributes: { |
| 89 | + class: "mt-4 mb-6 border-t border-stone-300", |
| 90 | + }, |
| 91 | + }), |
| 92 | + TiptapLink.configure({ |
| 93 | + HTMLAttributes: { |
| 94 | + class: |
| 95 | + "text-stone-400 underline underline-offset-[3px] hover:text-stone-600 transition-colors cursor-pointer", |
| 96 | + }, |
| 97 | + }), |
| 98 | + UpdatedImage.configure({ |
| 99 | + HTMLAttributes: { |
| 100 | + class: "rounded-lg border border-stone-200", |
| 101 | + }, |
| 102 | + }), |
| 103 | + TextStyle, |
| 104 | + Link.configure({ |
| 105 | + HTMLAttributes: { |
| 106 | + class: |
| 107 | + "text-stone-400 underline underline-offset-[3px] hover:text-stone-600 transition-colors cursor-pointer", |
| 108 | + }, |
| 109 | + }), |
| 110 | + Markdown.configure({ |
| 111 | + html: false, |
| 112 | + transformCopiedText: true, |
| 113 | + }), |
| 114 | + Youtube.configure({ |
| 115 | + width: 480, |
| 116 | + height: 320, |
| 117 | + allowFullscreen: true, |
| 118 | + }), |
| 119 | +]; |
0 commit comments