You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HTML export: a line break inside a cell stays a line break - #4369
to_html in crates/engine/src/io.rs escaped a cell's text and wrote it as is. A line feed inside a cell (alpha ⏎ beta) reached the page as a raw newline, which HTML (and the cell's white-space:nowrap) shows as a space. So the cell read alpha beta in a browser, and Excel reopened it as one line, the same as a single-line neighbour, as the issue shows.
What changed
A line feed in a cell's text is written as <br style="mso-data-placement:same-cell">. That's the form Excel's own Web Page export uses for a break that stays in the cell; a plain <br> can make Excel start a new row when it reads HTML. Browsers ignore the style and break the line.
How: a cell-text variant of the escaper (esc_cell_within) does this, inside the same page-size budget.
Unchanged:esc_within itself, so image alt text and other attribute values keep a line feed as a character, never markup inside an attribute.
QA report
Main vs branch, end to end (gridcraft-cli convert)
The workbook is the issue's setup, built with cell.set: A1 alpha⏎beta, A2 the single-line alpha beta, B1 neighbor, and A3 a&b⏎<c>, which checks escaping around a break. It was saved to .xlsx and converted with gridcraft-cli convert source.xlsx output.htm. main is a gridcraft-cli built from origin/main (1476d4e7); the branch is this PR (6ba8ea13).
Read back. I didn't have Excel. I read each page back with a gridcraft-cli built from #4345, the import-side fix for <br> in cells, and evaluated =LEN(A1)&"|"&CODE(MID(A1,6,1))&"|"&(A1=A2)&"|"&B1&"|"&LEN(A3):
Page from
result
meaning
main
10|32|TRUE|neighbor|7
A1 came back as alpha beta: the break is a space, and A1 equals A2
this PR
10|10|FALSE|neighbor|7
A1 kept its line feed (code 10), and it no longer equals A2
a cell with &, <, > and a double break (a&b⏎<c>⏎⏎d);
esc_within keeping a line feed as a character for attributes;
the break counting against the page's room (one byte short gives None).
The other HTML export tests still pass.
Negative control
With esc_cell_within writing line feeds as characters again (on top of 6ba8ea13, then restored with git checkout), the test fails at its first assertion.
Excel: I didn't open the output in Excel. The mso-data-placement:same-cell form is the one the issue and Excel's own export use; the read-back above used GridCraft's importer.
Wrap text: cells keep white-space:nowrap, so a long line still doesn't wrap. Only an explicit line feed breaks it, as in Excel when wrap text is off.
Carriage returns: a lone \r is written as it is; GridCraft stores line breaks as \n.
Overlap with HTML export: cell hyperlinks keep their destinations #4366: both PRs change the line in to_html that escapes the cell text (this one swaps esc_within for esc_cell_within). Whichever lands second needs a one-line rebase.
cargo xtask ci: I didn't run the full cargo xtask ci (wasm, layers, the other crates).
Summary by CodeRabbit
Bug Fixes
HTML exports now preserve line breaks within cells, displaying them as breaks rather than running text together. Spaces and escaped HTML characters are also preserved.
A cell holding a line feed was written as plain text, which the page (and the cell's white-space:nowrap) shows as a space, so Excel reopened it as one line. The break is now written as Excel's Web Page export writes it, <br style="mso-data-placement:same-cell">, so it stays in the cell. Image alt text and other attributes are escaped as before. Fixesstorytold#4357.
No actionable comments were generated in the recent review.
Walkthrough
HTML page export now converts line feeds in cell text to Excel same-cell <br> markup. General-purpose escaping leaves line feeds unchanged. The added test checks line breaks, HTML escaping, and the generated markup’s byte length.
Changes: HTML cell line breaks
Layer / File(s)
Summary
Cell escaping and HTML export crates/engine/src/io.rs, crates/engine/src/io/tests.rs
Cell-specific escaping converts line feeds to same-cell break markup. The HTML page exporter uses this escaping path. A test checks line breaks, ordinary spaces, special-character escaping, and byte-length handling.
Issue 4329 describes the separate HTML import behavior for <br />. This change updates the writer, not the reader, so it does not address that issue.
Suggested reviewers:dylanmtaylor, echelon
Merge Risk: Minimal · up to 6ba8e
HTML export now keeps a line break inside a cell as a line break. The change is small and has test coverage. No actionable merge-blocking risk remains. Excel rendering itself was not tested.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: a line feed inside an HTML-exported cell is now emitted as a same-cell line break instead of being lost. The raw summary, the PR objectives, and the linked issue #4357…
Linked Issues check
Issue #4357 requires HTML export to keep a line feed inside a cell as a line break, so A1 (alpha⏎beta) differs from the single-line A2 (alpha beta), and adjacent values survive. The PR routes cell…
Out of Scope Changes check
The whole-PR changes (merge base 1476d4e to head 6ba8ea1) touch the HTML cell-text escaping path in crates/engine/src/io.rs and add one test in crates/engine/src/io/tests.rs. The test's added li…
Full details: Title check
Explanation
The title names the main change: a line feed inside an HTML-exported cell is now emitted as a same-cell line break instead of being lost. The raw summary, the PR objectives, and the linked issue #4357 all describe this same change to HTML cell escaping. The title is specific and matches the changeset.
Full details: Linked Issues check
Explanation
Issue #4357 requires HTML export to keep a line feed inside a cell as a line break, so A1 (alpha⏎beta) differs from the single-line A2 (alpha beta), and adjacent values survive. The PR routes cell text through the new esc_cell_within, which writes each LF as <br style="mso-data-placement:same-cell">. The added test io::tests::html_export_keeps_line_breaks_inside_cells calls to_html and asserts: >alpha<br…>beta</td> for A1, >alpha beta</td> for A2, and escaped a&amp;b<br…>&lt;c&gt;<br…><br…>d for A3. It also checks that esc_within keeps LF as a character and that the break counts toward the page budget. The PR reports these tests and the wider engine and xlsx test suites pass at head. The issue's requirement is an Excel result. Excel was not run here, and the PR states this. The mso-data-placement:same-cell form matches the form the issue cites from Excel's own Web Page export. The io.rs text diff could not be read in this review. The implementation was checked only through the test's assertions and the PR's summary, not through the changed source lines. The requirement is met as far as this evidence shows. No requirement is unmet in the evidence.
Full details: Out of Scope Changes check
Explanation
The whole-PR changes (merge base 1476d4e to head 6ba8ea1) touch the HTML cell-text escaping path in crates/engine/src/io.rs and add one test in crates/engine/src/io/tests.rs. The test's added lines all exercise the cell-text break behavior, the attribute-escaping boundary (esc_within), or the page-size budget for the same change. The PR says esc_within is unchanged. The summary and test do not show unrelated edits. The io.rs diff could not be read, so line-level scope was verified only through the test and the PR summary. No demonstrated unrelated change was found.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Reviewing files that changed from the base of the PR and between abcfc19 and 6ba8ea1.
Files selected for processing: 2
crates/engine/src/io.rs
crates/engine/src/io/tests.rs
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.
emrahoksak
pushed a commit
to emrahoksak/girdcraft-
that referenced
this pull request
Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4357
What was wrong
to_htmlincrates/engine/src/io.rsescaped a cell's text and wrote it as is. A line feed inside a cell (alpha⏎beta) reached the page as a raw newline, which HTML (and the cell'swhite-space:nowrap) shows as a space. So the cell readalpha betain a browser, and Excel reopened it as one line, the same as a single-line neighbour, as the issue shows.What changed
<br style="mso-data-placement:same-cell">. That's the form Excel's own Web Page export uses for a break that stays in the cell; a plain<br>can make Excel start a new row when it reads HTML. Browsers ignore the style and break the line.esc_cell_within) does this, inside the same page-size budget.esc_withinitself, so imagealttext and other attribute values keep a line feed as a character, never markup inside an attribute.QA report
Main vs branch, end to end (
gridcraft-cli convert)The workbook is the issue's setup, built with
cell.set: A1alpha⏎beta, A2 the single-linealpha beta, B1neighbor, and A3a&b⏎<c>, which checks escaping around a break. It was saved to.xlsxand converted withgridcraft-cli convert source.xlsx output.htm.mainis agridcraft-clibuilt fromorigin/main(1476d4e7); the branch is this PR (6ba8ea13).alpha⏎beta(raw newline, shown as a space)alpha<br style="mso-data-placement:same-cell">betaalpha betaalpha betaa&b⏎<c>a&b<br style="mso-data-placement:same-cell"><c>neighborneighborRead back. I didn't have Excel. I read each page back with a
gridcraft-clibuilt from #4345, the import-side fix for<br>in cells, and evaluated=LEN(A1)&"|"&CODE(MID(A1,6,1))&"|"&(A1=A2)&"|"&B1&"|"&LEN(A3):10|32|TRUE|neighbor|7alpha beta: the break is a space, and A1 equals A210|10|FALSE|neighbor|7Test
io::tests::html_export_keeps_line_breaks_inside_cellscovers:&,<,>and a double break (a&b⏎<c>⏎⏎d);esc_withinkeeping a line feed as a character for attributes;None).The other HTML export tests still pass.
Negative control
With
esc_cell_withinwriting line feeds as characters again (on top of6ba8ea13, then restored withgit checkout), the test fails at its first assertion.Gate (macOS arm64)
cargo fmt --all -- --checkcargo clippy -p gridcraft-engine --all-targets -- -D warningscargo test -p gridcraft-engine -p gridcraft-xlsxNot covered
mso-data-placement:same-cellform is the one the issue and Excel's own export use; the read-back above used GridCraft's importer.white-space:nowrap, so a long line still doesn't wrap. Only an explicit line feed breaks it, as in Excel when wrap text is off.\ris written as it is; GridCraft stores line breaks as\n.to_htmlthat escapes the cell text (this one swapsesc_withinforesc_cell_within). Whichever lands second needs a one-line rebase.cargo xtask ci: I didn't run the fullcargo xtask ci(wasm, layers, the other crates).Summary by CodeRabbit