Skip to content

Commit

Permalink
feat: support notion block equation html import
Browse files Browse the repository at this point in the history
  • Loading branch information
donteatfriedrice committed Oct 10, 2024
1 parent 06309b9 commit 153ad51
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/blocks/src/__tests__/adapters/notion-html.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1730,4 +1730,44 @@ describe('notion html to snapshot', () => {
});
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
});

test('block equation', async () => {
const html = `<div class="page-body">
<figure id="11b088dd-6fdb-804f-8299-cc84de0b4909" class="equation">
<div class="equation-container">
<annotation encoding="application/x-tex">E = mc^2</annotation>
</div>
</figure>
</div>`;

const blockSnapshot: BlockSnapshot = {
type: 'block',
id: 'matchesReplaceMap[0]',
flavour: 'affine:note',
props: {
xywh: '[0,0,800,95]',
background: DEFAULT_NOTE_BACKGROUND_COLOR,
index: 'a0',
hidden: false,
displayMode: NoteDisplayMode.DocAndEdgeless,
},
children: [
{
type: 'block',
id: 'matchesReplaceMap[1]',
flavour: 'affine:latex',
props: {
latex: 'E = mc^2',
},
children: [],
},
],
};

const adapter = new NotionHtmlAdapter(createJob());
const rawBlockSnapshot = await adapter.toBlockSnapshot({
file: html,
});
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
});
});
22 changes: 22 additions & 0 deletions packages/blocks/src/_common/adapters/notion-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,28 @@ export class NotionHtmlAdapter extends BaseAdapter<NotionHtml> {
context.skipAllChildren();
break;
}
// Notion equation
if (hastQuerySelector(o.node, '.equation-container')) {
const latex = hastGetTextContent(
hastQuerySelector(o.node, 'annotation')
);
context
.openNode(
{
type: 'block',
id: nanoid(),
flavour: 'affine:latex',
props: {
latex,
},
children: [],
},
'children'
)
.closeNode();
context.skipAllChildren();
break;
}
// Notion callout
if (hastQuerySelector(o.node, '.callout')) {
context
Expand Down

0 comments on commit 153ad51

Please sign in to comment.