on master help sign in
Heading: flatten array to last string child
bd5614eMatilde Park
components/schema/Heading.markdoc.js+5−2
@@ -1,11 +1,14 @@
1import { Tag } from "@markdoc/markdoc";
1import { Tag } from "@markdoc/markdoc";
2
2
3−// Or replace this with your own function
4function generateID(children, attributes) {
3function generateID(children, attributes) {
5 if (attributes.id && typeof attributes.id === "string") {
4 if (attributes.id && typeof attributes.id === "string") {
6 return attributes.id;
5 return attributes.id;
7 }
6 }
8− return children
7+
8+ const bottomChildren = children
9+ .map((child) => (child.children ? child.children : child))
10+ .flat();
11+ return bottomChildren
9 .filter((child) => typeof child === "string")
12 .filter((child) => typeof child === "string")
10 .join(" ")
13 .join(" ")
11 .replace(/[?]/g, "")
14 .replace(/[?]/g, "")