Repository navigation
Fixes to CharacterLimit - #124
Merged
Merged
Conversation
acywatson
pushed a commit
that referenced
this pull request
Apr 9, 2022
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Oct 5, 2026
…de in a Markdown table cell ## Description GFM splits a row on each pipe that no backslash escapes, then drops the backslash of each `\|` in a cell, code spans included. Inline code `a\|b` exported as `` `a\|b` `` and read back as `a|b`, and `a\\|b` exported with the pipe unescaped, so the row split and the table broke apart. Each pipe in inline code now gets a backslash of its own (`` `a\\\|b` ``). Code with an odd run of backslashes right before a pipe can't be written as a GFM code span in a cell, so it is written as `<code>` with its punctuation as character references (`<code>a&meta#92;&meta#124;b</code>`), which GitHub renders as that code and which the playground reads back as a code span. ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-playground/__tests__/unit/MarkdownTransformers.test.ts -t "inline code with pipes" × round-trips inline code with pipes and backslashes in a cell: "a\\|b" × round-trips inline code with pipes and backslashes in a cell: "a\\\\|b" × round-trips inline code with pipes and backslashes in a cell: "\\|" × round-trips inline code with pipes and backslashes in a cell: "x`\\|`*y*" Tests 4 failed | 1 passed | 46 skipped (51) ``` ### After ``` $ vitest run --project unit packages/lexical-markdown packages/lexical-playground packages/lexical-mdast packages/lexical-code-core Tests 1378 passed (1378) ``` micromark's GFM table parser reads each exported row as one cell holding the original code. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Oct 6, 2026
…eader cell and keep raw HTML whitespace and pipes in cells ## Description Fixes from a /code-review of `MdastTableExtension`: - A column took the alignment most of its cells had, so inserting rows with no format into an aligned column cleared it (one of two centered cells isn't a majority). A column now takes the alignment of its header cell, the cell the GFM delimiter row sits under, and only when that has none the alignment most of its cells have, so aligning one body cell still doesn't align its column and a row inserted above the header still doesn't clear it. - Raw HTML in a cell was put on one line by turning each newline and the whitespace around it into a space, which changed the text of a `<pre>` or `<textarea>` and attribute values. And a `|` in raw HTML (`<span title="a|b">`) split the row, since gfm-table writes HTML as is and micromark doesn't unescape `\|` in HTML. Now a newline inside a tag becomes a space, and every other newline and every pipe becomes a character reference (` `, `&meta#124;`), which reads back as the same character. - The docs describe the alignment rule, the HTML encoding, and what the upstream review asked about the migration of the old table-level alignment: it is moved only onto cells with no format of their own, so a cell already formatted, including `justify`, `start` or `end`, which GFM can't write, keeps its format (covered by the existing legacy-state tests). ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-mdast × keeps a column aligned when rows are inserted below the header 12ms × aligns a column by its header cell alone 3ms × keeps the newlines and pipes of raw HTML in a cell (HTML extension: false) 45ms × keeps the newlines and pipes of raw HTML in a cell (HTML extension: true) 6ms AssertionError: expected '| a |\n| - |\n| x |\n| y |\n| z |\n| …' to be '| a |\n| :-: |\n| x |\n| y |\n|…' // Object.is equality AssertionError: expected '| a |\n| - |\n| 1 |\n| 2 |' to be '| a |\n| -: |\n| 1 |\n| 2 |' // Object.is equality AssertionError: expected '<pre>a|b c</pre><span title="x|y z">w…' to be '<pre>a&meta#124;b c</pre><span titl…' // Object.is equality ``` ### After ``` $ vitest run --project unit packages/lexical-mdast Tests 238 passed (238) $ vitest run --project browser dev-examples/mdast-editor packages/lexical-mdast packages/lexical-playground Tests 187 passed | 1 skipped (188) ``` Browser tests ran in Chromium only; Firefox and WebKit were not exercised. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Oct 6, 2026
…a tokenizer would, and take column alignment from the majority before the header row ## Description Fixes from a /code-review of the previous commit on `MdastTableExtension`: - Raw HTML in a cell treated any quote inside something tag-like as an attribute quote, so an apostrophe in a comment (`<!-- don't -->`) left the scan in a quote, and a later newline inside a tag became ` `, which broke the tag. The encoder now scans comments and declarations to their end and opens a quote only for an attribute value after `=`. - A newline between tags became ` `, which Markdown decodes into a real newline that the next export writes as `<br>`. Only a newline in a quoted attribute value or in the text of a `<pre>`, `<textarea>` or `<listing>` is now a reference; any other newline, with the whitespace around it, is one space, as before the previous commit. - The encoding now runs in the Markdown writer (an `html` handler that applies inside a `tableCell`), so it covers every HTML node a cell writes, without the extra copy of each cell's content on export. An `htmlBlock` (`rawHtmlBlock`, from `MdastHtmlExtension`) in a cell is now written as one line of its HTML around its Markdown children; before, its HTML was dropped and its children flattened into lines. - A pipe in a comment stays `&meta#124;`: a comment takes no character references and GFM splits the row on a bare pipe, so no spelling keeps it. The docs say so. - A column took its header cell's alignment even when all its other cells had another, the header was the first row a selection's export included rather than the table's header row, and an empty first row hid the header. A column now takes the alignment a strict majority of its cells have, or else that of the cell in the table's first row of cells, so rows inserted into an aligned column still don't clear it. ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-mdast × aligns a column by most of its cells over its header cell 15ms × takes the header from the table's first row with cells 4ms × takes no header alignment from a selection without the header row 8ms × writes a newline as a space outside a <pre> and ignores quotes in comments (HTML extension: false) 20ms × writes a newline as a space outside a <pre> and ignores quotes in comments (HTML extension: true) 8ms × adds no lines to raw HTML in a cell that is read and written again 18ms × writes an htmlBlock in a cell on one line 6ms AssertionError: expected '| a |\n| -: |\n| 1 |\n| 2 |' to be '| a |\n| :-: |\n| 1 |\n| 2 |' // Object.is equality AssertionError: expected '| |\n| - |\n| a |\n| 1 |\n| 2 |' to be '| |\n| -: |\n| a |\n| 1 |\n| 2 |' // Object.is equality AssertionError: expected '| 1 |\n| -: |\n| 2 |\n| 3 |' to be '| 1 |\n| - |\n| 2 |\n| 3 |' // Object.is equality AssertionError: expected '<!-- don\'t --> <div>x<span c…' to be '<!-- don\'t --> <div>x<span class=\'a…' // Object.is equality AssertionError: expected 's\|t<br>b' to be '<details><summary> s\|t </summary> b …' // Object.is equality Tests 7 failed | 238 passed (245) ``` ### After ``` $ vitest run --project unit packages/lexical-mdast Tests 245 passed (245) $ vitest run --project browser dev-examples/mdast-editor packages/lexical-mdast Tests 44 passed (44) $ pnpm run ci-check # exit 0 ``` Browser tests ran in Chromium only; Firefox and WebKit were not exercised. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Oct 8, 2026
…hout dropping the table transformer ## Description - A cell paragraph whose content writes nothing (an empty text node before normalization) was no longer written as an empty line. It is again. - Reading a cell without `TABLE` made export and import disagree and filtered the transformers twice per cell. Cells are read with all of `PLAYGROUND_TRANSFORMERS` again, and a cell line that reads as a table row (`|q|`) is written starting with `&meta#124;` so it stays text. - The export retry took mismatched marks as written after one try, which could add stray `<br>`s. Marks are now counted per write rather than per node, so a node written twice counts twice, and a retry happens only on a real collision, which the next try avoids. ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-playground/__tests__/unit/MarkdownTransformers.test.ts × writes a paragraph whose content writes nothing as an empty line ``` ### After ``` $ vitest run --project unit packages/lexical-playground/__tests__/unit/MarkdownTransformers.test.ts Tests 142 passed (142) ``` With the `&meta#124;` escape disabled, "keeps a line that starts and ends with a pipe as text" fails, so that case stays covered now that `TABLE` reads cells again. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Oct 17, 2026
…ll line as text ## Description Cell decoding turns `\|` into `|` before the cell's Markdown is read, and since cells are read with `TABLE` again, a cell such as `\|q\|` or `\|a\|b\|` became a table nested in the cell and lost its pipes. An escaped pipe that starts a line of the cell now decodes to `&meta#124;`, which reads back as `|` but can't start a table row. ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-playground/__tests__/unit/MarkdownTransformers.test.ts × reads the escaped pipes in "\\|q\\|" as text × reads the escaped pipes in "\\|a\\|b\\|" as text Tests 2 failed | 143 passed (145) ``` ### After ``` $ vitest run --project unit packages/lexical-markdown packages/lexical-playground/__tests__/unit packages/lexical-mdast Tests 1314 passed (1314) $ pnpm run tsc ``` `tsc` exited 0. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Oct 18, 2026
…r, keep equation line breaks, and write long cells in linear time ## Description - ab251de decoded an escaped pipe at the start of a cell line as `&meta#124;`, which also changed pipes in inline syntax after a `<br>`, so `$x<br>\|y$` stored `&meta#124;` in the equation for good. That decode is reverted. Cells are read with every playground transformer except `TABLE` instead (the list is built once), since a GFM cell can't hold a table and its pipes are decoded before its Markdown is read; `\|q\|` stays text. The `&meta#124;` escape on export, which only guarded against that, is gone. - A line break inside an inline equation in a cell was left in the equation as a placeholder mark. It is now a newline, which the equation writes back as `<br>`. - The export retry could loop forever when a transformer wrote a line break it then dropped, since no choice of marks fixes that count. It now retries once: the retry avoids all of the first try's Markdown, so every mark in it was written as one. - Writing a cell searched back for the last blank line at every line, and reading one copied the rest of the cell at every line, so a cell with a long list took quadratic time. Both now keep their position as they go. ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-playground/__tests__/unit/MarkdownTransformers.test.ts × writes a list with many items in a cell in linear time 19324ms Error: Test timed out in 5000ms. × reads an escaped pipe after a <br> in an equation as a pipe AssertionError: expected '| h |\n| --- |\n| $x &meta#124;y$ |' to be '| h |\n| --- |\n| $x<br>\|y$ |' ``` ### After ``` $ vitest run --project unit packages/lexical-playground/__tests__/unit/MarkdownTransformers.test.ts Tests 146 passed (146) ``` The 100,000-item list now takes about 1.8 s. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Oct 18, 2026
…ble cells down to plain <br> lines ## Description The table cell code had grown special cases for other nodes: the playground's `TABLE` transformer used private-use marks, a probe parse and its own code fence, list, quote and equation handling to keep each kind of block intact in a cell, and `MdastTableExtension` wrote lists, headings, quotes and code blocks in a cell as one line of HTML through `MdastHtmlExtension`, with an HTML tokenizer for raw HTML and source-offset filling for edge spaces. Both are now a plain mapping between a cell's lines and `<br>`: - Playground: a cell's Markdown has its pipes and literal `<br>`s backslash-escaped and each newline written as `<br>`; import undoes that and reads the result with every transformer but `TABLE`. Code blocks, lists and paragraphs round-trip through the newlines. A hard break's marker is still kept out of the `<br>`, delimiter-row fixes and the selection fix stay, padding is trimmed as spaces and tabs only. - mdast: each paragraph and line break in a cell is a `<br>`-separated line, other blocks are flattened into lines, raw HTML has its newlines as spaces and pipes as `&meta#124;`. Column alignment per cell and its migration are unchanged. No longer handled: the legacy `\n` the old transformer wrote is read as text, formatting that spans a `<br>` in hand-written Markdown (`**a<br>b**`) in the playground, code with a backslash right before a pipe, empty paragraphs and edge spaces in a cell, block HTML in mdast cells. Min+gzip against main (esbuild, packages external): `@lexical/mdast` +898 B (was +2,800), playground transformers +284 B (was +2,734), `@lexical/markdown` +191 B (unchanged). ## Test plan ### Before The playground suite's cell tests covered the removed paths. ### After ``` $ vitest run --project unit packages/lexical-playground/__tests__/unit/MarkdownTransformers.test.ts packages/lexical-mdast $ vitest run --project browser dev-examples/mdast-editor/src/__tests__/browser/TableEdit.test.ts $ tsc -p . && pnpm run tsc-dev-examples ``` All pass. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Oct 20, 2026
… line in table cells ## Description `MdastTableExtension` put only plain `html` nodes in a cell on one line. The `htmlBlock` and `htmlInline` nodes that `MdastHtmlExtension` exports (`$exportViaDOM`, `rawHtmlBlock`) kept their line ends, which split the table row, and a block one was flattened to its embedded children, losing its element and attributes. Both now stay whole on the cell's line: a line end next to a tag is dropped and any other becomes a space, pipes in the raw HTML become `&meta#124;`, and each embedded block becomes one line of the cell. ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastHtmlExtension.test.ts × keeps an inline element on the row × keeps a block element and its attributes Tests 2 failed | 43 passed (45) ``` ### After ``` $ vitest run --project unit packages/lexical-mdast Tests 229 passed (229) ``` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Oct 21, 2026
… and JSX ## Description Round 3 of the review of the cell's one-line JavaScript and TeX: - A `|` in a string, a template's text or a comment of an MDX expression is now written as `\x7c`, and in JSX text or an attribute string as `&meta#124;`, so GFM doesn't end the cell there. An `mdxJsxAttribute` string in a cell writes its line ends and pipes as references too, instead of turning into an expression attribute. - A JSX tag closed with `/ >` or `/` and a line end is read as self-closing. - JSX text trims only spaces and tabs beside a line end, as JSX does, so a non-breaking space is kept. - A JSX element without attributes or children no longer throws. - Stacked TeX comment lines are removed together, indented ones included. ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts × keeps {"type":"mdxFlowExpression","value":"\"a|b\" + `c|d`"} a block exports to in a cell on its row 14ms × keeps {"attributes":[{"name":"title","type":"mdxJsxAttribute","value":"a\nb|c"},{"name":"data","type":"mdxJsxAttribute","value":{"type":"mdxJsxAttribu × keeps {"name":"abbr","type":"mdxJsxFlowElement"} a block exports to in a cell on its row 3ms × keeps {"type":"mdxFlowExpression","value":"[<a t=\"a|b\nc\" /\n>, <b>x|y</b>, 1 // c|d\n+ 2]"} a block exports to in a cell on its row 3ms × keeps {"type":"math","value":"a % one\n % two\nb"} a block exports to in a cell on its row 2ms Tests 5 failed | 179 passed (184) ``` ### After ``` $ vitest run --project unit packages/lexical-mdast Test Files 7 passed (7) Tests 301 passed (301) ``` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Oct 21, 2026
…d keep regexes after conditions ## Description Math in a table cell was rewritten with a set of regex replacements that missed several cases: a `|` before a comment or `@` lost its separator, a comment after a space joined words, `\mbox` was treated as text, nested braces in `\url` ended early, and KaTeX's whitespace and `\r` comment rules weren't followed. In MDX expressions a regex after `if (...)` was read as division, a string could hold a raw line end, and `\` before a line end in code wrote a raw line end. JSX and directive attribute values with `&` were written without escaping it, so `&meta#124;` read back as `|`. Math now goes through one tokenizer modeled on KaTeX's lexer, MDX code tracks the condition parens before a regex, every remaining line end in code becomes U+2028, and `&` is escaped in attribute values. KaTeX is aligned to 0.16.47 in the playground and the test devDependency. ## Test plan ### Before ``` pnpm exec vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts Tests 17 failed | 208 passed (225) ``` ### After ``` pnpm exec vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastImportExport.test.ts Tests 225 passed (225) ``` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Oct 22, 2026
… GFM's own escapes, and fall back to an HTML table ## Description `MdastTableExtension` put a cell's content on one line with readers of its own for TeX, JavaScript/JSX and HTML, so it could tell where a `|` or a line end could be rewritten. Each was right only in the cases tested, and every fix moved where it was wrong. Now a cell uses only what GFM defines and other readers implement. A paragraph or line break is a `<br>`-separated line, and a pipe in code, math and MDX expressions is written as `\|`, which GFM (cmark-gfm, markdown-it, micromark) reads as a pipe before anything else in a cell. Raw HTML keeps `&meta#124;`. Import reads `\|` back as a pipe in math and raw HTML, as GFM does; micromark only does so in code. The TeX and JavaScript readers are gone. Some content has no form in a GFM cell: a list, heading, quote or code block, a display equation or block directive or JSX, a line end in math, code, HTML or an MDX expression, a pipe in an MDX expression or in script or style text, or a pipe right after a backslash (which micromark reads otherwise than GFM). When the editor has `MdastHtmlExtension`, a table holding any of that is written as an HTML table with Markdown in its cells between blank lines, which GitHub, CommonMark renderers and MDX read, and which reads back through the table's HTML import rules; other tables stay GFM. Without it, the content is flattened onto the row as before. `@lexical/mdast` is 927 B smaller min+gzip, and no longer needs `katex` for its tests. ## Test plan ### Before ``` pnpm exec vitest run --project unit packages/lexical-mdast × writes {"type":"inlineMath","value":"a|b"} in a cell as it is × writes {"type":"inlineMath","value":"a\n+ b|c"} as HTML, or else on its row × writes a table with a cell GFM cannot hold as HTML and reads it back × reads \| in raw HTML in a cell as a pipe, as GFM does ``` ### After ``` pnpm exec vitest run --project unit packages/lexical-mdast dev-examples/mdast-editor Tests 319 passed (319) ``` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
pushed a commit
to etrepum/lexical
that referenced
this pull request
Oct 22, 2026
…able cells, and escape pipes in raw HTML as GFM does ## Description MdastTableExtension rewrote MDX expressions, JSX and directive attributes in a cell, and their flow forms, and wrote pipes in raw HTML as `&meta#124;`, which changed comments and raw text, while their pipes still counted as exact. MDX and directives aren't GFM, so their nodes now go through as they are (a pipe in an MDX expression isn't representable in a cell), and raw HTML takes GFM's `\|` like code and math, with an odd backslash before a pipe the only case that falls back to an HTML table. Import now reads `\|` in math or HTML nested in raw HTML too, and the `<br>`/`<hr>` patterns are compiled once. The MDX and directive devDependencies go with their tests. The mdast entry is 308 B smaller (min+gzip 14642 to 14334). ## Test plan ### Before ``` $ vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastHtmlExtension.test.ts -t "math inside" AssertionError: expected 'x\|y' to be 'x|y' // Object.is equality Tests 1 failed | 50 skipped (51) ``` ### After ``` $ vitest run --project unit packages/lexical-mdast Tests 264 passed (264) $ FUZZ_RUNS=5000 vitest run --project conformance Tests 1 passed (1) ``` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This applies a few more fixes to CharacterLimit, where next siblings were not properly being marked as overflowed.