radiant-docs 0.1.16 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "radiant-docs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"description": "CLI tool for previewing Radiant documentation locally",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"bundle-template": "node scripts/bundle-template.js",
|
|
11
11
|
"build": "tsup src/index.ts --format esm --clean && npm run bundle-template",
|
|
12
12
|
"dev": "tsup src/index.ts --format esm --watch",
|
|
13
|
-
"prepublishOnly": "npm run build
|
|
14
|
-
"
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
|
+
"release": "npm version patch && npm publish"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"chokidar": "^4.0.3",
|
|
@@ -100,6 +100,40 @@ const isInitiallyExpanded = shouldShowAllCode || totalLineCount <= visibleLines;
|
|
|
100
100
|
</div>
|
|
101
101
|
|
|
102
102
|
<style>
|
|
103
|
+
.rd-component-preview :global([data-rd-preview-heading="true"]) {
|
|
104
|
+
color: var(--tw-prose-headings, currentColor);
|
|
105
|
+
font-weight: 600;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.rd-component-preview :global([data-rd-preview-heading-level="2"]) {
|
|
109
|
+
font-size: 1.5em;
|
|
110
|
+
line-height: 1.3333333;
|
|
111
|
+
margin-top: 2em;
|
|
112
|
+
margin-bottom: 1em;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.rd-component-preview :global([data-rd-preview-heading-level="3"]) {
|
|
116
|
+
font-size: 1.25em;
|
|
117
|
+
line-height: 1.6;
|
|
118
|
+
margin-top: 1.6em;
|
|
119
|
+
margin-bottom: 0.6em;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.rd-component-preview :global([data-rd-preview-heading-level="4"]) {
|
|
123
|
+
font-size: 1em;
|
|
124
|
+
line-height: 1.5;
|
|
125
|
+
margin-top: 1.5em;
|
|
126
|
+
margin-bottom: 0.5em;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.rd-component-preview :global([data-rd-preview-heading-level="5"]),
|
|
130
|
+
.rd-component-preview :global([data-rd-preview-heading-level="6"]) {
|
|
131
|
+
font-size: 0.875em;
|
|
132
|
+
line-height: 1.5714286;
|
|
133
|
+
margin-top: 1.4285714em;
|
|
134
|
+
margin-bottom: 0.5714286em;
|
|
135
|
+
}
|
|
136
|
+
|
|
103
137
|
.rd-component-preview :global(.group\/prose-code) {
|
|
104
138
|
margin-top: 0 !important;
|
|
105
139
|
margin-bottom: 0 !important;
|
|
@@ -56,6 +56,17 @@ type MdxJsxTextElementNode = {
|
|
|
56
56
|
children?: unknown[];
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
type HeadingNode = {
|
|
60
|
+
type: "heading";
|
|
61
|
+
depth?: number;
|
|
62
|
+
children?: unknown[];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
type NodeWithChildren = {
|
|
66
|
+
type?: string;
|
|
67
|
+
children?: unknown[];
|
|
68
|
+
};
|
|
69
|
+
|
|
59
70
|
const COMPONENT_PREVIEW_NAME = "ComponentPreview";
|
|
60
71
|
const COMPONENT_PREVIEW_BLOCK_NAME = "ComponentPreviewBlock";
|
|
61
72
|
const COMPONENT_PREVIEW_LANGUAGES = new Set(["jsx", "tsx", "mdx"]);
|
|
@@ -192,44 +203,81 @@ function readBooleanAttribute(
|
|
|
192
203
|
return parseBooleanAttributeValue(attribute.value);
|
|
193
204
|
}
|
|
194
205
|
|
|
195
|
-
function
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
206
|
+
function normalizePreviewHeadingDepth(depth: number | undefined): number {
|
|
207
|
+
if (depth === 1) return 2;
|
|
208
|
+
if (depth === 2 || depth === 3 || depth === 4 || depth === 5 || depth === 6) {
|
|
209
|
+
return depth;
|
|
210
|
+
}
|
|
211
|
+
return 2;
|
|
212
|
+
}
|
|
200
213
|
|
|
201
|
-
|
|
214
|
+
function transformPreviewChildren(children: unknown[] | undefined): unknown[] {
|
|
215
|
+
if (!Array.isArray(children)) return [];
|
|
216
|
+
return children.map((child) => transformPreviewNode(child));
|
|
217
|
+
}
|
|
202
218
|
|
|
219
|
+
function transformPreviewNode(node: unknown): unknown {
|
|
203
220
|
// Promote a single inline MDX JSX node into flow-level JSX so the preview
|
|
204
221
|
// renders block components (e.g. <Callout />) as expected.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
222
|
+
const headingNode = node as HeadingNode;
|
|
223
|
+
if (headingNode.type === "heading") {
|
|
224
|
+
const depth = normalizePreviewHeadingDepth(headingNode.depth);
|
|
225
|
+
return {
|
|
226
|
+
type: "mdxJsxFlowElement",
|
|
227
|
+
name: "div",
|
|
228
|
+
attributes: [
|
|
229
|
+
createAttribute("data-rd-preview-heading", "true"),
|
|
230
|
+
createAttribute("data-rd-preview-heading-level", String(depth)),
|
|
231
|
+
createAttribute("role", "heading"),
|
|
232
|
+
createAttribute("aria-level", String(depth)),
|
|
233
|
+
],
|
|
234
|
+
children: transformPreviewChildren(headingNode.children),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
214
237
|
|
|
238
|
+
const paragraphNode = node as ParagraphNode;
|
|
239
|
+
if (
|
|
240
|
+
paragraphNode.type === "paragraph" &&
|
|
241
|
+
Array.isArray(paragraphNode.children) &&
|
|
242
|
+
paragraphNode.children.length === 1
|
|
243
|
+
) {
|
|
215
244
|
const onlyChild = paragraphNode.children[0] as MdxJsxTextElementNode;
|
|
216
245
|
if (
|
|
217
|
-
onlyChild.type
|
|
218
|
-
typeof onlyChild.name
|
|
219
|
-
onlyChild.name.trim().length
|
|
246
|
+
onlyChild.type === "mdxJsxTextElement" &&
|
|
247
|
+
typeof onlyChild.name === "string" &&
|
|
248
|
+
onlyChild.name.trim().length > 0
|
|
220
249
|
) {
|
|
221
|
-
return
|
|
250
|
+
return {
|
|
251
|
+
type: "mdxJsxFlowElement",
|
|
252
|
+
name: onlyChild.name,
|
|
253
|
+
attributes: Array.isArray(onlyChild.attributes)
|
|
254
|
+
? onlyChild.attributes
|
|
255
|
+
: [],
|
|
256
|
+
children: transformPreviewChildren(onlyChild.children),
|
|
257
|
+
};
|
|
222
258
|
}
|
|
259
|
+
}
|
|
223
260
|
|
|
261
|
+
const nodeWithChildren = node as NodeWithChildren;
|
|
262
|
+
if (Array.isArray(nodeWithChildren.children)) {
|
|
224
263
|
return {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
attributes: Array.isArray(onlyChild.attributes)
|
|
228
|
-
? onlyChild.attributes
|
|
229
|
-
: [],
|
|
230
|
-
children: Array.isArray(onlyChild.children) ? onlyChild.children : [],
|
|
264
|
+
...nodeWithChildren,
|
|
265
|
+
children: transformPreviewChildren(nodeWithChildren.children),
|
|
231
266
|
};
|
|
232
|
-
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return node;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function parseComponentPreviewChildren(rawCode: string): unknown[] {
|
|
273
|
+
const parsedTree = fromMarkdown(rawCode, {
|
|
274
|
+
extensions: [gfm(), mdxjs()],
|
|
275
|
+
mdastExtensions: [gfmFromMarkdown(), mdxFromMarkdown()],
|
|
276
|
+
}) as Root;
|
|
277
|
+
|
|
278
|
+
return transformPreviewChildren(
|
|
279
|
+
Array.isArray(parsedTree.children) ? parsedTree.children : [],
|
|
280
|
+
);
|
|
233
281
|
}
|
|
234
282
|
|
|
235
283
|
function getNearestMdxJsxFlowElementName(
|
|
@@ -145,6 +145,15 @@
|
|
|
145
145
|
@apply px-1 py-px bg-neutral-100/90 text-neutral-600 rounded-md font-mono font-medium border border-neutral-200/80 after:hidden before:hidden;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
/* Keep nested blockquote content flush with the quote container edges */
|
|
149
|
+
:is(.prose, .prose-rules) blockquote > :first-child {
|
|
150
|
+
margin-top: 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
:is(.prose, .prose-rules) blockquote > :last-child {
|
|
154
|
+
margin-bottom: 0;
|
|
155
|
+
}
|
|
156
|
+
|
|
148
157
|
/* <ol> numbers */
|
|
149
158
|
.prose :where(ol > li)::marker {
|
|
150
159
|
@apply font-medium;
|