First pass at hero section.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
|
||||
module.exports.contentAsText = async function(doc, rootLevel) {
|
||||
module.exports.contentAsText = async function(doc, rootLevel, includeCurrent = false) {
|
||||
const { level, next, line, head } = doc
|
||||
const linesAsArray = []
|
||||
|
||||
let contentDepth = -1
|
||||
if (includeCurrent) linesAsArray.push(line())
|
||||
let contentDepth = includeCurrent ? level() : -1
|
||||
|
||||
while(await next(rootLevel)) {
|
||||
if (contentDepth === -1 && !!line()) contentDepth = level()
|
||||
|
||||
23
docs/parser/nodes/Button.js
Normal file
23
docs/parser/nodes/Button.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const { contentAsText } = require('../helpers.js')
|
||||
|
||||
module.exports = async function (doc, rootLevel) {
|
||||
const { next, line, match, tail, level, head } = doc
|
||||
|
||||
const node = {
|
||||
type: head(),
|
||||
variant: tail() || 'neutral',
|
||||
class: '',
|
||||
href: '',
|
||||
text: ''
|
||||
}
|
||||
|
||||
while (await next(rootLevel)) {
|
||||
if (match('class')) node.class = tail()
|
||||
else if (match('href')) node.href = tail()
|
||||
else {
|
||||
node.text = await contentAsText(doc, rootLevel, true)
|
||||
}
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
@@ -1,7 +1,15 @@
|
||||
const parseNode = require('./Node.js')
|
||||
|
||||
module.exports.Section = parseNode
|
||||
module.exports.Section = async (doc, rootLevel) => {
|
||||
const variant = doc.tail()
|
||||
return { variant, ...(await parseNode(doc, rootLevel)) }
|
||||
}
|
||||
|
||||
module.exports.Div = parseNode
|
||||
module.exports.Logo = doc => ({ type: `Logo` })
|
||||
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')
|
||||
|
||||
Reference in New Issue
Block a user