fix(v2): properly process multiple nodes in slugger

This commit is contained in:
Alexey Pyltsyn 2020-03-21 21:06:51 +03:00
parent 79a3f35de6
commit c7101e032b

View file

@ -23,11 +23,14 @@ function slug() {
if (id) {
id = slugs.slug(id, true);
} else {
const headingTextNodes =
headingNode.children.find(
({type}) => !['html', 'jsx'].includes(type),
) || headingNode;
id = slugs.slug(toString(headingTextNodes));
const headingTextNodes = headingNode.children.filter(
({type}) => !['html', 'jsx'].includes(type),
);
const normalizedHeadingNode =
headingTextNodes.length > 0
? {children: headingTextNodes}
: headingNode;
id = slugs.slug(toString(normalizedHeadingNode));
}
data.id = id;