Repository navigation
fix(core): keep the list start and the children of a list item in the HTML parse - #3403
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/diagram-block
@blocknote/mantine
@blocknote/math-block
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
@blocknote/xl-typst-exporter
commit: |
|
12bc606 to
1966327
Compare
1966327 to
8aa5c57
Compare
8aa5c57 to
ff41820
Compare
ff41820 to
e17a1bc
Compare
e17a1bc to
b065fc6
Compare
b065fc6 to
f7b04c4
Compare
The fault: the HTML parse lost the `start` of a numbered list (for example `<ol start="2">`) if the first item of the list had a nested list. The markdown parse uses the HTML parse, so `3. a` with a nested list also became a list that starts at 1. The cause: before the parse rules run, the parser puts a list item with a nested list into a `div` element, together with the block group of the nested list (`createGroups` in `nestedLists.ts`). The parse rule of the numbered list item read the `start` attribute from the parent of the `<li>`. For such an item, the parent is that `div`, and not the list. The fix: for an item in a `div`, the rule reads `start` from the parent of the `div` (the list). It also uses the `div` to find out if the item is the first item of the list, so that a later item with a nested list does not get the start. The rule does not tell a `div` of the HTML source from the `div` of the parser. No known source writes `<ol><div><li>`.
The HTML parse moves a nested list out of its <li>, to make it a child block of the list item. It did not keep the other nodes of the <li> with the nested list: - Each node after the nested list went into a new item of the outer list. A paragraph became a new bullet. An image became an empty bullet with the image as its child. - When a block came between the content of the list item and the nested list (for example a code block), the nested list became a list after the list item, not a child of it. The markdown parse uses the HTML parse, thus it had the same fault. Now all the nodes after the own content of a list item move out of the <li> together, in order, into the block group of the list item. The parser makes the blocks from them. The own content is the text and the inline elements up to the first block, or else that first block if it is a paragraph, a heading, a code block or a quote with text. A comment, white space and an element without text are not content. If the first block is a different element (for example an image), the nodes before the nested list stay in the <li>, as before. Text directly after a nested list becomes a paragraph. It keeps one space at its start if the HTML has white space there, as each text after a block does in the parse (for example `<li><p>a</p> b</li>`). A <li> that starts with a nested list has no content of its own. As before, the nested list goes to the list item before it. Test changes: - nestedLists.browser.test.ts.snap: in "content after nested list" and "content in between", the text is in the block group of the list item, not in a new <li>. The other 4 changed snapshots change only by white space: the white space after a nested list moves with it into the block group. - parse html/emptyNestedCheckListItem: the paragraph is a child of the list item, not a new bullet. - parse markdown/complex: "Paragraph" is a paragraph child of its list item, and the lists after it are children of the same list item. It was a new bullet that took these lists as its children. - nestedLists.browser.test.ts, "stays out of the active document": the image after the nested list is in the block group of the list item, not in a new <li>. The test still sees an element of the HTML that goes into the active document. New cases in the parse tests (parseTestInstances.ts): 7 for HTML and 1 for markdown. The new elements of the two steps are made in `detachedDoc()`.
No test failed when one of these rules of `nestedLists.ts` was removed. Each new parse case fails without its rule: - listItemEmptyParagraphBeforeContent: an empty paragraph is not the content of the list item (`hasContent` in `isTextBlock`). - listItemTextAndBlockBeforeNestedList: the text before the first block is the content of the list item. - listItemLinkedImageBeforeNestedList: an image is a block, also in a link (the last line of `BLOCK_ELEMENTS`, `querySelector` in `isBlock`). - listItemHeadingCodeQuoteBeforeNestedList: a heading, a code block and a quote are text blocks (`isTextBlock`). - listItemContentInDivBeforeNestedList: a first block that is not a text block stays in the list item (the last line of `childrenStart`). - nestedListInOwnListItem, nestedCheckListInOwnListItem: a list item that holds only a nested list (the `start === 0` branch). - nestedListInAndNextToListItem: a list next to a list item that has a block group of step 1 (the loop in `createGroups`). The inputs are forms of Tiptap, Notion, GitHub, Plate and Lexical, and of markdown renderers. Three cases fail on `main`: listItemTextAndBlockBeforeNestedList, listItemLinkedImageBeforeNestedList and listItemHeadingCodeQuoteBeforeNestedList. The other five have the same result on `main`. They are guards. There is no source change.
f7b04c4 to
586f0cc
Compare
main has 91 new commits. Most core conflicts come from core fixes of this branch that went to main as separate pull requests, often in a changed form. For these files, the form of main is the reviewed one. Resolutions: - y/extensions/blockMatchNodes.ts and its browser test, y/utils.ts and its test: the files of main (#3380: blocks pair by ID only). - api/nodeConversions/blockToNode.ts: main (#3383). - api/parsers/html/util/nestedLists.ts and its snapshot: main (#3393, #3404). - blocks/File/block.ts, createLinkWithCaption.ts: main (#3401, #3387). - blocks/Image, Video, Audio: main (#3400). - CheckListItem/block.ts: main (#3388). NumberedListItem/block.ts: main (#3403). - api/exporters/markdown/htmlToMarkdown.ts and api/parsers/markdown/markdownToHtml.ts: main (#3385, #3392, #3394, #3391 and later commits). The parts of the branch that main does not have and that the lens needs come back in separate commits after this merge. - markdownExporter.ts, parseMarkdown.ts, ExportManager.ts, copyExtension.ts, SideMenu/dragging.ts merged without a conflict, but they used the API of the old markdown files of the branch (`escapes`, `target`): main. - serializeBlocksExternalHTML.ts merged without a conflict, but the merge had the toggle child order fix two times and did not compile: the form of main (#3388), with the white space placeholder of the branch. - exportParseEqualityTestInstances.ts: main (the toggle case of #3388). - vite.config.ts: main, with the lint rules of the lens. - tests/vite.config.browser.ts: main, with the lens files. - pnpm-lock.yaml: main, then `vp install`. main moved the shared test document to tests/src/fixtures/exporters (#3420). The lens test helper imports it from there, and the xl-ai build does not include the lens test helpers and benchmarks (a package build cannot read a file outside the package).
Summary
Stack on #3393.
Two fixes for the HTML parse of lists, one commit for each. The markdown parse uses the HTML parse.
1. The start of a numbered list. Input:
<ol start="2"><li>A<ul><li>B</li></ul></li><li>C</li></ol>main:Ahas nostart. The list starts at 1.Ahasstart: 2.Cause: the parser puts an item that has a nested list into a
div. The parse rule readstartfrom thatdiv, not from the list.2. The children of a list item. Input:
<ul><li><p>A</p><ul><li><p>B</p></li></ul><p>C</p></li></ul>main: bulletAwith the childB, then a new bulletC.Awith the childrenBand paragraphC.A nested list after a second block (
<p>A</p><pre>…</pre><ul>…) also went out of its item. Cause: the parser moved only the nested list out of the<li>. Now all the nodes after the own content of the item move with it.Testing
emptyNestedCheckListItem, markdowncomplex, 6 innestedLists.test.ts.snap(4 by white space only), and the inline snapshot of the test of fix(core): keep parsed HTML out of the active document #3393 for content after a nested list.@blocknote/core: 1,774 tests pass, as in fix(core): keep parsed HTML out of the active document #3393. Format tests: 851 pass (fix(core): keep parsed HTML out of the active document #3393: 834).Notes
main.<li><ol>…</ol>tail</li>): the list goes to the item before it, as onmain, andtailis now a paragraph (main: a list item). In a numbered list, the numbers after that paragraph start again. No known tool writes this form.<ol start="6"><div><li>: the items in the firstdivget the start (main: no start). No known source writes this HTML.<style>,<script>,<title>) before the paragraph of an item with a nested list gives an empty item with the paragraph as its child.Summary by CodeRabbit