2023-02-03 00:37:33 +08:00
|
|
|
import { Node } from '@tiptap/pm/model'
|
2022-06-08 20:10:25 +08:00
|
|
|
|
2023-07-01 03:03:49 +08:00
|
|
|
import { Extensions, JSONContent } from '../types.js'
|
|
|
|
import { getHTMLFromFragment } from './getHTMLFromFragment.js'
|
|
|
|
import { getSchema } from './getSchema.js'
|
2020-09-03 22:22:08 +08:00
|
|
|
|
2024-05-14 00:28:53 +08:00
|
|
|
/**
|
|
|
|
* Generate HTML from a JSONContent
|
|
|
|
* @param doc The JSONContent to generate HTML from
|
|
|
|
* @param extensions The extensions to use for the schema
|
|
|
|
* @returns The generated HTML
|
|
|
|
*/
|
2021-12-06 19:00:09 +08:00
|
|
|
export function generateHTML(doc: JSONContent, extensions: Extensions): string {
|
2020-09-04 19:06:54 +08:00
|
|
|
const schema = getSchema(extensions)
|
|
|
|
const contentNode = Node.fromJSON(schema, doc)
|
2020-09-03 22:22:08 +08:00
|
|
|
|
2021-09-29 03:34:57 +08:00
|
|
|
return getHTMLFromFragment(contentNode.content, schema)
|
2020-09-03 22:22:08 +08:00
|
|
|
}
|