Files
AFFiNE-Mirror/blocksuite/affine/blocks/latex/src/adapters/markdown/markdown.ts
T
Saul-Mirone 1f45cc5dec refactor(editor): unify directories naming (#11516)
**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`
2025-04-07 12:34:40 +00:00

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
);