Skip to content

Commit 9d01e99

Browse files
committed
Fixed PR comments and updated docs
1 parent 9d15a45 commit 9d01e99

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

docs/content/docs/features/export/html.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ path: /docs/converting-blocks
1616

1717
## Export to BlockNote HTML
1818

19-
Use `editor.blocksToFullHTML` to export the entire document with all structure, styles and formatting.
20-
The exported HTML is the same as BlockNote would use to render the editor, and includes all structure for nested blocks.
19+
Use `editor.blocksToFullHTML` to export blocks with their full HTML structure, the same as BlockNote uses in its rendered HTML.
2120

2221
For example, you an use this for static rendering documents that have been created in the editor.
23-
Make sure to include the same stylesheets when you want to render the output HTML ([see example](/examples/backend/rendering-static-documents)).
22+
23+
<Callout type={"info"}>
24+
For the exported HTML to look the same as the editor, make sure to wrap it in the same `div`s that the editor renders, and add the same stylesheets. To learn more, see [this example](/examples/backend/rendering-static-documents).
25+
26+
</Callout>
2427

2528
```typescript
2629
async blocksToFullHTML(blocks?: Block[]): Promise<string>;

examples/02-backend/04-rendering-static-documents/src/App.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import "@blocknote/core/fonts/inter.css";
2-
import "@blocknote/core/style.css";
2+
import "@blocknote/mantine/style.css";
33

44
/**
55
On Server Side, you can use the ServerBlockNoteEditor to render BlockNote documents to HTML. e.g.:
66
7-
import { ServerBlockNoteEditor } from "@blocknote/server-util";
7+
import { ServerBlockNoteEditor } from "@blocknote/server-util";
88
9-
const editor = ServerBlockNoteEditor.create();
10-
const html = await editor.blocksToFullHTML(document);
9+
const editor = ServerBlockNoteEditor.create();
10+
const html = await editor.blocksToFullHTML(document);
1111
1212
You can then use render this HTML as a static page or send it to the client. Make sure to include the editor stylesheets:
13-
14-
import "@blocknote/core/fonts/inter.css";
15-
import "@blocknote/core/style.css";
13+
14+
import "@blocknote/core/fonts/inter.css";
15+
// Depending on the UI library you're using, you may want to use `react`,
16+
// `mantine`, etc instead of `core`.
17+
import "@blocknote/core/style.css";
1618
1719
This example has the HTML hard-coded, but shows at least how the document will be rendered when the appropriate style sheets are loaded.
1820
*/
@@ -50,9 +52,14 @@ export default function App() {
5052

5153
// Renders the editor instance using a React component.
5254
return (
53-
<div className="bn-container">
55+
// To make the HTML look identical to the editor, we need to add these two
56+
// wrapping divs to the exported blocks. You need will need to add
57+
// additional class names/attributes depend on the UI library you're using,
58+
// whether you want to show light or dark more, etc. It's easiest to just
59+
// check the rendered editor HTML to see what you need to add.
60+
<div className="bn-container bn-mantine">
5461
<div
55-
className="bn-default-styles"
62+
className="ProseMirror bn-editor bn-default-styles"
5663
dangerouslySetInnerHTML={{ __html: html }}
5764
/>
5865
</div>

packages/core/src/blocks/TableBlockContent/TableBlockContent.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ export const TableBlockContent = createStronglyTypedTiptapNode({
3939
this.name,
4040
"table",
4141
{
42-
...(this.options.domAttributes?.blockContent || { fesfes: "fesfes" }),
42+
...(this.options.domAttributes?.blockContent || {}),
4343
...HTMLAttributes,
4444
},
4545
this.options.domAttributes?.inlineContent || {},
4646
);
4747

48-
// Need to manually add column widths.
49-
const cols: HTMLTableColElement[] = [];
48+
// Need to manually add colgroup element
49+
const colGroup = document.createElement("colgroup");
5050
for (const tableCell of node.children[0].children) {
5151
const colWidths: null | (number | undefined)[] =
5252
tableCell.attrs["colwidth"];
@@ -58,18 +58,13 @@ export const TableBlockContent = createStronglyTypedTiptapNode({
5858
col.style = `width: ${colWidth}px`;
5959
}
6060

61-
cols.push(col);
61+
colGroup.appendChild(col);
6262
}
6363
} else {
64-
cols.push(document.createElement("col"));
64+
colGroup.appendChild(document.createElement("col"));
6565
}
6666
}
6767

68-
const colGroup = document.createElement("colgroup");
69-
for (const col of cols) {
70-
colGroup.appendChild(col);
71-
}
72-
7368
domOutputSpec.dom.firstChild?.appendChild(colGroup);
7469

7570
return domOutputSpec;
@@ -176,6 +171,9 @@ const TableParagraph = createStronglyTypedTiptapNode({
176171
},
177172

178173
renderHTML({ node, HTMLAttributes }) {
174+
// Insert a line break if there is no content, in order to preserve the
175+
// correct cell height. Otherwise, the cell will have a height of zero +
176+
// padding.
179177
return ["p", HTMLAttributes, node.childCount ? 0 : ["br"]];
180178
},
181179
});

0 commit comments

Comments
 (0)