opencode-mermaid-renderer 0.0.1 → 0.0.2
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/index.ts +17 -2
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -10,6 +10,10 @@ const MERMAID_BLOCK_REGEX = /```mermaid\n([\s\S]*?)```/g
|
|
|
10
10
|
/**
|
|
11
11
|
* OpenCode plugin that renders mermaid diagrams as ASCII art
|
|
12
12
|
*
|
|
13
|
+
* Features:
|
|
14
|
+
* - Renders diagrams inline as ASCII art (shown by default)
|
|
15
|
+
* - Preserves original mermaid source in expandable <details> section
|
|
16
|
+
*
|
|
13
17
|
* Supported diagram types:
|
|
14
18
|
* - Flowcharts (graph TD/LR/BT/RL)
|
|
15
19
|
* - State diagrams (stateDiagram-v2)
|
|
@@ -49,14 +53,25 @@ function renderMermaidBlocks(text: string): string {
|
|
|
49
53
|
|
|
50
54
|
/**
|
|
51
55
|
* Render a single mermaid diagram to ASCII
|
|
56
|
+
* Shows rendered diagram by default with expandable source code
|
|
52
57
|
* On error, returns the original code block with an error comment
|
|
53
58
|
*/
|
|
54
59
|
function renderSingleBlock(mermaidCode: string): string {
|
|
55
60
|
try {
|
|
56
61
|
const ascii = renderMermaidAscii(mermaidCode)
|
|
57
62
|
|
|
58
|
-
//
|
|
59
|
-
return
|
|
63
|
+
// Show rendered diagram with expandable source code section
|
|
64
|
+
return (
|
|
65
|
+
"```\n" +
|
|
66
|
+
ascii +
|
|
67
|
+
"\n```\n\n" +
|
|
68
|
+
"<details>\n" +
|
|
69
|
+
"<summary>View Mermaid Source</summary>\n\n" +
|
|
70
|
+
"```mermaid\n" +
|
|
71
|
+
mermaidCode +
|
|
72
|
+
"\n```\n\n" +
|
|
73
|
+
"</details>"
|
|
74
|
+
)
|
|
60
75
|
} catch (error) {
|
|
61
76
|
// Keep original mermaid block and add error as comment
|
|
62
77
|
const errorMessage = (error as Error).message || "Unknown error"
|