30 lines
799 B
JavaScript
30 lines
799 B
JavaScript
import { contentAsText } from '../helpers.js'
|
|
|
|
const languages = ['terrace', 'json', 'yaml', 'toml', 'javascript', 'typescript', 'c', 'python', 'sh']
|
|
|
|
export default async (doc, rootNode) => {
|
|
const node = {
|
|
type: rootNode.head,
|
|
class: '',
|
|
summaryClass: 'mb-[400px]',
|
|
preClass: 'max-h-[400px]',
|
|
examples: []
|
|
}
|
|
|
|
for await (const child of rootNode.children()) {
|
|
if (child.is('class')) node.class = child.tail
|
|
if (child.is('summary-class')) node.summaryClass = child.tail
|
|
if (child.is('pre-class')) node.preClass = child.tail
|
|
|
|
if (languages.includes(child.head)) {
|
|
node.examples.push({
|
|
language: child.head.trim(),
|
|
name: child.tail || '',
|
|
code: (await contentAsText(child, true)).trimEnd('\n')
|
|
})
|
|
}
|
|
}
|
|
|
|
return node
|
|
}
|