|
| 1 | +import { |
| 2 | + TiptapImage, |
| 3 | + TiptapLink, |
| 4 | + UpdatedImage, |
| 5 | + TaskList, |
| 6 | + TaskItem, |
| 7 | + HorizontalRule, |
| 8 | + StarterKit, |
| 9 | + Placeholder, |
| 10 | + AIHighlight, |
| 11 | + CodeBlockLowlight, |
| 12 | + Mathematics, |
| 13 | +} from "novel/extensions"; |
| 14 | +import { UploadImagesPlugin } from "novel/plugins"; |
| 15 | +import { cx } from "class-variance-authority"; |
| 16 | +import { all, createLowlight } from "lowlight"; |
| 17 | + |
| 18 | +const aiHighlight = AIHighlight; |
| 19 | +const placeholder = Placeholder; |
| 20 | +const tiptapLink = TiptapLink.configure({ |
| 21 | + HTMLAttributes: { |
| 22 | + class: cx( |
| 23 | + "text-muted-foreground underline underline-offset-[3px] hover:text-primary transition-colors cursor-pointer", |
| 24 | + ), |
| 25 | + }, |
| 26 | +}); |
| 27 | +const lowlight = createLowlight(all); |
| 28 | + |
| 29 | +const tiptapImage = TiptapImage.extend({ |
| 30 | + addProseMirrorPlugins() { |
| 31 | + return [ |
| 32 | + UploadImagesPlugin({ |
| 33 | + imageClass: cx("opacity-40 rounded-lg border border-stone-200"), |
| 34 | + }), |
| 35 | + ]; |
| 36 | + }, |
| 37 | +}).configure({ |
| 38 | + allowBase64: true, |
| 39 | + HTMLAttributes: { |
| 40 | + class: cx("rounded-lg border border-muted"), |
| 41 | + }, |
| 42 | +}); |
| 43 | + |
| 44 | +const updatedImage = UpdatedImage.configure({ |
| 45 | + HTMLAttributes: { |
| 46 | + class: cx("rounded-lg border border-muted"), |
| 47 | + }, |
| 48 | +}); |
| 49 | + |
| 50 | +const taskList = TaskList.configure({ |
| 51 | + HTMLAttributes: { |
| 52 | + class: cx("not-prose pl-2 "), |
| 53 | + }, |
| 54 | +}); |
| 55 | +const taskItem = TaskItem.configure({ |
| 56 | + HTMLAttributes: { |
| 57 | + class: cx("flex gap-2 items-start my-4"), |
| 58 | + }, |
| 59 | + nested: true, |
| 60 | +}); |
| 61 | + |
| 62 | +const horizontalRule = HorizontalRule.configure({ |
| 63 | + HTMLAttributes: { |
| 64 | + class: cx("mt-4 mb-6 border-t border-muted-foreground"), |
| 65 | + }, |
| 66 | +}); |
| 67 | + |
| 68 | +const starterKit = StarterKit.configure({ |
| 69 | + bulletList: { |
| 70 | + HTMLAttributes: { |
| 71 | + class: cx("list-disc list-outside leading-3 -mt-2"), |
| 72 | + }, |
| 73 | + }, |
| 74 | + orderedList: { |
| 75 | + HTMLAttributes: { |
| 76 | + class: cx("list-decimal list-outside leading-3 -mt-2"), |
| 77 | + }, |
| 78 | + }, |
| 79 | + listItem: { |
| 80 | + HTMLAttributes: { |
| 81 | + class: cx("leading-normal -mb-2"), |
| 82 | + }, |
| 83 | + }, |
| 84 | + blockquote: { |
| 85 | + HTMLAttributes: { |
| 86 | + class: cx("border-l-4 border-primary"), |
| 87 | + }, |
| 88 | + }, |
| 89 | + codeBlock: { |
| 90 | + HTMLAttributes: { |
| 91 | + class: cx( |
| 92 | + "rounded-md bg-muted text-muted-foreground border p-5 font-mono font-medium bg-slate-200", |
| 93 | + ), |
| 94 | + }, |
| 95 | + }, |
| 96 | + code: { |
| 97 | + HTMLAttributes: { |
| 98 | + class: cx("rounded-md bg-muted px-1.5 py-1 font-mono font-medium"), |
| 99 | + spellcheck: "false", |
| 100 | + }, |
| 101 | + }, |
| 102 | + paragraph: { |
| 103 | + HTMLAttributes: { |
| 104 | + class: cx(""), |
| 105 | + }, |
| 106 | + }, |
| 107 | + horizontalRule: false, |
| 108 | + dropcursor: { |
| 109 | + color: "#DBEAFE", |
| 110 | + width: 4, |
| 111 | + }, |
| 112 | + gapcursor: false, |
| 113 | +}); |
| 114 | + |
| 115 | +const codeBlockLowlight = CodeBlockLowlight.configure({ |
| 116 | + // configure lowlight: common / all / use highlightJS in case there is a need to specify certain language grammars only |
| 117 | + // common: covers 37 language grammars which should be good enough in most cases |
| 118 | + lowlight, |
| 119 | +}); |
| 120 | + |
| 121 | +const mathematics = Mathematics.configure({ |
| 122 | + HTMLAttributes: { |
| 123 | + class: cx("text-foreground rounded p-1 hover:bg-accent cursor-pointer"), |
| 124 | + }, |
| 125 | + katexOptions: { |
| 126 | + throwOnError: false, |
| 127 | + }, |
| 128 | +}); |
| 129 | +export const defaultExtensions = [ |
| 130 | + starterKit, |
| 131 | + placeholder, |
| 132 | + tiptapLink, |
| 133 | + tiptapImage, |
| 134 | + updatedImage, |
| 135 | + taskList, |
| 136 | + taskItem, |
| 137 | + horizontalRule, |
| 138 | + aiHighlight, |
| 139 | + codeBlockLowlight, |
| 140 | + mathematics, |
| 141 | +]; |
0 commit comments