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 committed Aug 15, 2022
1 parent 09f10a9 commit 73c0da8
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 @@ -42,6 +42,10 @@ jspm_packages
# macOS finder cache file
.DS_Store

# Intellij
.idea
*.iml

# VS Code settings
.vscode

Expand Down
Expand Up @@ -91,7 +91,7 @@ export default function createHTMLRules(blockContentType, options: any = {}) {
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"
}
]
]

2 comments on commit 73c0da8

@vercel
Copy link

@vercel vercel bot commented on 73c0da8 Aug 15, 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:

studio-workshop – ./

studio-workshop.sanity.build
studio-workshop-git-next.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 73c0da8 Aug 15, 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.sanity.build
test-studio-git-next.sanity.build

Please sign in to comment.