import type { Editor } from '@tiptap/react' import { parseContentEditorMathInput } from '@admin/utils/editor/parse-content-editor-math-input' export function insertContentEditorMath(editor: Editor | null, input: string): boolean { if (!editor?.isEditable) return false const math = parseContentEditorMathInput(input) if (!math) return false if (math.kind === 'display') { return editor .chain() .focus() .insertContent({ type: 'rawContentBlock', attrs: { kind: 'math', raw: math.markdown } }) .run() } return editor .chain() .focus() .insertContent({ type: 'inlineMath', attrs: { delimiter: math.delimiter ?? '$', raw: math.raw } }) .run() }