27 lines
707 B
JavaScript
27 lines
707 B
JavaScript
import { useDocument } from '@terrace-lang/js/document'
|
|
import { createFileReader } from '@terrace-lang/js/readers/node-readline'
|
|
import fs from 'fs/promises'
|
|
import path from 'path'
|
|
import knownNodes from './index.js'
|
|
|
|
export default async function (originalDoc, rootLevel, ...args) {
|
|
const includedDoc = useDocument(createFileReader(originalDoc.tail()))
|
|
const { next, head, tail, level } = includedDoc
|
|
|
|
const node = {
|
|
type: originalDoc.head(),
|
|
class: '',
|
|
children: []
|
|
}
|
|
|
|
while (await next()) {
|
|
if (!head()) continue
|
|
const block = head()
|
|
|
|
if (!knownNodes[block]) continue
|
|
node.children.push(await knownNodes[block](includedDoc, level(), ...args))
|
|
}
|
|
|
|
return node
|
|
}
|