mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-22 20:41:50 +08:00
1f45cc5dec
**Directory Structure Changes** - Renamed multiple block-related directories by removing the "block-" prefix: - `block-attachment` → `attachment` - `block-bookmark` → `bookmark` - `block-callout` → `callout` - `block-code` → `code` - `block-data-view` → `data-view` - `block-database` → `database` - `block-divider` → `divider` - `block-edgeless-text` → `edgeless-text` - `block-embed` → `embed`
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { LatexBlockSchema } from '@blocksuite/affine-model';
|
|
import {
|
|
BlockMarkdownAdapterExtension,
|
|
type BlockMarkdownAdapterMatcher,
|
|
type MarkdownAST,
|
|
} from '@blocksuite/affine-shared/adapters';
|
|
import { nanoid } from '@blocksuite/store';
|
|
|
|
const isLatexNode = (node: MarkdownAST) => node.type === 'math';
|
|
|
|
export const latexBlockMarkdownAdapterMatcher: BlockMarkdownAdapterMatcher = {
|
|
flavour: LatexBlockSchema.model.flavour,
|
|
toMatch: o => isLatexNode(o.node),
|
|
fromMatch: o => o.node.flavour === LatexBlockSchema.model.flavour,
|
|
toBlockSnapshot: {
|
|
enter: (o, context) => {
|
|
const latex = 'value' in o.node ? o.node.value : '';
|
|
const { walkerContext } = context;
|
|
walkerContext
|
|
.openNode(
|
|
{
|
|
type: 'block',
|
|
id: nanoid(),
|
|
flavour: 'affine:latex',
|
|
props: {
|
|
latex,
|
|
},
|
|
children: [],
|
|
},
|
|
'children'
|
|
)
|
|
.closeNode();
|
|
},
|
|
},
|
|
fromBlockSnapshot: {
|
|
enter: (o, context) => {
|
|
const latex =
|
|
'latex' in o.node.props ? (o.node.props.latex as string) : '';
|
|
const { walkerContext } = context;
|
|
walkerContext
|
|
.openNode(
|
|
{
|
|
type: 'math',
|
|
value: latex,
|
|
},
|
|
'children'
|
|
)
|
|
.closeNode();
|
|
},
|
|
},
|
|
};
|
|
|
|
export const LatexBlockMarkdownAdapterExtension = BlockMarkdownAdapterExtension(
|
|
latexBlockMarkdownAdapterMatcher
|
|
);
|