Add 'Core' section.

This commit is contained in:
Joshua Bemenderfer
2023-02-12 22:11:13 -05:00
parent df3aa36e26
commit 381aec4ba4
17 changed files with 178 additions and 32 deletions

View File

@@ -4,17 +4,18 @@ const languages = ['terrace', 'json', 'yaml', 'toml', 'javascript', 'typescript'
module.exports = async (doc, rootLevel) => {
const { next, level, line, head, tail } = doc
const codeExample = {
type: 'CodeExample',
const node = {
type: head(),
languages: {}
}
while (await next(rootLevel)) {
const languageLevel = level()
if (languages.includes(head())) {
codeExample.languages[head()] = await contentAsText(doc, languageLevel)
node.languages[head()] = await contentAsText(doc, languageLevel)
}
}
return codeExample
return node
}

View File

@@ -0,0 +1,16 @@
module.exports = async function (doc, rootLevel) {
const { next, line, match, tail, level, head } = doc
const node = {
type: head(),
level: tail().split(' ')[0],
text: tail().split(' ').slice(1).join(' '),
class: ''
}
while (await next(rootLevel)) {
if (match('class')) node.class = tail()
}
return node
}

10
docs/parser/nodes/Icon.js Normal file
View File

@@ -0,0 +1,10 @@
module.exports = async function (doc) {
const { head, tail } = doc
const node = {
type: head(),
icon: tail()
}
return node
}

View File

@@ -1,9 +1,9 @@
const { contentAsText } = require('../helpers.js')
const marked = require('marked')
module.exports = async (...args) => {
module.exports = async (doc, rootLevel) => {
return {
type: `Markdown`,
text: marked.parse(await contentAsText(...args))
type: doc.head(),
text: marked.parse(await contentAsText(doc, rootLevel))
}
}

View File

@@ -1,15 +1,17 @@
const parseNode = require('./Node.js')
module.exports.Div = parseNode
module.exports.Section = async (doc, rootLevel) => {
const variant = doc.tail()
return { variant, ...(await parseNode(doc, rootLevel)) }
}
module.exports.Header = require('./Header.js')
module.exports.Button = require('./Button.js')
module.exports.Icon = require('./Icon.js')
module.exports.Div = parseNode
module.exports.Markdown = require('./Markdown.js')
module.exports.CodeExample = require('./CodeExample.js')
module.exports.Logo = doc => ({
type: `Logo`,
variant: doc.tail() || 'light'
})
module.exports.Markdown = require('./Markdown.js')
module.exports.CodeExample = require('./CodeExample.js')
module.exports.Button = require('./Button.js')