Skip to content

Commit

Permalink
documentChildren & nodeChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Oct 16, 2023
1 parent a46130d commit 364150d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/document/documentChildren.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Node } from "../node"
import { Document } from "./Document"

export function documentChildren(document: Document): Array<Node> {
return [
...document.children,
...document.footnotes.flatMap((footnote) => footnote.nodes),
]
}
1 change: 1 addition & 0 deletions src/document/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./Document"
export * from "./documentChildren"
1 change: 1 addition & 0 deletions src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./Node"
export * from "./nodeChildren"
16 changes: 16 additions & 0 deletions src/node/nodeChildren.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Node } from "./Node"

export function nodeChildren(node: Node): Array<Node> {
if (node.kind === "Table") {
return [
...node.head.flatMap((nodes) => nodes),
...node.body.flatMap((row) => row.flatMap((nodes) => nodes)),
]
}

if ("children" in node) {
return node.children
}

return []
}

0 comments on commit 364150d

Please sign in to comment.