From da9d62f79b82aa01ea17d4a71a38af5822459dec Mon Sep 17 00:00:00 2001 From: Aaron HS Date: Thu, 16 May 2024 09:45:47 +1000 Subject: [PATCH] Allow caller to supply parser options --- packages/html/src/generateJSON.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/html/src/generateJSON.ts b/packages/html/src/generateJSON.ts index babf983d9b..19c75f6504 100644 --- a/packages/html/src/generateJSON.ts +++ b/packages/html/src/generateJSON.ts @@ -1,11 +1,12 @@ import { Extensions, getSchema } from '@tiptap/core' -import { DOMParser } from '@tiptap/pm/model' +import { DOMParser, ParseOptions } from '@tiptap/pm/model' import { parseHTML } from 'zeed-dom' /** * Generates a JSON object from the given HTML string and converts it into a Prosemirror node with content. * @param {string} html - The HTML string to be converted into a Prosemirror node. * @param {Extensions} extensions - The extensions to be used for generating the schema. + * @param {ParseOptions} options - The options to be supplied to the parser. * @returns {Record} - The generated JSON object. * @example * const html = '

Hello, world!

' @@ -13,9 +14,9 @@ import { parseHTML } from 'zeed-dom' * const json = generateJSON(html, extensions) * console.log(json) // { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }] }] } */ -export function generateJSON(html: string, extensions: Extensions): Record { +export function generateJSON(html: string, extensions: Extensions, options?: ParseOptions): Record { const schema = getSchema(extensions) const dom = parseHTML(html) as unknown as Node - return DOMParser.fromSchema(schema).parse(dom).toJSON() + return DOMParser.fromSchema(schema).parse(dom, options).toJSON() }