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 rexxars committed Dec 16, 2022
1 parent cd0819f commit 5e51831
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"
}
]
]

1 comment on commit 5e51831

@vercel
Copy link

@vercel vercel bot commented on 5e51831 Dec 16, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

test-studio – ./

test-studio-git-next.sanity.build
test-studio.sanity.build

Please sign in to comment.