mirror of
https://github.com/docmost/docmost.git
synced 2026-05-15 05:04:06 +08:00
937a07059a
* page import feature * make file interceptor common * replace @tiptap/html * update tiptap version * reduce table margin * update tiptap version * switch to upstream drag handle lib (fixes table dragging) * WIP * Page import module and other fixes * working page imports * extract page title from h1 heading * finalize page imports * cleanup unused imports * add menu arrow
21 lines
557 B
TypeScript
21 lines
557 B
TypeScript
import { Extensions, getSchema } from '@tiptap/core';
|
|
import { DOMParser, ParseOptions } from '@tiptap/pm/model';
|
|
import { Window, DOMParser as HappyDomParser } from 'happy-dom';
|
|
|
|
export function generateJSON(
|
|
html: string,
|
|
extensions: Extensions,
|
|
options?: ParseOptions,
|
|
): Record<string, any> {
|
|
const schema = getSchema(extensions);
|
|
|
|
const window = new Window();
|
|
const dom = new HappyDomParser(window).parseFromString(
|
|
html,
|
|
'text/html',
|
|
).body;
|
|
|
|
// @ts-ignore
|
|
return DOMParser.fromSchema(schema).parse(dom, options).toJSON();
|
|
}
|