Heading: flatten array to last string child
commitbd5614e7dca3cce25dbb02067826a1599213e7ec
authorMatilde Park <matilde.park@urbit.org>
dateWed 1 Jun 2022, 13:38 (4 years ago)
parentb043294
components/schema/Heading.markdoc.js+5−2
@@ -1,11 +1,14 @@
11import { Tag } from "@markdoc/markdoc";
22
3−// Or replace this with your own function
43function generateID(children, attributes) {
54 if (attributes.id && typeof attributes.id === "string") {
65 return attributes.id;
76 }
8− return children
7+
8+ const bottomChildren = children
9+ .map((child) => (child.children ? child.children : child))
10+ .flat();
11+ return bottomChildren
912 .filter((child) => typeof child === "string")
1013 .join(" ")
1114 .replace(/[?]/g, "")