Skip to content

fix: Table column widths not being set in exported HTML #1947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

matthewlipski
Copy link
Collaborator

Closes #1574

TODO: Empty paragraphs should also include a line break for correct row height.

Copy link

vercel bot commented Aug 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
blocknote Error Error Aug 18, 2025 3:19pm
blocknote-website Error Error Aug 18, 2025 3:19pm

Copy link

pkg-pr-new bot commented Aug 14, 2025

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/ariakit@1947

@blocknote/code-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/code-block@1947

@blocknote/core

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/core@1947

@blocknote/mantine

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/mantine@1947

@blocknote/react

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/react@1947

@blocknote/server-util

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/server-util@1947

@blocknote/shadcn

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/shadcn@1947

@blocknote/xl-ai

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-ai@1947

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-docx-exporter@1947

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-email-exporter@1947

@blocknote/xl-multi-column

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-multi-column@1947

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-odt-exporter@1947

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-pdf-exporter@1947

commit: 9d15a45

this.name,
"table",
{
...(this.options.domAttributes?.blockContent || {}),
...(this.options.domAttributes?.blockContent || { fesfes: "fesfes" }),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this?

renderHTML({ HTMLAttributes }) {
return ["p", HTMLAttributes, 0];
renderHTML({ node, HTMLAttributes }) {
return ["p", HTMLAttributes, node.childCount ? 0 : ["br"]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a break?

Comment on lines +48 to +71
// Need to manually add column widths.
const cols: HTMLTableColElement[] = [];
for (const tableCell of node.children[0].children) {
const colWidths: null | (number | undefined)[] =
tableCell.attrs["colwidth"];

if (colWidths) {
for (const colWidth of tableCell.attrs["colwidth"]) {
const col = document.createElement("col");
if (colWidth) {
col.style = `width: ${colWidth}px`;
}

cols.push(col);
}
} else {
cols.push(document.createElement("col"));
}
}

const colGroup = document.createElement("colgroup");
for (const col of cols) {
colGroup.appendChild(col);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Need to manually add column widths.
const cols: HTMLTableColElement[] = [];
for (const tableCell of node.children[0].children) {
const colWidths: null | (number | undefined)[] =
tableCell.attrs["colwidth"];
if (colWidths) {
for (const colWidth of tableCell.attrs["colwidth"]) {
const col = document.createElement("col");
if (colWidth) {
col.style = `width: ${colWidth}px`;
}
cols.push(col);
}
} else {
cols.push(document.createElement("col"));
}
}
const colGroup = document.createElement("colgroup");
for (const col of cols) {
colGroup.appendChild(col);
}
// Need to manually add colgroup element
const colGroup = document.createElement("colgroup");
for (const tableCell of node.children[0].children) {
const colWidths: null | (number | undefined)[] =
tableCell.attrs["colwidth"];
if (colWidths) {
for (const colWidth of tableCell.attrs["colwidth"]) {
const col = document.createElement("col");
if (colWidth) {
col.style = `width: ${colWidth}px`;
}
colGroup.appendChild(col);
}
} else {
colGroup.appendChild(document.createElement("col"));
}
}

Just makes it a bit clearer what is happening here without the extra insertion loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

blocksToFullHTML and blocksToHTMLLossy produces broken tables
3 participants