mirror of
https://github.com/docmost/docmost.git
synced 2026-05-12 18:04:06 +08:00
6a3a7721be
* fix page import title bug * fix youtube embed in markdown export * add link to rendered file html * fix: markdown callout import * update local generateJSON * feat: switch spaces from sidebar * remove unused package * feat: editor date menu command * fix date description * update default locale code * feat: add more code highlight languages
22 lines
589 B
TypeScript
22 lines
589 B
TypeScript
import { Extensions, getSchema } from '@tiptap/core';
|
|
import { DOMParser, ParseOptions } from '@tiptap/pm/model';
|
|
import { Window } from 'happy-dom';
|
|
|
|
// this function does not work as intended
|
|
// it has issues with closing tags
|
|
export function generateJSON(
|
|
html: string,
|
|
extensions: Extensions,
|
|
options?: ParseOptions,
|
|
): Record<string, any> {
|
|
const schema = getSchema(extensions);
|
|
|
|
const window = new Window();
|
|
const document = window.document;
|
|
document.body.innerHTML = html;
|
|
|
|
return DOMParser.fromSchema(schema)
|
|
.parse(document as never, options)
|
|
.toJSON();
|
|
}
|