diff --git a/docs/parser/helpers.js b/docs/parser/helpers.js index 1c71356..802d06a 100644 --- a/docs/parser/helpers.js +++ b/docs/parser/helpers.js @@ -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() diff --git a/docs/parser/nodes/Button.js b/docs/parser/nodes/Button.js new file mode 100644 index 0000000..c7e0941 --- /dev/null +++ b/docs/parser/nodes/Button.js @@ -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 +} diff --git a/docs/parser/nodes/index.js b/docs/parser/nodes/index.js index 6b0d086..d986170 100644 --- a/docs/parser/nodes/index.js +++ b/docs/parser/nodes/index.js @@ -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') diff --git a/docs/src/_includes/layout.njk b/docs/src/_includes/layout.njk index 523d100..6b47b0c 100644 --- a/docs/src/_includes/layout.njk +++ b/docs/src/_includes/layout.njk @@ -12,6 +12,7 @@
+ {{ Node('Navbar') }} {% for child in children %} {{ Node(child.type, child) }} {% endfor %} diff --git a/docs/src/_includes/nodes/Button.njk b/docs/src/_includes/nodes/Button.njk new file mode 100644 index 0000000..a0f88cf --- /dev/null +++ b/docs/src/_includes/nodes/Button.njk @@ -0,0 +1,14 @@ +{% set commonClasses = "px-12 py-3 text-white rounded-md w-auto" %} +{% macro render(node) %} + + {{ node.text | safe }} + +{% endmacro %} diff --git a/docs/src/_includes/nodes/CodeExample.njk b/docs/src/_includes/nodes/CodeExample.njk index f7f047b..e051dad 100644 --- a/docs/src/_includes/nodes/CodeExample.njk +++ b/docs/src/_includes/nodes/CodeExample.njk @@ -26,7 +26,7 @@ set languageMeta = { {{ languageMeta[id].name }}{{ code | highlight(id) | safe }}diff --git a/docs/src/_includes/nodes/Logo.njk b/docs/src/_includes/nodes/Logo.njk index 392f957..ebf3900 100644 --- a/docs/src/_includes/nodes/Logo.njk +++ b/docs/src/_includes/nodes/Logo.njk @@ -1,2 +1,13 @@ {% macro render(node) %} + {% if node.variant != 'small' %} +