prev-cli 0.1.6 → 0.1.7
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 +8 -2
- package/package.json +1 -1
- package/src/theme/Layout.tsx +23 -18
package/dist/cli.js
CHANGED
|
@@ -387,7 +387,10 @@ async function createViteConfig(options) {
|
|
|
387
387
|
"@prev/theme": path4.join(srcRoot2, "theme"),
|
|
388
388
|
react: path4.join(cliNodeModules, "react"),
|
|
389
389
|
"react-dom": path4.join(cliNodeModules, "react-dom"),
|
|
390
|
-
"react-router-dom": path4.join(cliNodeModules, "react-router-dom")
|
|
390
|
+
"react-router-dom": path4.join(cliNodeModules, "react-router-dom"),
|
|
391
|
+
mermaid: path4.join(cliNodeModules, "mermaid"),
|
|
392
|
+
dayjs: path4.join(cliNodeModules, "dayjs"),
|
|
393
|
+
"@terrastruct/d2": path4.join(cliNodeModules, "@terrastruct/d2")
|
|
391
394
|
}
|
|
392
395
|
},
|
|
393
396
|
optimizeDeps: {
|
|
@@ -398,7 +401,10 @@ async function createViteConfig(options) {
|
|
|
398
401
|
"react-dom/client",
|
|
399
402
|
"react-router-dom",
|
|
400
403
|
"react/jsx-runtime",
|
|
401
|
-
"react/jsx-dev-runtime"
|
|
404
|
+
"react/jsx-dev-runtime",
|
|
405
|
+
"mermaid",
|
|
406
|
+
"dayjs",
|
|
407
|
+
"@terrastruct/d2"
|
|
402
408
|
],
|
|
403
409
|
exclude: [
|
|
404
410
|
"clsx",
|
package/package.json
CHANGED
package/src/theme/Layout.tsx
CHANGED
|
@@ -37,28 +37,33 @@ async function renderD2Diagrams() {
|
|
|
37
37
|
const codeBlocks = document.querySelectorAll('code.language-d2, code.hljs.language-d2')
|
|
38
38
|
if (codeBlocks.length === 0) return
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
try {
|
|
41
|
+
const d2Module = await import('@terrastruct/d2')
|
|
42
|
+
const { D2 } = d2Module
|
|
43
|
+
const d2 = new D2()
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
for (const block of codeBlocks) {
|
|
46
|
+
const pre = block.parentElement as HTMLElement
|
|
47
|
+
if (!pre || pre.dataset.rendered) continue
|
|
48
|
+
pre.dataset.rendered = 'true'
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
const code = block.textContent || ''
|
|
51
|
+
const container = document.createElement('div')
|
|
52
|
+
container.className = 'd2-diagram'
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
try {
|
|
55
|
+
const result = await d2.compile(code)
|
|
56
|
+
const svg = await d2.render(result.diagram, result.renderOptions)
|
|
57
|
+
container.innerHTML = svg
|
|
58
|
+
// Hide original instead of replacing (avoids React DOM conflicts)
|
|
59
|
+
pre.style.display = 'none'
|
|
60
|
+
pre.insertAdjacentElement('afterend', container)
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error('D2 render error:', e)
|
|
63
|
+
}
|
|
61
64
|
}
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.error('D2 library load error:', e)
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
|