prev-cli 0.1.3 → 0.1.5
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/dist/cli.js +1 -5
- package/package.json +2 -2
- package/src/theme/Layout.tsx +77 -2
package/dist/cli.js
CHANGED
|
@@ -12,7 +12,6 @@ import tailwindcss from "@tailwindcss/vite";
|
|
|
12
12
|
import mdx from "@mdx-js/rollup";
|
|
13
13
|
import remarkGfm from "remark-gfm";
|
|
14
14
|
import rehypeHighlight from "rehype-highlight";
|
|
15
|
-
import rehypeMermaid from "rehype-mermaid";
|
|
16
15
|
import path4 from "path";
|
|
17
16
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
18
17
|
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
@@ -319,10 +318,7 @@ async function createViteConfig(options) {
|
|
|
319
318
|
plugins: [
|
|
320
319
|
mdx({
|
|
321
320
|
remarkPlugins: [remarkGfm],
|
|
322
|
-
rehypePlugins: [
|
|
323
|
-
rehypeHighlight,
|
|
324
|
-
[rehypeMermaid, { strategy: "pre-mermaid" }]
|
|
325
|
-
]
|
|
321
|
+
rehypePlugins: [rehypeHighlight]
|
|
326
322
|
}),
|
|
327
323
|
react(),
|
|
328
324
|
tailwindcss(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prev-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Transform MDX directories into beautiful documentation websites",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@mdx-js/rollup": "^3.0.0",
|
|
44
|
+
"@terrastruct/d2": "^0.1.33",
|
|
44
45
|
"@tailwindcss/vite": "^4.0.0",
|
|
45
46
|
"@vitejs/plugin-react-swc": "^4.2.2",
|
|
46
47
|
"class-variance-authority": "^0.7.0",
|
|
@@ -52,7 +53,6 @@
|
|
|
52
53
|
"react-dom": "^19.0.0",
|
|
53
54
|
"react-router-dom": "^7.0.0",
|
|
54
55
|
"rehype-highlight": "^7.0.0",
|
|
55
|
-
"rehype-mermaid": "^3.0.0",
|
|
56
56
|
"remark-gfm": "^4.0.0",
|
|
57
57
|
"rolldown-vite": "^7.3.0",
|
|
58
58
|
"tailwind-merge": "^2.5.0",
|
package/src/theme/Layout.tsx
CHANGED
|
@@ -1,9 +1,84 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { Outlet } from 'react-router-dom'
|
|
1
|
+
import React, { useEffect } from 'react'
|
|
2
|
+
import { Outlet, useLocation } from 'react-router-dom'
|
|
3
3
|
import { Sidebar } from './Sidebar'
|
|
4
4
|
import './styles.css'
|
|
5
5
|
|
|
6
|
+
// Lazy-load and render mermaid diagrams
|
|
7
|
+
async function renderMermaidDiagrams() {
|
|
8
|
+
const codeBlocks = document.querySelectorAll('code.language-mermaid, code.hljs.language-mermaid')
|
|
9
|
+
if (codeBlocks.length === 0) return
|
|
10
|
+
|
|
11
|
+
const mermaid = await import('mermaid')
|
|
12
|
+
mermaid.default.initialize({ startOnLoad: false, theme: 'neutral' })
|
|
13
|
+
|
|
14
|
+
for (const block of codeBlocks) {
|
|
15
|
+
const pre = block.parentElement as HTMLElement
|
|
16
|
+
if (!pre || pre.dataset.rendered) continue
|
|
17
|
+
pre.dataset.rendered = 'true'
|
|
18
|
+
|
|
19
|
+
const code = block.textContent || ''
|
|
20
|
+
const container = document.createElement('div')
|
|
21
|
+
container.className = 'mermaid-diagram'
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const { svg } = await mermaid.default.render(`mermaid-${Math.random().toString(36).slice(2)}`, code)
|
|
25
|
+
container.innerHTML = svg
|
|
26
|
+
// Hide original instead of replacing (avoids React DOM conflicts)
|
|
27
|
+
pre.style.display = 'none'
|
|
28
|
+
pre.insertAdjacentElement('afterend', container)
|
|
29
|
+
} catch (e) {
|
|
30
|
+
console.error('Mermaid render error:', e)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Lazy-load and render D2 diagrams
|
|
36
|
+
async function renderD2Diagrams() {
|
|
37
|
+
const codeBlocks = document.querySelectorAll('code.language-d2, code.hljs.language-d2')
|
|
38
|
+
if (codeBlocks.length === 0) return
|
|
39
|
+
|
|
40
|
+
const { D2 } = await import('@terrastruct/d2')
|
|
41
|
+
const d2 = new D2()
|
|
42
|
+
|
|
43
|
+
for (const block of codeBlocks) {
|
|
44
|
+
const pre = block.parentElement as HTMLElement
|
|
45
|
+
if (!pre || pre.dataset.rendered) continue
|
|
46
|
+
pre.dataset.rendered = 'true'
|
|
47
|
+
|
|
48
|
+
const code = block.textContent || ''
|
|
49
|
+
const container = document.createElement('div')
|
|
50
|
+
container.className = 'd2-diagram'
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const result = await d2.compile(code)
|
|
54
|
+
const svg = await d2.render(result.diagram)
|
|
55
|
+
container.innerHTML = svg
|
|
56
|
+
// Hide original instead of replacing (avoids React DOM conflicts)
|
|
57
|
+
pre.style.display = 'none'
|
|
58
|
+
pre.insertAdjacentElement('afterend', container)
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.error('D2 render error:', e)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Render all diagrams
|
|
66
|
+
async function renderDiagrams() {
|
|
67
|
+
await Promise.all([
|
|
68
|
+
renderMermaidDiagrams(),
|
|
69
|
+
renderD2Diagrams()
|
|
70
|
+
])
|
|
71
|
+
}
|
|
72
|
+
|
|
6
73
|
export function Layout() {
|
|
74
|
+
const location = useLocation()
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
// Render diagrams after content loads
|
|
78
|
+
const timer = setTimeout(renderDiagrams, 100)
|
|
79
|
+
return () => clearTimeout(timer)
|
|
80
|
+
}, [location.pathname])
|
|
81
|
+
|
|
7
82
|
return (
|
|
8
83
|
<div className="min-h-screen bg-background text-foreground">
|
|
9
84
|
<div className="flex">
|