/**
 * Adapted From:
 * https://github.com/syntax-tree/mdast-util-to-string
 */ import * as Md from "@common/markdown/markdown-ast" ; import { unistIsParent , unistIsStringLiteral } from "@common/markdown/unist-utils" ; /**
 * Get the text content of a node.
 * Prefer the node’s plain-text fields, otherwise serialize its children,
 * and if the given value is an array, serialize the nodes in it.
 */ export function mdastTextContent ( node , options ? ) { var { includeImageAlt = true } = options || { } ; return one ( node , includeImageAlt ) ; } function one ( node , includeImageAlt ) { if ( ! node || typeof node !== "object" ) { return "" ; } if ( unistIsStringLiteral ( node ) ) { return node . value ; } if ( includeImageAlt && node . alt !== undefined ) { return node . alt as string ; } if ( unistIsParent ( node ) ) { let result = all ( node . children , includeImageAlt ) ; if ( result ) { return result ; } ; } if ( Array . isArray ( node ) ) { return all ( node , includeImageAlt ) ; } return "" ; } function all ( values , includeImageAlt ) { var result = [ ] ; for ( let idx = 0 ; idx < values . length ; idx ++ ) { result [ idx ] = one ( values [ idx ] , includeImageAlt ) ; } return result . join ( '' ) ; }