20 lines
437 B
JavaScript
20 lines
437 B
JavaScript
import { contentAsText } from '../helpers.js'
|
|
|
|
export default async (doc, rootNode) => {
|
|
const node = {
|
|
type: rootNode.head,
|
|
language: rootNode.tail.trim(),
|
|
class: '',
|
|
text: ''
|
|
}
|
|
|
|
let codeText = ''
|
|
for await (const child of rootNode.children()) {
|
|
if (child.is('class')) node.class = child.tail
|
|
else codeText += await contentAsText(child, true) + '\n'
|
|
}
|
|
node.text = codeText.trimEnd()
|
|
|
|
return node
|
|
}
|