Skip to content

Commit

Permalink
fix(block-tools): ignore blocks inside list items (#3492)
Browse files Browse the repository at this point in the history
This fixes a bug where p-tags (and other block elements) inside li elements
where incorrectly hoisted out of the li element.

With this change blocks are ignored, and block children are added directly to the
listItem instead.
  • Loading branch information
snorrees authored and bjoerge committed Sep 26, 2022
1 parent 5e0c079 commit 98e2717
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -39,6 +39,10 @@ jspm_packages
# macOS finder cache file
.DS_Store

# Intellij
.idea
*.iml

# VS Code settings
/.vscode

Expand Down
Expand Up @@ -111,7 +111,7 @@ export default function createHTMLRules(
return undefined
}
// Don't add blocks into list items
if (el.parentNode && tagName(el) === 'li') {
if (el.parentNode && tagName(el.parentNode) === 'li') {
return next(el.childNodes)
}
// If style is not supported, return a defaultBlockType
Expand Down
Expand Up @@ -22,6 +22,10 @@
<li>
<a href="/">Link</a>
</li>
<li>
<p>p in li.</p>
<h1>block children are still <strong>processed.</strong></h1>
</li>
</ul>
</body>
</html>
Expand Up @@ -126,5 +126,27 @@
}
],
"style": "normal"
},
{
"_key": "randomKey8",
"_type": "block",
"children": [
{
"_key": "randomKey80",
"_type": "span",
"marks": [],
"text": "p in li. block children are still "
},
{
"_key": "randomKey81",
"_type": "span",
"marks": ["strong"],
"text": "processed."
}
],
"level": 1,
"listItem": "bullet",
"markDefs": [],
"style": "normal"
}
]
]

0 comments on commit 98e2717

Please sign in to comment.