Terrace/docs/parser/helpers.js
2023-02-12 09:00:19 -05:00

18 lines
410 B
JavaScript

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