Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | import type { Node } from '@tiptap/core';
import { type Extension, InputRule, type Mark } from '@tiptap/core';
import { Color } from '@tiptap/extension-color';
import { Highlight } from '@tiptap/extension-highlight';
import { HorizontalRule } from '@tiptap/extension-horizontal-rule';
import { TaskItem } from '@tiptap/extension-task-item';
import { TaskList } from '@tiptap/extension-task-list';
import { TextAlign } from '@tiptap/extension-text-align';
import { TextStyle } from '@tiptap/extension-text-style';
import { StarterKit } from '@tiptap/starter-kit';
import { Markdown } from 'tiptap-markdown';
import { JinjaHighlight } from './jinja-highlight';
export const defaultExtensions = (): (Extension | Node | Mark)[] => [
StarterKit.configure({
paragraph: {
HTMLAttributes: {
class: 'tiptap-paragraph',
},
},
bulletList: {
HTMLAttributes: {
class: 'list-disc list-outside leading-3 -mt-2',
},
},
orderedList: {
HTMLAttributes: {
class: 'list-decimal list-outside leading-3 -mt-2',
},
},
listItem: {
HTMLAttributes: {
class: 'leading-normal -mb-2',
},
},
blockquote: {
HTMLAttributes: {
class: 'border-l-4 border-stone-700',
},
},
codeBlock: {
HTMLAttributes: {
class:
'rounded-sm p-5 font-mono font-medium text-stone-800 whitespace-pre overflow-x-auto',
},
},
code: {
HTMLAttributes: {
class: 'rounded-md px-1.5 py-1 font-mono font-medium text-stone-900',
spellcheck: 'false',
},
},
horizontalRule: false,
dropcursor: {
color: '#DBEAFE',
width: 4,
},
gapcursor: false,
}),
// patch to fix horizontal rule bug: https://github.com/ueberdosis/tiptap/pull/3859#issuecomment-1536799740
HorizontalRule.extend({
addInputRules(): InputRule[] {
return [
new InputRule({
find: /^(?:---|—-|___\s|\*\*\*\s)$/,
handler: ({ state, range }): void => {
const attributes = {};
const { tr } = state;
const start = range.from;
const end = range.to;
tr.insert(start - 1, this.type.create(attributes)).delete(
tr.mapping.map(start),
tr.mapping.map(end),
);
},
}),
];
},
}).configure({
HTMLAttributes: {
class: 'mt-4 mb-6 border-t border-stone-300',
},
}),
TextStyle,
Color,
Highlight.configure({
multicolor: true,
}),
TaskList.configure({
HTMLAttributes: {
class: 'not-prose pl-0',
},
}),
TaskItem.configure({
HTMLAttributes: {
class: 'flex items-start my-4',
},
nested: true,
}),
TextAlign.configure({
types: ['heading', 'paragraph'],
}),
Markdown.configure({
html: true, // Allow HTML input/output
tightLists: true, // No <p> inside <li> in markdown output
tightListClass: 'tight', // Add class to <ul> allowing you to remove <p> margins when tight
bulletListMarker: '-', // <li> prefix in markdown output
linkify: true, // Create links from "https://..." text
breaks: false, // New lines (\n) in markdown input are converted to <br>
transformPastedText: true, // Allow to paste markdown text in the editor
transformCopiedText: false, // Copied text is transformed to markdown
}),
];
export const jinjaExtensions = (): (Extension | Node | Mark)[] => [
StarterKit.configure({
paragraph: {
HTMLAttributes: {
class: 'tiptap-paragraph',
},
},
bulletList: false, // Disable lists for system prompts
orderedList: false,
listItem: false,
blockquote: false, // Disable blockquotes for system prompts
horizontalRule: false,
heading: false, // Disable headings for system prompts
code: {
HTMLAttributes: {
class: 'rounded-md px-1.5 py-1 font-mono font-medium text-stone-900',
spellcheck: 'false',
},
},
codeBlock: false, // Disable code blocks for system prompts
dropcursor: {
color: '#DBEAFE',
width: 4,
},
gapcursor: false, // Keep consistent with existing config
}),
TextStyle,
JinjaHighlight.configure({
variableClass: 'jinja-variable',
blockClass: 'jinja-block',
commentClass: 'jinja-comment',
}),
];
|