mirror of
https://github.com/Shadowfita/docmost.git
synced 2025-11-24 13:41:02 +10:00
18 lines
538 B
TypeScript
18 lines
538 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().parseFromString(html, 'text/html').body;
|
|
|
|
// @ts-ignore
|
|
return DOMParser.fromSchema(schema).parse(dom, options).toJSON();
|
|
}
|