mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-22 04:21:40 +08:00
205cd7a86d
Closes: BS-2946
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
|
import { StdIdentifier } from '@blocksuite/std';
|
|
import { InlineSpecExtension } from '@blocksuite/std/inline';
|
|
import { html } from 'lit';
|
|
import { z } from 'zod';
|
|
|
|
export const LatexInlineSpecExtension =
|
|
InlineSpecExtension<AffineTextAttributes>('latex', provider => {
|
|
const std = provider.get(StdIdentifier);
|
|
return {
|
|
name: 'latex',
|
|
schema: z.string().optional().nullable().catch(undefined),
|
|
match: delta => typeof delta.attributes?.latex === 'string',
|
|
renderer: ({ delta, selected, editor, startOffset, endOffset }) => {
|
|
return html`<affine-latex-node
|
|
.std=${std}
|
|
.delta=${delta}
|
|
.selected=${selected}
|
|
.editor=${editor}
|
|
.startOffset=${startOffset}
|
|
.endOffset=${endOffset}
|
|
></affine-latex-node>`;
|
|
},
|
|
embed: true,
|
|
};
|
|
});
|
|
|
|
export const LatexEditorUnitSpecExtension =
|
|
InlineSpecExtension<AffineTextAttributes>({
|
|
name: 'latex-editor-unit',
|
|
schema: z.undefined(),
|
|
match: () => true,
|
|
renderer: ({ delta }) => {
|
|
return html`<latex-editor-unit .delta=${delta}></latex-editor-unit>`;
|
|
},
|
|
});
|