33 lines
835 B
JavaScript
33 lines
835 B
JavaScript
const { contentAsText } = require('../helpers')
|
|
|
|
const languages = ['terrace', 'json', 'yaml', 'toml', 'javascript', 'typescript', 'c', 'python', 'sh']
|
|
|
|
module.exports = async (doc, rootLevel) => {
|
|
const { next, level, line, head, tail, match } = doc
|
|
|
|
const node = {
|
|
type: head(),
|
|
class: '',
|
|
summaryClass: 'mb-[400px]',
|
|
preClass: 'max-h-[400px]',
|
|
examples: []
|
|
}
|
|
|
|
while (await next(rootLevel)) {
|
|
if (match('class')) node.class = tail()
|
|
if (match('summary-class')) node.summaryClass = tail()
|
|
if (match('pre-class')) node.preClass = tail()
|
|
|
|
const exampleLevel = level()
|
|
if (languages.includes(head())) {
|
|
node.examples.push({
|
|
language: head(),
|
|
name: tail() || '',
|
|
code: (await contentAsText(doc, exampleLevel)).trimEnd('\n')
|
|
})
|
|
}
|
|
}
|
|
|
|
return node
|
|
}
|