diff --git a/docs/content/docs/features/custom-schemas/custom-blocks.mdx b/docs/content/docs/features/custom-schemas/custom-blocks.mdx index bcad6e9dac..9fc766e87a 100644 --- a/docs/content/docs/features/custom-schemas/custom-blocks.mdx +++ b/docs/content/docs/features/custom-schemas/custom-blocks.mdx @@ -147,6 +147,7 @@ type ReactCustomBlockImplementation = { childrenRef: (node: HTMLElement | null) => void; context: { nestingLevel: number }; }>; + postProcessHTML?(context: HTMLExportContext): undefined; parse?: (element: HTMLElement) => PartialBlock["props"] | undefined; parseContent?: (options: { el: HTMLElement; @@ -201,6 +202,8 @@ type ReactCustomBlockImplementation = { on React Contexts._ +`postProcessHTML?:` A synchronous DOM callback for changes that need the assembled document, rather than one block's render output. It is available on both `createBlockSpec` and `createReactBlockSpec`. See [Post-processing Exported HTML](#post-processing-exported-html). + `parse?:` The `parse` function defines how to parse HTML content into your block, for example when pasting contents from the clipboard. If the element should be parsed into your custom block, you return the props that the block should be given. Otherwise, return `undefined`. Takes a single argument: - `element`: The HTML element that's being parsed. @@ -398,3 +401,24 @@ When the user moves the alert, its title and its body move together. set. See [Layout Blocks and Block Frames](/docs/features/custom-schemas/layout-blocks#layout-blocks-and-block-frames)._ + +## Post-processing Exported HTML + +Add `postProcessHTML` alongside `render` or `toExternalHTML` to adjust a block's HTML after the whole document has been rendered. This is useful when the result depends on other blocks, such as numbering list items. + +The callback runs once for each block type present in the export, for both `blocksToFullHTML` and `blocksToHTMLLossy`. It receives: + +- `root`: the whole exported document's DOM, which you can search with `querySelectorAll`. +- `blockOutputs`: a map from blocks of this type to their rendered output. Use `elements` to access their HTML elements, or `nodes` to include text and comments too. + +```ts +postProcessHTML({ blockOutputs }) { + for (const { elements } of blockOutputs.values()) { + for (const element of elements) { + element.setAttribute("data-exported", "true"); + } + } +} +``` + +Keep the callback synchronous and only change the exported DOM, not block data or editor state. For relationships between blocks, use DOM siblings and parents rather than map order. Since the two export methods can produce different HTML, only change elements that match the structure you need. diff --git a/packages/core/src/api/exporters/html/internalHTMLSerializer.ts b/packages/core/src/api/exporters/html/internalHTMLSerializer.ts index 05338f5f97..cdf06dbc0c 100644 --- a/packages/core/src/api/exporters/html/internalHTMLSerializer.ts +++ b/packages/core/src/api/exporters/html/internalHTMLSerializer.ts @@ -1,7 +1,6 @@ import { DOMSerializer, Schema } from "prosemirror-model"; import { PartialBlock } from "../../../blocks/defaultBlocks.js"; -import { EMPTY_CELL_WIDTH } from "../../../blocks/index.js"; import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js"; import { BlockSchema, @@ -10,131 +9,9 @@ import { } from "../../../schema/index.js"; import { serializeBlocksInternalHTML } from "./util/serializeBlocksInternalHTML.js"; -// This is normally handled using decorations in the -// `NumberedListIndexingDecorationPlugin`. This does not run when exporting, so -// we have to add the necessary HTML attributes ourselves. -const addIndexToNumberedListItems = (element: HTMLElement) => { - const numberedListItems = element.querySelectorAll( - '[data-content-type="numberedListItem"]', - ); - numberedListItems.forEach((numberedListItem) => { - const prevNumberedListItem = numberedListItem - .closest(".bn-block-outer") - ?.previousElementSibling?.querySelector( - '[data-content-type="numberedListItem"]', - ); - - if (!prevNumberedListItem) { - numberedListItem.setAttribute( - "data-index", - numberedListItem.getAttribute("data-start") || "1", - ); - } else { - const prevNumberedListItemIndex = - prevNumberedListItem.getAttribute("data-index"); - numberedListItem.setAttribute( - "data-index", - (parseInt(prevNumberedListItemIndex || "0") + 1).toString(), - ); - } - }); - - return element; -}; - -// Makes the checkboxes in check list items read-only, as the HTML should be -// static and therefore read-only when rendered. -const makeCheckListItemsReadOnly = (element: HTMLElement) => { - const checkboxes: NodeListOf = element.querySelectorAll( - '[data-content-type="checkListItem"] input', - ); - checkboxes.forEach((checkbox) => { - checkbox.disabled = true; - }); - - return element; -}; - -// Forces toggle blocks (toggle headings, toggle list items) to be expanded. -// This is because event listeners for the toggle button are lost when -// serializing HTML elements to a string, so the button no longer works if the -// HTML string is rendered out. -const forceToggleBlocksShow = (element: HTMLElement) => { - const closedToggleButtons = element.querySelectorAll( - '.bn-toggle-button[aria-expanded="false"]', - ); - closedToggleButtons.forEach((toggleButton) => { - toggleButton.setAttribute("aria-expanded", "true"); - }); - - return element; -}; - -// Adds minimum cell widths, which would normally be done by the -// `columnResizing` extension. This extension doesn't run when exporting to -// HTML, so we have to add this manually. -const addTableMinCellWidths = (element: HTMLElement) => { - const tables = element.querySelectorAll('[data-content-type="table"] table'); - tables.forEach((table) => { - table.setAttribute( - "style", - `--default-cell-min-width: ${EMPTY_CELL_WIDTH}px;`, - ); - table.setAttribute("data-show-children", "true"); - }); - - return element; -}; - -// Adds table wrapping elements, which would normally be done by the -// `columnResizing` extension. This extension doesn't run when exporting to -// HTML, so we have to add this manually. This adds the correct padding to -// tables. -const addTableWrappers = (element: HTMLElement) => { - const tables = element.querySelectorAll('[data-content-type="table"] table'); - tables.forEach((table) => { - const tableWrapper = document.createElement("div"); - tableWrapper.className = "tableWrapper"; - const tableWrapperInner = document.createElement("div"); - tableWrapperInner.className = "tableWrapper-inner"; - - tableWrapper.appendChild(tableWrapperInner); - table.parentElement?.appendChild(tableWrapper); - tableWrapper.appendChild(table); - }); - - return element; -}; - -// Adds trailing breaks to blocks with empty inline content. This is normally -// done by ProseMirror, but only when rendering an actual editor. Without them, -// empty inline content has a height of 0. -const addTrailingBreakToEmptyInlineContent = (element: HTMLElement) => { - const emptyInlineContent = element.querySelectorAll( - ".bn-inline-content:empty", - ); - emptyInlineContent.forEach((inlineContent) => { - // We actually use a `span` instead of a `br` to avoid potential false - // positives when parsing. - const trailingBreak = document.createElement("span"); - trailingBreak.className = "ProseMirror-trailingBreak"; - trailingBreak.setAttribute("style", "display: inline-block;"); - - inlineContent.appendChild(trailingBreak); - }); - - return element; -}; - -// Used to serialize BlockNote blocks and ProseMirror nodes to HTML without -// losing data. Blocks are exported using the `toInternalHTML` method in their -// `blockSpec`. -// -// The HTML created by this serializer is the same as what's rendered by the -// editor to the DOM. This means that it retains the same structure as the -// editor, including the `blockGroup` and `blockContainer` wrappers. This also -// means that it can be converted back to the original blocks without any data -// loss. +// Serializes to the editor's HTML structure, retaining blockGroup and +// blockContainer wrappers so the document can be parsed back without data loss. +// Block-owned post-processing is part of the shared serialization pipeline. export const createInternalHTMLSerializer = < BSchema extends BlockSchema, I extends InlineContentSchema, @@ -145,38 +22,12 @@ export const createInternalHTMLSerializer = < ) => { const serializer = DOMSerializer.fromSchema(schema); - // Set of transforms to run on the output HTML element after serializing - // blocks. These are used to add HTML elements, attributes, or class names - // which would normally be done by extensions and plugins. Since these don't - // run when converting blocks to HTML, tranforms are used to mock their - // functionality so that the rendered HTML looks identical to that of a live - // editor. - const transforms: ((element: HTMLElement) => HTMLElement)[] = [ - addIndexToNumberedListItems, - makeCheckListItemsReadOnly, - forceToggleBlocksShow, - addTableMinCellWidths, - addTableWrappers, - addTrailingBreakToEmptyInlineContent, - ]; - return { serializeBlocks: ( blocks: PartialBlock[], options: { document?: Document }, - ) => { - let element = serializeBlocksInternalHTML( - editor, - blocks, - serializer, - options, - ); - - for (const transform of transforms) { - element = transform(element); - } - - return element.outerHTML; - }, + ) => + serializeBlocksInternalHTML(editor, blocks, serializer, options) + .outerHTML, }; }; diff --git a/packages/core/src/api/exporters/html/postProcessHTML.browser.test.tsx b/packages/core/src/api/exporters/html/postProcessHTML.browser.test.tsx new file mode 100644 index 0000000000..870b2b2051 --- /dev/null +++ b/packages/core/src/api/exporters/html/postProcessHTML.browser.test.tsx @@ -0,0 +1,411 @@ +import { createElement } from "react"; +import { createReactBlockSpec } from "@blocknote/react"; +import { expect, test, vi } from "vite-plus/test"; + +import { + BlockNoteSchema, + defaultBlockSpecs, + BlockNoteEditor, + createBlockSpec, +} from "@blocknote/core"; + +function parseHTML(html: string) { + const container = document.createElement("div"); + container.innerHTML = html; + return container; +} + +for (const html of [ + "text", + "text", + "text", + "", +]) { + test(`external: preserves fallback fragment roots ${JSON.stringify(html)}`, () => { + let calls = 0; + const fragment = createBlockSpec( + { type: "fragment", propSchema: {}, content: "none" }, + { + render() { + const template = document.createElement("template"); + template.innerHTML = html; + return { dom: template.content }; + }, + postProcessHTML({ root, blockOutputs }) { + calls++; + expect(blockOutputs.size).toBe(1); + const output = Array.from(blockOutputs.values())[0]; + const expected = parseHTML(html); + expect(output.nodes.map((node) => node.nodeType)).toEqual( + Array.from(expected.childNodes, (node) => node.nodeType), + ); + expect(output.elements.length).toBe(expected.children.length); + expect(Array.from(root.childNodes)).toEqual(output.nodes); + }, + }, + )(); + const editor = BlockNoteEditor.create({ + schema: BlockNoteSchema.create({ + blockSpecs: { ...defaultBlockSpecs, fragment }, + }), + }); + + expect(editor.blocksToHTMLLossy([{ type: "fragment" }])).toBe(html); + expect(calls).toBe(1); + }); +} + +for (const format of ["internal", "external"] as const) { + test(`${format}: layout slots, fallback frames and explicit external renderers`, () => { + const calls: string[] = []; + const framed = createBlockSpec( + { type: "framed", propSchema: {}, content: "inline" }, + { + render() { + const dom = document.createElement("p"); + return { dom, contentDOM: dom }; + }, + renderFrame() { + const dom = document.createElement("aside"); + return { dom, slot: dom }; + }, + postProcessHTML({ blockOutputs }) { + calls.push("framed"); + expect(blockOutputs.size).toBe(1); + for (const { nodes } of blockOutputs.values()) { + const root = nodes[0]; + expect(root instanceof Element).toBe(true); + expect(root.textContent).toContain("nested-child"); + expect(root.getRootNode().textContent).toContain("after-panel"); + if (root instanceof Element) { + const frame = root.matches("aside") + ? root + : root.querySelector("aside"); + expect(frame).not.toBeNull(); + frame?.setAttribute("data-frame-finalized", "true"); + } + } + }, + }, + )(); + const panel = createBlockSpec( + { type: "panel", propSchema: {}, content: "none", layoutOnly: true }, + { + renderFrame() { + const dom = document.createElement("section"); + return { dom, slot: dom }; + }, + toExternalHTML() { + const dom = document.createElement("article"); + return { dom, childrenDOM: dom }; + }, + postProcessHTML({ blockOutputs }) { + calls.push("panel"); + for (const { nodes } of blockOutputs.values()) { + expect(nodes).toHaveLength(1); + expect(nodes[0].nodeName).toBe( + format === "internal" ? "SECTION" : "ARTICLE", + ); + expect(nodes[0].textContent).toContain("nested-child"); + } + }, + }, + )(); + const editor = BlockNoteEditor.create({ + schema: BlockNoteSchema.create({ + blockSpecs: { ...defaultBlockSpecs, panel, framed }, + }), + }); + try { + const blocks = [ + { + type: "panel" as const, + children: [ + { + type: "framed" as const, + content: "framed-content", + children: [ + { type: "paragraph" as const, content: "nested-child" }, + ], + }, + ], + }, + { type: "paragraph" as const, content: "after-panel" }, + ]; + const html = + format === "internal" + ? editor.blocksToFullHTML(blocks) + : editor.blocksToHTMLLossy(blocks); + expect( + parseHTML(html).querySelector("aside[data-frame-finalized]"), + ).not.toBeNull(); + expect(calls.sort()).toEqual(["framed", "panel"]); + } finally { + editor._tiptapEditor.destroy(); + } + }); + + test(`${format}: one batch after assembly, with render identities and surviving roots`, () => { + const rendered = new Set(); + const batches: number[] = []; + const unusedHook = vi.fn(); + const spec = createBlockSpec( + { + type: "batch", + propSchema: { label: { default: "default-label" } }, + content: "none", + }, + { + render(block) { + rendered.add(block); + const dom = document.createDocumentFragment(); + const label = document.createElement("label"); + label.textContent = block.props.label; + const emptyInlineContent = document.createElement("span"); + emptyInlineContent.className = "bn-inline-content"; + label.appendChild(emptyInlineContent); + dom.append( + label, + "text-root", + document.createComment("comment-root"), + ); + return { dom }; + }, + postProcessHTML({ blockOutputs, root }) { + batches.push(blockOutputs.size); + expect(rendered.size).toBe(3); + expect(root.nodeType).toBe( + format === "internal" + ? Node.ELEMENT_NODE + : Node.DOCUMENT_FRAGMENT_NODE, + ); + expect(root.querySelector("p")?.textContent).toBe( + "following-sibling", + ); + for (const [block, output] of blockOutputs) { + const { nodes, elements } = output; + expect(elements).toHaveLength(1); + expect(elements[0]).toBe(nodes[0]); + expect(output.elements).toBe(elements); + expect(rendered.has(block)).toBe(true); + expect(block.props?.label).toBe("default-label"); + expect(nodes).toHaveLength(format === "external" ? 3 : 1); + for (const node of nodes) { + expect(node.nodeType).not.toBe(Node.DOCUMENT_FRAGMENT_NODE); + expect(node.getRootNode()).toBe(root); + // All parents, descendants and following siblings already exist. + expect(node.getRootNode().textContent).toContain( + "following-sibling", + ); + if (node instanceof Element) { + node.setAttribute("data-finalized", format); + } + } + } + root.appendChild(document.createComment("export-root-finalized")); + }, + }, + )(); + const unused = createBlockSpec( + { type: "unused", propSchema: {}, content: "none" }, + { + render() { + return { dom: document.createElement("div") }; + }, + postProcessHTML: unusedHook, + }, + )(); + const editor = BlockNoteEditor.create({ + schema: BlockNoteSchema.create({ + blockSpecs: { ...defaultBlockSpecs, batch: spec, unused }, + }), + }); + const props = Object.freeze({}); + const blocks = [ + { type: "batch" as const, props, children: [{ type: "batch" as const }] }, + { type: "batch" as const }, + { type: "paragraph" as const, content: "following-sibling" }, + ]; + try { + for (let i = 0; i < 2; i++) { + rendered.clear(); + const html = + format === "internal" + ? editor.blocksToFullHTML(blocks) + : editor.blocksToHTMLLossy(blocks); + expect( + parseHTML(html).querySelectorAll("[data-finalized]"), + ).toHaveLength(3); + expect(html).toContain(""); + if (format === "external") { + expect( + parseHTML(html).querySelector(".ProseMirror-trailingBreak"), + ).toBeNull(); + } + } + expect(batches).toEqual([3, 3]); + expect(props).toEqual({}); + expect(unusedHook).not.toHaveBeenCalled(); + } finally { + editor._tiptapEditor.destroy(); + } + }); + + test(`${format}: React block specs retain the DOM hook`, () => { + let calls = 0; + const spec = createReactBlockSpec( + { type: "reactBatch", propSchema: {}, content: "none" }, + { + render() { + return createElement("span", null, "React output"); + }, + postProcessHTML({ blockOutputs, root }) { + calls++; + expect(blockOutputs.size).toBe(1); + expect(root.textContent).toContain("React output"); + for (const { nodes } of blockOutputs.values()) { + for (const node of nodes) { + expect(node.getRootNode()).toBe(root); + if (node instanceof Element) { + node.setAttribute("data-react-finalized", "true"); + } + } + } + }, + }, + )(); + const editor = BlockNoteEditor.create({ + schema: BlockNoteSchema.create({ + blockSpecs: { ...defaultBlockSpecs, reactBatch: spec }, + }), + }); + try { + const blocks = [{ type: "reactBatch" as const }]; + const html = + format === "internal" + ? editor.blocksToFullHTML(blocks) + : editor.blocksToHTMLLossy(blocks); + expect(calls).toBe(1); + expect( + parseHTML(html).querySelector("[data-react-finalized]"), + ).not.toBeNull(); + } finally { + editor._tiptapEditor.destroy(); + } + }); +} + +test("built-in finalization restores empty inline content after block hooks", () => { + const cleared = createBlockSpec( + { type: "cleared", propSchema: {}, content: "inline" }, + { + render() { + const dom = document.createElement("p"); + return { dom, contentDOM: dom }; + }, + postProcessHTML({ blockOutputs }) { + for (const { nodes } of blockOutputs.values()) { + for (const node of nodes) { + if (node instanceof Element) { + node.querySelector(".bn-inline-content")?.replaceChildren(); + } + } + } + }, + }, + )(); + const editor = BlockNoteEditor.create({ + schema: BlockNoteSchema.create({ + blockSpecs: { ...defaultBlockSpecs, cleared }, + }), + }); + try { + const html = editor.blocksToFullHTML([ + { type: "cleared", content: "cleared by hook" }, + ]); + expect( + parseHTML(html).querySelector( + ".bn-inline-content > .ProseMirror-trailingBreak", + ), + ).not.toBeNull(); + } finally { + editor._tiptapEditor.destroy(); + } +}); + +test("numbering uses immediate siblings, independent of nested groups", () => { + const editor = BlockNoteEditor.create(); + try { + const html = editor.blocksToFullHTML([ + { + type: "numberedListItem", + props: { start: 4 }, + children: [{ type: "numberedListItem", props: { start: 20 } }], + }, + { type: "numberedListItem" }, + { + type: "paragraph", + children: [{ type: "numberedListItem", props: { start: 30 } }], + }, + { type: "numberedListItem", props: { start: 7 } }, + { type: "numberedListItem", props: { start: 99 } }, + ]); + expect( + Array.from( + parseHTML(html).querySelectorAll( + '[data-content-type="numberedListItem"]', + ), + (element) => element.getAttribute("data-index"), + ), + ).toEqual(["4", "20", "5", "30", "7", "8"]); + } finally { + editor._tiptapEditor.destroy(); + } +}); + +test("static built-ins preserve internal and external behavior", () => { + const editor = BlockNoteEditor.create(); + try { + const blocks = [ + { type: "checkListItem" as const, props: { checked: true } }, + { type: "toggleListItem" as const }, + { type: "heading" as const, props: { isToggleable: true } }, + { + type: "table" as const, + content: { type: "tableContent" as const, rows: [{ cells: [""] }] }, + }, + { type: "paragraph" as const }, + { type: "numberedListItem" as const }, + { type: "numberedListItem" as const }, + ]; + const internal = parseHTML(editor.blocksToFullHTML(blocks)); + expect(internal.querySelector("input")?.disabled).toBe(true); + expect( + internal.querySelectorAll('.bn-toggle-button[aria-expanded="true"]'), + ).toHaveLength(2); + expect(internal.querySelector(".tableWrapper-inner")).not.toBeNull(); + expect( + internal + .querySelector("table") + ?.style.getPropertyValue("--default-cell-min-width"), + ).not.toBe(""); + expect( + internal.querySelectorAll(".ProseMirror-trailingBreak").length, + ).toBeGreaterThan(0); + + const external = parseHTML(editor.blocksToHTMLLossy(blocks)); + expect(external.querySelector("input")?.disabled).toBe(false); + expect(external.querySelectorAll("details[open]")).toHaveLength(2); + expect(external.querySelector(".tableWrapper")).toBeNull(); + expect( + external + .querySelector("table") + ?.style.getPropertyValue("--default-cell-min-width"), + ).toBe(""); + expect(external.querySelector("[data-index]")).toBeNull(); + expect(external.querySelectorAll("ol > li")).toHaveLength(2); + expect(external.querySelector(".ProseMirror-trailingBreak")).toBeNull(); + } finally { + editor._tiptapEditor.destroy(); + } +}); diff --git a/packages/core/src/api/exporters/html/util/HTMLExportSession.test.ts b/packages/core/src/api/exporters/html/util/HTMLExportSession.test.ts new file mode 100644 index 0000000000..56d804e775 --- /dev/null +++ b/packages/core/src/api/exporters/html/util/HTMLExportSession.test.ts @@ -0,0 +1,19 @@ +// @vitest-environment node +import { expect, test, vi } from "vite-plus/test"; + +import { createHTMLExportOutput } from "./HTMLExportSession.js"; + +test("element roots are allocated lazily and cached, including empty results", () => { + const nodes: Node[] = []; + const filter = vi.spyOn(nodes, "filter"); + const output = createHTMLExportOutput(nodes); + + expect(output.nodes).toBe(nodes); + expect(filter).not.toHaveBeenCalled(); + + const elements = output.elements; + expect(elements).toEqual([]); + expect(filter).toHaveBeenCalledTimes(1); + expect(output.elements).toBe(elements); + expect(filter).toHaveBeenCalledTimes(1); +}); diff --git a/packages/core/src/api/exporters/html/util/HTMLExportSession.ts b/packages/core/src/api/exporters/html/util/HTMLExportSession.ts new file mode 100644 index 0000000000..4317b3b4b5 --- /dev/null +++ b/packages/core/src/api/exporters/html/util/HTMLExportSession.ts @@ -0,0 +1,52 @@ +import type { + BlockSpecs, + HTMLExportBlock, + HTMLExportOutput, +} from "../../../../schema/index.js"; +import { postProcessBuiltInHTML } from "./postProcessBuiltInHTML.js"; + +export function createHTMLExportOutput( + nodes: readonly globalThis.Node[], +): HTMLExportOutput { + let elements: readonly Element[] | undefined; + return { + nodes, + get elements() { + // Avoid browser globals so this also works during SSR and across realms. + return (elements ??= nodes.filter( + (node): node is Element => node.nodeType === 1, + )); + }, + }; +} + +/** One registry for a whole export, shared by every recursive serializer call. */ +export class HTMLExportSession { + private readonly outputs = new Map< + string, + Map + >(); + + record( + type: string, + block: HTMLExportBlock, + nodes: readonly globalThis.Node[], + ) { + let blockOutputs = this.outputs.get(type); + if (!blockOutputs) { + blockOutputs = new Map(); + this.outputs.set(type, blockOutputs); + } + blockOutputs.set(block, createHTMLExportOutput(nodes)); + } + + run(specs: BlockSpecs, root: globalThis.Node & ParentNode) { + for (const [type, { implementation }] of Object.entries(specs)) { + const blockOutputs = this.outputs.get(type); + if (blockOutputs) { + implementation.postProcessHTML?.({ root, blockOutputs }); + } + } + postProcessBuiltInHTML(root); + } +} diff --git a/packages/core/src/api/exporters/html/util/postProcessBuiltInHTML.ts b/packages/core/src/api/exporters/html/util/postProcessBuiltInHTML.ts new file mode 100644 index 0000000000..89b42057fa --- /dev/null +++ b/packages/core/src/api/exporters/html/util/postProcessBuiltInHTML.ts @@ -0,0 +1,13 @@ +/** Framework-wide normalization, after block-owned hooks have finalized the DOM. */ +export function postProcessBuiltInHTML(dom: ParentNode) { + // ProseMirror adds these only in a live view. Preserve the height of empty + // inline content, including custom blocks and paragraphs inside table cells. + for (const inlineContent of dom.querySelectorAll( + ".bn-block-content .bn-inline-content:empty", + )) { + const trailingBreak = inlineContent.ownerDocument.createElement("span"); + trailingBreak.className = "ProseMirror-trailingBreak"; + trailingBreak.setAttribute("style", "display: inline-block;"); + inlineContent.appendChild(trailingBreak); + } +} diff --git a/packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts b/packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts index 0a267d1b43..2c0f68c7c4 100644 --- a/packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +++ b/packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts @@ -20,6 +20,7 @@ import { tableContentToNodes, } from "../../../nodeConversions/blockToNode.js"; import { nodeToCustomInlineContent } from "../../../nodeConversions/nodeToBlock.js"; +import { HTMLExportSession } from "./HTMLExportSession.js"; /** * Placeholder character inserted into empty inline-content blocks when @@ -35,7 +36,7 @@ import { nodeToCustomInlineContent } from "../../../nodeConversions/nodeToBlock. */ export const EMPTY_BLOCK_PLACEHOLDER = ""; -function addAttributesAndRemoveClasses(element: HTMLElement) { +function addAttributesAndRemoveClasses(element: Element) { // Removes all BlockNote specific class names. const className = Array.from(element.classList).filter( @@ -245,13 +246,14 @@ function serializeBlock< orderedListItemBlockTypes: Set, unorderedListItemBlockTypes: Set, nestingLevel: number, + session: HTMLExportSession, options?: { document?: Document }, ) { const doc = options?.document ?? document; const BC_NODE = editor.pmSchema.nodes["blockContainer"]; // set default props in case we were passed a partial block - const props = block.props || {}; + const props = { ...block.props }; for (const [name, spec] of Object.entries( editor.schema.blockSchema[block.type as any].propSchema, )) { @@ -308,19 +310,19 @@ function serializeBlock< attr.name !== "data-editable", ); - for (const attr of blockContentDataAttributes) { - (rootElement.firstChild! as HTMLElement).setAttribute( - attr.name, - attr.value, - ); - } + const firstElement = rootElement.firstElementChild; + if (firstElement) { + for (const attr of blockContentDataAttributes) { + firstElement.setAttribute(attr.name, attr.value); + } - addAttributesAndRemoveClasses(rootElement.firstChild! as HTMLElement); - if (nestingLevel > 0) { - (rootElement.firstChild! as HTMLElement).setAttribute( - "data-nesting-level", - nestingLevel.toString(), - ); + addAttributesAndRemoveClasses(firstElement); + if (nestingLevel > 0) { + firstElement.setAttribute( + "data-nesting-level", + nestingLevel.toString(), + ); + } } elementFragment.append(...Array.from(rootElement.childNodes)); } else { @@ -383,6 +385,10 @@ function serializeBlock< childrenDOM = frame.slot; } + // Capture roots before appending consumes the fragment. Record after all + // children have been assembled; hooks run only at the top-level boundary. + const outputNodes = Array.from(elementFragment.childNodes); + let listType = undefined; if (orderedListItemBlockTypes.has(block.type!)) { listType = "OL"; @@ -420,6 +426,7 @@ function serializeBlock< orderedListItemBlockTypes, unorderedListItemBlockTypes, nestingLevel + 1, + session, options, ); if ( @@ -451,6 +458,7 @@ function serializeBlock< ret.contentDOM.append(childFragment); } } + session.record(block.type!, blockWithDefaults, outputNodes); } const serializeBlocksToFragment = < @@ -464,7 +472,8 @@ const serializeBlocksToFragment = < serializer: DOMSerializer, orderedListItemBlockTypes: Set, unorderedListItemBlockTypes: Set, - nestingLevel = 0, + nestingLevel: number, + session: HTMLExportSession, options?: { document?: Document }, ) => { for (const block of blocks) { @@ -476,6 +485,7 @@ const serializeBlocksToFragment = < orderedListItemBlockTypes, unorderedListItemBlockTypes, nestingLevel, + session, options, ); } @@ -496,6 +506,8 @@ export const serializeBlocksExternalHTML = < const doc = options?.document ?? document; const fragment = doc.createDocumentFragment(); + const session = new HTMLExportSession(); + serializeBlocksToFragment( fragment, editor, @@ -504,7 +516,9 @@ export const serializeBlocksExternalHTML = < orderedListItemBlockTypes, unorderedListItemBlockTypes, 0, + session, options, ); + session.run(editor.blockImplementations, fragment); return fragment; }; diff --git a/packages/core/src/api/exporters/html/util/serializeBlocksInternalHTML.ts b/packages/core/src/api/exporters/html/util/serializeBlocksInternalHTML.ts index 3a5ed1e357..f3443259d8 100644 --- a/packages/core/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +++ b/packages/core/src/api/exporters/html/util/serializeBlocksInternalHTML.ts @@ -20,6 +20,7 @@ import { markFrameSlot, renderFrameDOM, } from "../../../../schema/blocks/frame.js"; +import { HTMLExportSession } from "./HTMLExportSession.js"; export function serializeInlineContentInternalHTML< BSchema extends BlockSchema, I extends InlineContentSchema, @@ -140,12 +141,13 @@ function serializeBlock< editor: BlockNoteEditor, block: PartialBlock, serializer: DOMSerializer, + session: HTMLExportSession, options?: { document?: Document }, ) { const BC_NODE = editor.pmSchema.nodes["blockContainer"]; - // set default props in case we were passed a partial block - const props = block.props || {}; + // Fill defaults on a copy, without mutating caller-owned (possibly frozen) props. + const props = { ...block.props }; for (const [name, spec] of Object.entries( editor.schema.blockSchema[block.type as any].propSchema, )) { @@ -170,8 +172,11 @@ function serializeBlock< ); } if (children.length > 0) { - frame.slot.append(serializeBlocks(editor, children, serializer, options)); + frame.slot.append( + serializeBlocks(editor, children, serializer, session, options), + ); } + session.record(block.type!, fullBlock, [frame.dom]); return frame.dom; } @@ -231,9 +236,10 @@ function serializeBlock< if (children.length > 0) { contentDOM?.appendChild( - serializeBlocksInternalHTML(editor, children, serializer, options), + serializeBlockGroup(editor, children, serializer, session, options), ); } + session.record(block.type!, fullBlock, [bc.dom]); return bc.dom; } @@ -245,20 +251,27 @@ function serializeBlocks< editor: BlockNoteEditor, blocks: PartialBlock[], serializer: DOMSerializer, + session: HTMLExportSession, options?: { document?: Document }, ) { const doc = options?.document ?? document; const fragment = doc.createDocumentFragment(); for (const block of blocks) { - const blockDOM = serializeBlock(editor, block, serializer, options); + const blockDOM = serializeBlock( + editor, + block, + serializer, + session, + options, + ); fragment.appendChild(blockDOM); } return fragment; } -export const serializeBlocksInternalHTML = < +function serializeBlockGroup< BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema, @@ -266,8 +279,9 @@ export const serializeBlocksInternalHTML = < editor: BlockNoteEditor, blocks: PartialBlock[], serializer: DOMSerializer, + session: HTMLExportSession, options?: { document?: Document }, -) => { +) { const BG_NODE = editor.pmSchema.nodes["blockGroup"]; const bg = BG_NODE.spec!.toDOM!(BG_NODE.create({})) as { @@ -275,9 +289,31 @@ export const serializeBlocksInternalHTML = < contentDOM?: HTMLElement; }; - const fragment = serializeBlocks(editor, blocks, serializer, options); + const fragment = serializeBlocks( + editor, + blocks, + serializer, + session, + options, + ); bg.contentDOM?.appendChild(fragment); return bg.dom; -}; +} + +export function serializeBlocksInternalHTML< + BSchema extends BlockSchema, + I extends InlineContentSchema, + S extends StyleSchema, +>( + editor: BlockNoteEditor, + blocks: PartialBlock[], + serializer: DOMSerializer, + options?: { document?: Document }, +) { + const session = new HTMLExportSession(); + const dom = serializeBlockGroup(editor, blocks, serializer, session, options); + session.run(editor.blockImplementations, dom); + return dom; +} diff --git a/packages/core/src/blocks/Heading/block.ts b/packages/core/src/blocks/Heading/block.ts index 572468d29a..b6acaa68c8 100644 --- a/packages/core/src/blocks/Heading/block.ts +++ b/packages/core/src/blocks/Heading/block.ts @@ -9,6 +9,7 @@ import { import { getDetailsContent } from "../getDetailsContent.js"; import { createToggleFrame, + expandToggleHTML, isToggleOpen, } from "../ToggleWrapper/createToggleFrame.js"; @@ -177,6 +178,7 @@ export const createHeadingBlockSpec = createBlockSpec( !!updated.props.isToggleable && frame.update(updated), }; }, + postProcessHTML: expandToggleHTML, toExternalHTML(block) { const dom = document.createElement(`h${block.props.level}`); addDefaultPropsExternalHTML(block.props, dom); diff --git a/packages/core/src/blocks/ListItem/CheckListItem/block.ts b/packages/core/src/blocks/ListItem/CheckListItem/block.ts index 936efc3be0..13145a7842 100644 --- a/packages/core/src/blocks/ListItem/CheckListItem/block.ts +++ b/packages/core/src/blocks/ListItem/CheckListItem/block.ts @@ -132,6 +132,20 @@ export const createCheckListItemBlockSpec = createBlockSpec( contentDOM: paragraph, }; }, + postProcessHTML({ blockOutputs }) { + // Static editor controls have no change handlers. Portable checkboxes + // don't have the editor's content wrapper and are left unchanged. + for (const { elements } of blockOutputs.values()) { + for (const root of elements) { + const checkbox = root.querySelector( + '[data-content-type="checkListItem"] input', + ); + if (checkbox) { + checkbox.disabled = true; + } + } + } + }, runsBefore: ["bulletListItem"], }, [ diff --git a/packages/core/src/blocks/ListItem/NumberedListItem/block.ts b/packages/core/src/blocks/ListItem/NumberedListItem/block.ts index 57530d741b..0b37fba2c7 100644 --- a/packages/core/src/blocks/ListItem/NumberedListItem/block.ts +++ b/packages/core/src/blocks/ListItem/NumberedListItem/block.ts @@ -94,6 +94,41 @@ export const createNumberedListItemBlockSpec = createBlockSpec( contentDOM: p, }; }, + postProcessHTML({ blockOutputs }) { + // The registry is an index, not an ordering contract. Only an actual + // preceding sibling in the same block group can continue a list. + const items = new Map(); + for (const [block, { elements }] of blockOutputs) { + for (const root of elements) { + const content = root.querySelector( + '[data-content-type="numberedListItem"]', + ); + if (content) { + items.set(root, { content, start: block.props?.start || 1 }); + } + } + } + + const indices = new Map(); + for (const root of items.keys()) { + // Walk back to a cached sibling or the beginning of this run, then + // fill forwards. Iterative to support very long lists. + const chain: Element[] = []; + let current: Element | null = root; + while (current && items.has(current) && !indices.has(current)) { + chain.push(current); + current = current.previousElementSibling; + } + let index = current ? indices.get(current) : undefined; + while (chain.length > 0) { + const element = chain.pop()!; + const item = items.get(element)!; + index = index === undefined ? item.start : index + 1; + indices.set(element, index); + item.content.setAttribute("data-index", String(index)); + } + } + }, }, [ createExtension({ diff --git a/packages/core/src/blocks/ListItem/ToggleListItem/block.ts b/packages/core/src/blocks/ListItem/ToggleListItem/block.ts index b516cf9d9e..37e13fda6b 100644 --- a/packages/core/src/blocks/ListItem/ToggleListItem/block.ts +++ b/packages/core/src/blocks/ListItem/ToggleListItem/block.ts @@ -8,6 +8,7 @@ import { import { getDetailsContent } from "../../getDetailsContent.js"; import { createToggleFrame, + expandToggleHTML, isToggleOpen, } from "../../ToggleWrapper/createToggleFrame.js"; @@ -94,6 +95,7 @@ export const createToggleListItemBlockSpec = createBlockSpec( return { dom: paragraphEl, contentDOM: paragraphEl }; }, renderFrame: createToggleFrame, + postProcessHTML: expandToggleHTML, toExternalHTML(block) { const li = document.createElement("li"); const details = document.createElement("details"); diff --git a/packages/core/src/blocks/Table/block.ts b/packages/core/src/blocks/Table/block.ts index a60a43ee09..2201b048b9 100644 --- a/packages/core/src/blocks/Table/block.ts +++ b/packages/core/src/blocks/Table/block.ts @@ -434,9 +434,42 @@ export type TableBlockConfig = BlockConfig< "table" >; -export const createTableBlockSpec = () => - createBlockSpecFromTiptapNode( - { node: TiptapTableNode, type: "table", content: "table" }, +export function createTableBlockSpec() { + return createBlockSpecFromTiptapNode( + { + node: TiptapTableNode, + type: "table", + content: "table", + postProcessHTML({ blockOutputs }) { + for (const { elements } of blockOutputs.values()) { + for (const root of elements) { + // Only editor-shaped tables need resizing styles and wrappers. + const table = root.querySelector( + '.bn-block-content[data-content-type="table"] > table', + ); + if (!table) { + continue; + } + + // The live column-resizing extension supplies these, but doesn't run + // during export. Keep the table's own styles intact. + table.style.setProperty( + "--default-cell-min-width", + `${EMPTY_CELL_WIDTH}px`, + ); + table.setAttribute("data-show-children", "true"); + + const wrapper = table.ownerDocument.createElement("div"); + wrapper.className = "tableWrapper"; + const inner = table.ownerDocument.createElement("div"); + inner.className = "tableWrapper-inner"; + wrapper.appendChild(inner); + table.replaceWith(wrapper); + wrapper.appendChild(table); + } + } + }, + }, tablePropSchema, [ createExtension({ @@ -505,6 +538,7 @@ export const createTableBlockSpec = () => }), ], ); +} // We need to declare this here because we aren't using the table extensions from tiptap, so the types are not automatically inferred. declare module "@tiptap/core" { diff --git a/packages/core/src/blocks/ToggleWrapper/createToggleFrame.ts b/packages/core/src/blocks/ToggleWrapper/createToggleFrame.ts index f77b837eee..d80fadfb27 100644 --- a/packages/core/src/blocks/ToggleWrapper/createToggleFrame.ts +++ b/packages/core/src/blocks/ToggleWrapper/createToggleFrame.ts @@ -1,5 +1,20 @@ import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js"; import type { Block } from "../defaultBlocks.js"; +import type { HTMLExportContext } from "../../schema/blocks/types.js"; + +/** Event handlers are lost in HTML strings, so static toggles stay expanded. */ +export function expandToggleHTML({ + blockOutputs, +}: Pick): undefined { + for (const { elements } of blockOutputs.values()) { + for (const root of elements) { + const button = root.querySelector( + '.bn-toggle-button[aria-expanded="false"]', + ); + button?.setAttribute("aria-expanded", "true"); + } + } +} // Only the block's id is used, so anything with an id will do. type ToggledState = { diff --git a/packages/core/src/schema/blocks/internal.test.ts b/packages/core/src/schema/blocks/internal.test.ts index 809a314ed7..8e6f381110 100644 --- a/packages/core/src/schema/blocks/internal.test.ts +++ b/packages/core/src/schema/blocks/internal.test.ts @@ -1,8 +1,19 @@ -import { afterEach, beforeEach, describe, expect, it } from "vite-plus/test"; +import { Node } from "@tiptap/core"; +import { + afterEach, + beforeEach, + describe, + expect, + it, + vi, +} from "vite-plus/test"; import { getNodeById } from "../../api/nodeUtil.js"; import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js"; -import { getBlockFromNodeView } from "./internal.js"; +import { + createBlockSpecFromTiptapNode, + getBlockFromNodeView, +} from "./internal.js"; describe("getBlockFromNodeView", () => { let editor: BlockNoteEditor; @@ -84,3 +95,18 @@ describe("getBlockFromNodeView", () => { ).not.toThrow(); }); }); + +it("preserves the HTML post-processing hook for TipTap-backed blocks", () => { + const postProcessHTML = vi.fn(); + const spec = createBlockSpecFromTiptapNode( + { + node: Node.create({ name: "testBlock" }), + type: "testBlock", + content: "none", + postProcessHTML, + }, + {}, + ); + + expect(spec.implementation.postProcessHTML).toBe(postProcessHTML); +}); diff --git a/packages/core/src/schema/blocks/internal.ts b/packages/core/src/schema/blocks/internal.ts index 542f4408be..835fb285d3 100644 --- a/packages/core/src/schema/blocks/internal.ts +++ b/packages/core/src/schema/blocks/internal.ts @@ -9,7 +9,7 @@ import { propsToDataAttributes, setDataAttributes } from "../dataAttributes.js"; import { PropSchema, Props } from "../propTypes.js"; import { createBlockKeyboard } from "./keyboard.js"; import { resolveBlockMeta } from "./meta.js"; -import { LooseBlockSpec } from "./types.js"; +import { BlockConfig, BlockImplementation, LooseBlockSpec } from "./types.js"; // Function that uses the 'propSchema' of a blockConfig to create a TipTap // node's `addAttributes` property. @@ -256,20 +256,26 @@ export function wrapInBlockStructure< } export function createBlockSpecFromTiptapNode< - const T extends { - node: Node; - type: string; - content: "inline" | "table" | "none" | "plain"; - }, + const TName extends string, + const TContent extends BlockConfig["content"], P extends PropSchema, >( - config: T, + config: { + node: Node; + type: TName; + content: TContent; + postProcessHTML?: BlockImplementation< + TName, + P, + TContent + >["postProcessHTML"]; + }, propSchema: P, extensions?: ExtensionFactoryInstance[], -): LooseBlockSpec { +): LooseBlockSpec { return { config: { - type: config.type as T["type"], + type: config.type, content: config.content, propSchema, }, @@ -282,6 +288,7 @@ export function createBlockSpecFromTiptapNode< }), render: defaultBlockToHTML, toExternalHTML: defaultBlockToHTML, + postProcessHTML: config.postProcessHTML, }, extensions, }; diff --git a/packages/core/src/schema/blocks/types.ts b/packages/core/src/schema/blocks/types.ts index 5af9f0eb23..332e3f884a 100644 --- a/packages/core/src/schema/blocks/types.ts +++ b/packages/core/src/schema/blocks/types.ts @@ -721,6 +721,41 @@ export type PartialBlockFromConfig< export type BlockIdentifier = { id: string } | string; +/** An export can receive partial blocks, including children of other types. */ +export type HTMLExportBlock< + TName extends string = string, + TProps extends PropSchema = PropSchema, + TContent extends BlockConfig["content"] = BlockConfig["content"], +> = Omit< + PartialBlockNoDefaults< + { [C in TContent]: BlockConfig }, + InlineContentSchema, + StyleSchema + >, + "children" +> & { children?: readonly HTMLExportBlock[] }; + +/** Surviving roots for one block; element roots are filtered lazily and cached. */ +export type HTMLExportOutput = { + readonly nodes: readonly globalThis.Node[]; + readonly elements: readonly Element[]; +}; + +/** The assembled export and the outputs belonging to one block type. */ +export type HTMLExportContext< + TName extends string = string, + TProps extends PropSchema = PropSchema, + TContent extends BlockConfig["content"] = BlockConfig["content"], +> = { + /** The detached export root, an element or document fragment. */ + root: globalThis.Node & ParentNode; + /** Export-local blocks of this type, mapped to their surviving DOM roots. */ + blockOutputs: ReadonlyMap< + HTMLExportBlock, + HTMLExportOutput + >; +}; + export type BlockImplementation< TName extends string = string, TProps extends PropSchema = PropSchema, @@ -730,6 +765,16 @@ export type BlockImplementation< | "table" | "plain", > = { + /** + * Runs synchronously once per participating block type after the full HTML + * export is assembled, for both `blocksToFullHTML` and `blocksToHTMLLossy`. + * Mutate only the detached DOM, keeping recorded roots in place. Use DOM + * relationships, not map order, and do not depend on other types' hooks. + */ + postProcessHTML?( + context: HTMLExportContext, + ): undefined; + /** * @internal Framework adapter (React): draws the block's frame in the * editor, for the node view of a framed block's `blockContainer` or of a diff --git a/packages/react/src/editor/styles.css b/packages/react/src/editor/styles.css index 5046c97352..802b439516 100644 --- a/packages/react/src/editor/styles.css +++ b/packages/react/src/editor/styles.css @@ -183,113 +183,114 @@ font-size: 12px; } -/* Highlight color styling */ +/* Highlight color styling. Keep fallbacks in sync with core's Block.css so + standalone editors and exported HTML also work outside a themed .bn-root. */ [data-style-type="textColor"][data-value="gray"], [data-text-color="gray"], .bn-block:has(> .bn-block-content[data-text-color="gray"]) { - color: var(--bn-colors-highlights-gray-text); + color: var(--bn-colors-highlights-gray-text, #9b9a97); } [data-style-type="textColor"][data-value="brown"], [data-text-color="brown"], .bn-block:has(> .bn-block-content[data-text-color="brown"]) { - color: var(--bn-colors-highlights-brown-text); + color: var(--bn-colors-highlights-brown-text, #64473a); } [data-style-type="textColor"][data-value="red"], [data-text-color="red"], .bn-block:has(> .bn-block-content[data-text-color="red"]) { - color: var(--bn-colors-highlights-red-text); + color: var(--bn-colors-highlights-red-text, #e03e3e); } [data-style-type="textColor"][data-value="orange"], [data-text-color="orange"], .bn-block:has(> .bn-block-content[data-text-color="orange"]) { - color: var(--bn-colors-highlights-orange-text); + color: var(--bn-colors-highlights-orange-text, #d9730d); } [data-style-type="textColor"][data-value="yellow"], [data-text-color="yellow"], .bn-block:has(> .bn-block-content[data-text-color="yellow"]) { - color: var(--bn-colors-highlights-yellow-text); + color: var(--bn-colors-highlights-yellow-text, #dfab01); } [data-style-type="textColor"][data-value="green"], [data-text-color="green"], .bn-block:has(> .bn-block-content[data-text-color="green"]) { - color: var(--bn-colors-highlights-green-text); + color: var(--bn-colors-highlights-green-text, #4d6461); } [data-style-type="textColor"][data-value="blue"], [data-text-color="blue"], .bn-block:has(> .bn-block-content[data-text-color="blue"]) { - color: var(--bn-colors-highlights-blue-text); + color: var(--bn-colors-highlights-blue-text, #0b6e99); } [data-style-type="textColor"][data-value="purple"], [data-text-color="purple"], .bn-block:has(> .bn-block-content[data-text-color="purple"]) { - color: var(--bn-colors-highlights-purple-text); + color: var(--bn-colors-highlights-purple-text, #6940a5); } [data-style-type="textColor"][data-value="pink"], [data-text-color="pink"], .bn-block:has(> .bn-block-content[data-text-color="pink"]) { - color: var(--bn-colors-highlights-pink-text); + color: var(--bn-colors-highlights-pink-text, #ad1a72); } [data-style-type="backgroundColor"][data-value="gray"], [data-background-color="gray"], .bn-block:has(> .bn-block-content[data-background-color="gray"]) { - background-color: var(--bn-colors-highlights-gray-background); + background-color: var(--bn-colors-highlights-gray-background, #ebeced); } [data-style-type="backgroundColor"][data-value="brown"], [data-background-color="brown"], .bn-block:has(> .bn-block-content[data-background-color="brown"]) { - background-color: var(--bn-colors-highlights-brown-background); + background-color: var(--bn-colors-highlights-brown-background, #e9e5e3); } [data-style-type="backgroundColor"][data-value="red"], [data-background-color="red"], .bn-block:has(> .bn-block-content[data-background-color="red"]) { - background-color: var(--bn-colors-highlights-red-background); + background-color: var(--bn-colors-highlights-red-background, #fbe4e4); } [data-style-type="backgroundColor"][data-value="orange"], [data-background-color="orange"], .bn-block:has(> .bn-block-content[data-background-color="orange"]) { - background-color: var(--bn-colors-highlights-orange-background); + background-color: var(--bn-colors-highlights-orange-background, #f6e9d9); } [data-style-type="backgroundColor"][data-value="yellow"], [data-background-color="yellow"], .bn-block:has(> .bn-block-content[data-background-color="yellow"]) { - background-color: var(--bn-colors-highlights-yellow-background); + background-color: var(--bn-colors-highlights-yellow-background, #fbf3db); } [data-style-type="backgroundColor"][data-value="green"], [data-background-color="green"], .bn-block:has(> .bn-block-content[data-background-color="green"]) { - background-color: var(--bn-colors-highlights-green-background); + background-color: var(--bn-colors-highlights-green-background, #ddedea); } [data-style-type="backgroundColor"][data-value="blue"], [data-background-color="blue"], .bn-block:has(> .bn-block-content[data-background-color="blue"]) { - background-color: var(--bn-colors-highlights-blue-background); + background-color: var(--bn-colors-highlights-blue-background, #ddebf1); } [data-style-type="backgroundColor"][data-value="purple"], [data-background-color="purple"], .bn-block:has(> .bn-block-content[data-background-color="purple"]) { - background-color: var(--bn-colors-highlights-purple-background); + background-color: var(--bn-colors-highlights-purple-background, #eae4f2); } [data-style-type="backgroundColor"][data-value="pink"], [data-background-color="pink"], .bn-block:has(> .bn-block-content[data-background-color="pink"]) { - background-color: var(--bn-colors-highlights-pink-background); + background-color: var(--bn-colors-highlights-pink-background, #f4dfeb); } /* Sets base Z-index on UI elements, i.e. elements which use the diff --git a/tests/src/unit/core/schema/__snapshots__/blocks.json b/tests/src/unit/core/schema/__snapshots__/blocks.json index c28f2c2cf5..76c0390aa1 100644 --- a/tests/src/unit/core/schema/__snapshots__/blocks.json +++ b/tests/src/unit/core/schema/__snapshots__/blocks.json @@ -179,6 +179,7 @@ "node": null, "parse": [Function], "parseContent": [Function], + "postProcessHTML": [Function], "render": [Function], "runsBefore": [ "bulletListItem", @@ -368,6 +369,7 @@ "node": null, "parse": [Function], "parseContent": [Function], + "postProcessHTML": [Function], "render": [Function], "renderFrame": [Function], "runsBefore": [ @@ -474,6 +476,7 @@ "node": null, "parse": [Function], "parseContent": [Function], + "postProcessHTML": [Function], "render": [Function], "toExternalHTML": [Function], }, @@ -684,6 +687,7 @@ "selectable": true, }, "node": null, + "postProcessHTML": [Function], "render": [Function], "toExternalHTML": [Function], }, @@ -726,6 +730,7 @@ "node": null, "parse": [Function], "parseContent": [Function], + "postProcessHTML": [Function], "render": [Function], "renderFrame": [Function], "runsBefore": [