Terrace/docs/parser/helpers.js
2023-02-12 20:49:04 -05:00

17 lines
494 B
JavaScript

module.exports.contentAsText = async function(doc, rootLevel, includeCurrent = false) {
const { level, next, line, head } = doc
const linesAsArray = []
if (includeCurrent) linesAsArray.push(line())
let contentDepth = includeCurrent ? level() : -1
while(await next(rootLevel)) {
if (contentDepth === -1 && !!line()) contentDepth = level()
const indent = ''.padStart(level() - contentDepth, ' ')
linesAsArray.push(indent + line())
}
return linesAsArray.join('\n')
}