mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 10:45:57 +08:00
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { LatexBlockSchema } from '@blocksuite/affine-model';
|
|
import {
|
|
BlockNotionHtmlAdapterExtension,
|
|
type BlockNotionHtmlAdapterMatcher,
|
|
HastUtils,
|
|
} from '@blocksuite/affine-shared/adapters';
|
|
import { nanoid } from '@blocksuite/store';
|
|
|
|
export const latexBlockNotionHtmlAdapterMatcher: BlockNotionHtmlAdapterMatcher =
|
|
{
|
|
flavour: LatexBlockSchema.model.flavour,
|
|
toMatch: o => {
|
|
return (
|
|
HastUtils.isElement(o.node) &&
|
|
o.node.tagName === 'figure' &&
|
|
!!HastUtils.querySelector(o.node, '.equation-container')
|
|
);
|
|
},
|
|
fromMatch: () => false,
|
|
toBlockSnapshot: {
|
|
enter: (o, context) => {
|
|
if (!HastUtils.isElement(o.node)) {
|
|
return;
|
|
}
|
|
const { walkerContext } = context;
|
|
const latex = HastUtils.getTextContent(
|
|
HastUtils.querySelector(o.node, 'annotation')
|
|
);
|
|
walkerContext
|
|
.openNode(
|
|
{
|
|
type: 'block',
|
|
id: nanoid(),
|
|
flavour: LatexBlockSchema.model.flavour,
|
|
props: {
|
|
latex,
|
|
},
|
|
children: [],
|
|
},
|
|
'children'
|
|
)
|
|
.closeNode();
|
|
walkerContext.skipAllChildren();
|
|
},
|
|
},
|
|
fromBlockSnapshot: {},
|
|
};
|
|
|
|
export const LatexBlockNotionHtmlAdapterExtension =
|
|
BlockNotionHtmlAdapterExtension(latexBlockNotionHtmlAdapterMatcher);
|