Terrace/docs/read-page/nodes/CodeBlock.js
2023-03-04 22:36:08 -05:00

22 lines
433 B
JavaScript

import { contentAsText } from '../helpers.js'
export default async (doc, rootLevel) => {
const { next, level, line, head, tail, match } = doc
const node = {
type: head(),
language: tail(),
class: '',
text: ''
}
while (await next(rootLevel)) {
if (match('class')) node.class = tail()
else node.text = await contentAsText(doc, rootLevel, true)
}
node.text = node.text.trimEnd()
return node
}