From d3893f5e3a07500397f20308953fb3bfe84cab11 Mon Sep 17 00:00:00 2001 From: lew Date: Sat, 24 Jan 2026 02:01:10 +0000 Subject: [PATCH] feat: labelled grids added to remark --- apps/blog/src/plugins/remark-aside.ts | 32 ++++++++++++++++++++++++++- apps/blog/src/styles/global.css | 26 ++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/apps/blog/src/plugins/remark-aside.ts b/apps/blog/src/plugins/remark-aside.ts index 847c25c..871cca5 100644 --- a/apps/blog/src/plugins/remark-aside.ts +++ b/apps/blog/src/plugins/remark-aside.ts @@ -1,14 +1,44 @@ import { visit } from 'unist-util-visit'; import type { Root } from 'mdast'; +function nodeToText(node: any): string { + if (node.type === 'text') return node.value; + if (node.children) return node.children.map(nodeToText).join(''); + return ''; +} + export default function remarkAside() { return (tree: Root) => { visit(tree, ['textDirective', 'leafDirective'], (node: any) => { if (node.name !== 'left' && node.name !== 'right') return; - const data = node.data || (node.data = {}); data.hName = 'span'; data.hProperties = { className: [node.name] }; }); + + visit(tree, 'containerDirective', (node: any) => { + if (node.name !== 'grid') return; + let html = '
'; + for (const child of node.children) { + if (child.data?.directiveLabel) continue; + if (child.type === 'paragraph' && child.children?.length > 0) { + const firstChild = child.children[0]; + if (firstChild?.type === 'textDirective' && firstChild.name === 'label') { + const labelText = nodeToText(firstChild); + const contentText = child.children + .slice(1) + .map(nodeToText) + .join('') + .replace(/^\s+/, ''); + html += `${labelText}`; + html += `
${contentText}
`; + } + } + } + html += '
'; + node.type = 'html'; + node.value = html; + delete node.children; + }); }; } diff --git a/apps/blog/src/styles/global.css b/apps/blog/src/styles/global.css index 38acacb..e7f7f52 100644 --- a/apps/blog/src/styles/global.css +++ b/apps/blog/src/styles/global.css @@ -34,6 +34,32 @@ h1, h2, h3, h4, h5, h6 { } } +div.grid { + display: grid; + grid-template-columns: minmax(2.375rem, min-content) 1fr; + gap: 0.625rem 0.75rem; + row-gap: 0.625rem; + line-height: 1.25; + margin-bottom: 2rem; + margin-top: 0; +} + +div.grid .label { + display: block; + margin-top: 0.375rem; + margin-block: 0; + white-space: nowrap; + font-variant-numeric: tabular-nums; + line-height: 1.4; + text-align: right; + color: #888; + font-style: italic; +} + +div.grid .content { + display: block; +} + details { margin: 1rem 0; }