@ootc/markdown 0.1.0 → 0.2.1
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/README.md +63 -9
- package/dist/CodeBlock-BquZ4WRk.cjs +2 -0
- package/dist/CodeBlock-DSwq2gw5.js +74 -0
- package/dist/MarkdownPreview-CMvzqhTd.js +7592 -0
- package/dist/MarkdownPreview-DfDx-wep.cjs +29 -0
- package/dist/code.cjs +1 -1
- package/dist/code.js +1 -1
- package/dist/components/code-block/CodeBlock.d.ts +7 -1
- package/dist/components/markdown/MarkdownPreview.d.ts +8 -2
- package/dist/components/markdown-editor/MarkdownEditor.d.ts +4 -1
- package/dist/css/MarkdownPreview.css +1 -1
- package/dist/css/plugin-mermaid.css +1 -0
- package/dist/editor.cjs +1 -1
- package/dist/editor.js +24 -22
- package/dist/index-BJZhyxD_.cjs +9 -0
- package/dist/index-DWVMYNE4.js +800 -0
- package/dist/index-HmBYTPyZ.js +1179 -0
- package/dist/index-jsnhzgIQ.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/jsx-runtime-DXgJBoQh.js +264 -0
- package/dist/jsx-runtime-nZSsnGb7.cjs +6 -0
- package/dist/plugin-highlight.cjs +1 -0
- package/dist/plugin-highlight.d.ts +3 -0
- package/dist/plugin-highlight.js +20 -0
- package/dist/plugin-katex.cjs +1 -0
- package/dist/plugin-katex.d.ts +3 -0
- package/dist/plugin-katex.js +12 -0
- package/dist/plugin-mermaid.cjs +1 -0
- package/dist/plugin-mermaid.css +1 -0
- package/dist/plugin-mermaid.d.ts +3 -0
- package/dist/plugin-mermaid.js +266 -0
- package/dist/plugins/highlight/index.d.ts +9 -0
- package/dist/plugins/katex/index.d.ts +12 -0
- package/dist/plugins/mermaid/MermaidDiagram.d.ts +7 -0
- package/dist/plugins/mermaid/index.d.ts +11 -0
- package/dist/plugins/types.d.ts +38 -0
- package/dist/preview.cjs +1 -1
- package/dist/preview.js +2 -2
- package/dist/style.css +1 -0
- package/package.json +49 -9
- package/dist/CodeBlock-B_Wu_RsD.cjs +0 -15
- package/dist/CodeBlock-BdSjKnRY.js +0 -2320
- package/dist/MarkdownPreview-CcTDfsgR.js +0 -20425
- package/dist/MarkdownPreview-imz9Sn8T.cjs +0 -295
- package/dist/_baseUniq-CmzFJAby.js +0 -477
- package/dist/_baseUniq-DTl9zLUk.cjs +0 -1
- package/dist/_commonjsHelpers-C6fGbg64.js +0 -6
- package/dist/_commonjsHelpers-DwGv2jUC.cjs +0 -1
- package/dist/arc-CLsgE_FO.cjs +0 -1
- package/dist/arc-DN0J6orD.js +0 -83
- package/dist/architectureDiagram-VXUJARFQ-C0Ox22_L.cjs +0 -36
- package/dist/architectureDiagram-VXUJARFQ-DD1WVkEB.js +0 -4662
- package/dist/blockDiagram-VD42YOAC-CXFrXgPY.cjs +0 -122
- package/dist/blockDiagram-VD42YOAC-DzX-b-6d.js +0 -2256
- package/dist/c4Diagram-YG6GDRKO-8tK3jTST.cjs +0 -10
- package/dist/c4Diagram-YG6GDRKO-CBo9Z0K5.js +0 -1580
- package/dist/channel-BWUNfmCm.js +0 -5
- package/dist/channel-MPm5yYgZ.cjs +0 -1
- package/dist/chunk-4BX2VUAB-BC2JrFPv.js +0 -8
- package/dist/chunk-4BX2VUAB-CVibkmL0.cjs +0 -1
- package/dist/chunk-55IACEB6-CzZUDZ70.js +0 -8
- package/dist/chunk-55IACEB6-DZnx2f_C.cjs +0 -1
- package/dist/chunk-B4BG7PRW-D0a_-7vE.cjs +0 -165
- package/dist/chunk-B4BG7PRW-DU2I6H4s.js +0 -1375
- package/dist/chunk-DI55MBZ5-BuXMX149.js +0 -1370
- package/dist/chunk-DI55MBZ5-Dr1JJdkm.cjs +0 -220
- package/dist/chunk-FMBD7UC4-DekHPa2I.cjs +0 -15
- package/dist/chunk-FMBD7UC4-RBUwxloo.js +0 -19
- package/dist/chunk-QN33PNHL-B6FGlZxV.js +0 -19
- package/dist/chunk-QN33PNHL-C1YRBk0j.cjs +0 -1
- package/dist/chunk-QZHKN3VN-BspjB43V.cjs +0 -1
- package/dist/chunk-QZHKN3VN-DR_oy1P1.js +0 -15
- package/dist/chunk-TZMSLE5B-BRck7Be7.cjs +0 -1
- package/dist/chunk-TZMSLE5B-pyixj0XE.js +0 -64
- package/dist/classDiagram-2ON5EDUG-Bvw7buPq.cjs +0 -1
- package/dist/classDiagram-2ON5EDUG-DK3Yvqrk.js +0 -16
- package/dist/classDiagram-v2-WZHVMYZB-Bvw7buPq.cjs +0 -1
- package/dist/classDiagram-v2-WZHVMYZB-DK3Yvqrk.js +0 -16
- package/dist/clone-D2V_3-x6.cjs +0 -1
- package/dist/clone-O816pP2i.js +0 -8
- package/dist/cose-bilkent-S5V4N54A-Bu3r2cA0.js +0 -2609
- package/dist/cose-bilkent-S5V4N54A-vz9hoE-P.cjs +0 -1
- package/dist/cytoscape.esm-CNUX3VTg.cjs +0 -321
- package/dist/cytoscape.esm-Cvf3sx9F.js +0 -18704
- package/dist/dagre-6UL2VRFP-D2UBESo6.cjs +0 -4
- package/dist/dagre-6UL2VRFP-DiBRZkX2.js +0 -443
- package/dist/defaultLocale-D7EN2tov.js +0 -171
- package/dist/defaultLocale-DIVzfLaQ.cjs +0 -1
- package/dist/diagram-PSM6KHXK-CUF6rC_5.js +0 -531
- package/dist/diagram-PSM6KHXK-uKXJz4r1.cjs +0 -24
- package/dist/diagram-QEK2KX5R-Da150Pqe.js +0 -217
- package/dist/diagram-QEK2KX5R-kQTDsG_x.cjs +0 -43
- package/dist/diagram-S2PKOQOG-C5ATPkHT.cjs +0 -24
- package/dist/diagram-S2PKOQOG-DA2RxLrC.js +0 -142
- package/dist/erDiagram-Q2GNP2WA-BsCdOw62.cjs +0 -60
- package/dist/erDiagram-Q2GNP2WA-YfCaUJjx.js +0 -841
- package/dist/flowDiagram-NV44I4VS-BG0KW3ec.cjs +0 -162
- package/dist/flowDiagram-NV44I4VS-D7WLCw1w.js +0 -1620
- package/dist/fonts/font-00b26ac8.woff2 +0 -0
- package/dist/fonts/font-036d4e95.woff2 +0 -0
- package/dist/fonts/font-07d8e303.ttf +0 -0
- package/dist/fonts/font-08ce98e5.ttf +0 -0
- package/dist/fonts/font-0cdd387c.woff2 +0 -0
- package/dist/fonts/font-0d85ae7c.ttf +0 -0
- package/dist/fonts/font-0f60d1b8.woff2 +0 -0
- package/dist/fonts/font-11e4dc8a.woff +0 -0
- package/dist/fonts/font-138ac28d.ttf +0 -0
- package/dist/fonts/font-1ae6bd74.woff +0 -0
- package/dist/fonts/font-1c67f068.ttf +0 -0
- package/dist/fonts/font-1e6f9579.ttf +0 -0
- package/dist/fonts/font-1ece03f7.ttf +0 -0
- package/dist/fonts/font-2014c523.woff +0 -0
- package/dist/fonts/font-30da91e8.woff +0 -0
- package/dist/fonts/font-3398dd02.woff +0 -0
- package/dist/fonts/font-3931dd81.ttf +0 -0
- package/dist/fonts/font-500e04d5.ttf +0 -0
- package/dist/fonts/font-51814d27.woff2 +0 -0
- package/dist/fonts/font-5d53e70a.woff2 +0 -0
- package/dist/fonts/font-5e28753b.woff +0 -0
- package/dist/fonts/font-68534840.ttf +0 -0
- package/dist/fonts/font-68e8c73e.woff2 +0 -0
- package/dist/fonts/font-6ab6b62e.woff +0 -0
- package/dist/fonts/font-6b47c401.woff2 +0 -0
- package/dist/fonts/font-70ee1f64.ttf +0 -0
- package/dist/fonts/font-71d517d6.woff2 +0 -0
- package/dist/fonts/font-73d59127.woff2 +0 -0
- package/dist/fonts/font-74444efd.woff2 +0 -0
- package/dist/fonts/font-7af58c5e.woff2 +0 -0
- package/dist/fonts/font-850c0af5.woff +0 -0
- package/dist/fonts/font-8a8d2445.woff +0 -0
- package/dist/fonts/font-9163df9c.ttf +0 -0
- package/dist/fonts/font-91ee6750.woff +0 -0
- package/dist/fonts/font-95b6d2f1.ttf +0 -0
- package/dist/fonts/font-97479ca6.woff2 +0 -0
- package/dist/fonts/font-99cd42a3.woff2 +0 -0
- package/dist/fonts/font-99f9c675.woff +0 -0
- package/dist/fonts/font-9be7ceb8.woff +0 -0
- package/dist/fonts/font-a4af7d41.woff2 +0 -0
- package/dist/fonts/font-a6b2099f.ttf +0 -0
- package/dist/fonts/font-a6f7ec0d.woff +0 -0
- package/dist/fonts/font-c2342cd8.woff2 +0 -0
- package/dist/fonts/font-c6368d87.woff +0 -0
- package/dist/fonts/font-c647367d.ttf +0 -0
- package/dist/fonts/font-c76c5d69.woff +0 -0
- package/dist/fonts/font-c943cc98.woff +0 -0
- package/dist/fonts/font-d0332f52.ttf +0 -0
- package/dist/fonts/font-d04c5421.woff2 +0 -0
- package/dist/fonts/font-d96cdf2b.woff +0 -0
- package/dist/fonts/font-dc47344d.woff2 +0 -0
- package/dist/fonts/font-de7701e4.woff2 +0 -0
- package/dist/fonts/font-e14fed02.woff +0 -0
- package/dist/fonts/font-e99ae511.woff2 +0 -0
- package/dist/fonts/font-ece03cfd.woff +0 -0
- package/dist/fonts/font-ed0b7437.ttf +0 -0
- package/dist/fonts/font-f01f3e87.ttf +0 -0
- package/dist/fonts/font-f1d6ef86.woff +0 -0
- package/dist/fonts/font-f36ea897.ttf +0 -0
- package/dist/fonts/font-f9377ab0.ttf +0 -0
- package/dist/ganttDiagram-JELNMOA3-BUA8njzO.cjs +0 -267
- package/dist/ganttDiagram-JELNMOA3-DSi9nt2I.js +0 -2671
- package/dist/gitGraphDiagram-NY62KEGX-C_9BbRSY.cjs +0 -65
- package/dist/gitGraphDiagram-NY62KEGX-Dr7HXTzE.js +0 -699
- package/dist/graph-Bd_3fIRG.cjs +0 -1
- package/dist/graph-DKQwyqwf.js +0 -381
- package/dist/index-BCrgOJjI.js +0 -38514
- package/dist/index-CPmaHYSB.cjs +0 -3920
- package/dist/infoDiagram-WHAUD3N6-LqpiKtaK.cjs +0 -2
- package/dist/infoDiagram-WHAUD3N6-cs5PUkbs.js +0 -24
- package/dist/init-CHZsXQcr.cjs +0 -1
- package/dist/init-DjUOC4st.js +0 -16
- package/dist/journeyDiagram-XKPGCS4Q-Uzzobun-.cjs +0 -139
- package/dist/journeyDiagram-XKPGCS4Q-Xh1PuBF3.js +0 -834
- package/dist/kanban-definition-3W4ZIXB7-BGNcniUS.cjs +0 -89
- package/dist/kanban-definition-3W4ZIXB7-BrCevkcy.js +0 -719
- package/dist/layout-C1JPMjBE.cjs +0 -1
- package/dist/layout-DCT3c1G0.js +0 -1441
- package/dist/linear-1V2v3HAv.js +0 -259
- package/dist/linear-BguQgdYO.cjs +0 -1
- package/dist/mermaid.core-B7U3vlPn.js +0 -15269
- package/dist/mermaid.core-Bi8BVJjR.cjs +0 -249
- package/dist/min-DxTpsh5w.js +0 -38
- package/dist/min-IWR7y697.cjs +0 -1
- package/dist/mindmap-definition-VGOIOE7T-Bo_AaB3S.cjs +0 -68
- package/dist/mindmap-definition-VGOIOE7T-y7MJRkKb.js +0 -784
- package/dist/ordinal-B6-f3MAq.js +0 -61
- package/dist/ordinal-CagbB1m8.cjs +0 -1
- package/dist/pieDiagram-ADFJNKIX-B3MwEiQQ.cjs +0 -30
- package/dist/pieDiagram-ADFJNKIX-Dat2qDxW.js +0 -161
- package/dist/quadrantDiagram-AYHSOK5B-BPI6p5FS.js +0 -1022
- package/dist/quadrantDiagram-AYHSOK5B-DJPxR-7E.cjs +0 -7
- package/dist/requirementDiagram-UZGBJVZJ-BjJSqttW.js +0 -850
- package/dist/requirementDiagram-UZGBJVZJ-CmIwuHrt.cjs +0 -64
- package/dist/sankeyDiagram-TZEHDZUN-CLroAHms.cjs +0 -10
- package/dist/sankeyDiagram-TZEHDZUN-jMmEhl5n.js +0 -810
- package/dist/sequenceDiagram-WL72ISMW-BVZMWdMT.cjs +0 -145
- package/dist/sequenceDiagram-WL72ISMW-CqGWWpuM.js +0 -2511
- package/dist/stateDiagram-FKZM4ZOC-DYHXgEjX.cjs +0 -1
- package/dist/stateDiagram-FKZM4ZOC-h1ovMUWJ.js +0 -263
- package/dist/stateDiagram-v2-4FDKWEC3-Di23ehqW.cjs +0 -1
- package/dist/stateDiagram-v2-4FDKWEC3-GGpuzcKb.js +0 -16
- package/dist/timeline-definition-IT6M3QCI-DC_axTKs.js +0 -795
- package/dist/timeline-definition-IT6M3QCI-DYx-RdCk.cjs +0 -61
- package/dist/treemap-KMMF4GRG-B-9lqUoG.js +0 -14192
- package/dist/treemap-KMMF4GRG-EXqF5Yz1.cjs +0 -128
- package/dist/xychartDiagram-PRI3JC2R-CedpkbBs.cjs +0 -7
- package/dist/xychartDiagram-PRI3JC2R-gFwsBSHN.js +0 -1340
package/README.md
CHANGED
|
@@ -8,6 +8,18 @@ React components for markdown rendering and editing.
|
|
|
8
8
|
pnpm add @ootc/markdown
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
The heavy features are opt-in and ship as **optional peer dependencies** — install only
|
|
12
|
+
what you use:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add mermaid # diagrams
|
|
16
|
+
pnpm add @wooorm/starry-night # syntax highlighting
|
|
17
|
+
pnpm add katex remark-math rehype-katex # math
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Nothing above is required. Without them the preview still renders GFM markdown; code
|
|
21
|
+
fences render unhighlighted and ```mermaid fences render as ordinary code blocks.
|
|
22
|
+
|
|
11
23
|
## Usage
|
|
12
24
|
|
|
13
25
|
```tsx
|
|
@@ -16,12 +28,20 @@ import {MarkdownPreview} from '@ootc/markdown/preview';
|
|
|
16
28
|
import {MarkdownEditor} from '@ootc/markdown/editor';
|
|
17
29
|
import '@ootc/markdown/style.css';
|
|
18
30
|
|
|
31
|
+
// opt in to only what you need
|
|
32
|
+
import {mermaidPlugin} from '@ootc/markdown/plugin-mermaid';
|
|
33
|
+
import {highlightPlugin} from '@ootc/markdown/plugin-highlight';
|
|
34
|
+
import {katexPlugin} from '@ootc/markdown/plugin-katex';
|
|
35
|
+
import '@ootc/markdown/plugin-mermaid.css';
|
|
36
|
+
|
|
37
|
+
const plugins = [mermaidPlugin, highlightPlugin, katexPlugin];
|
|
38
|
+
|
|
19
39
|
export default function Demo() {
|
|
20
40
|
return (
|
|
21
41
|
<div style={{display: 'grid', gap: 16}}>
|
|
22
|
-
<MarkdownPreview content={'# Hello\n\n```ts\nconst x = 1;\n```'} />
|
|
23
|
-
<CodeBlock code={'console.log("hi")'} language="ts" />
|
|
24
|
-
<MarkdownEditor value={'# Edit me'} onChange={() => {}} />
|
|
42
|
+
<MarkdownPreview content={'# Hello\n\n```ts\nconst x = 1;\n```'} plugins={plugins} />
|
|
43
|
+
<CodeBlock code={'console.log("hi")'} language="ts" plugins={[highlightPlugin]} />
|
|
44
|
+
<MarkdownEditor value={'# Edit me'} onChange={() => {}} plugins={plugins} />
|
|
25
45
|
</div>
|
|
26
46
|
);
|
|
27
47
|
}
|
|
@@ -33,6 +53,9 @@ export default function Demo() {
|
|
|
33
53
|
- `@ootc/markdown/code`: `CodeBlock`
|
|
34
54
|
- `@ootc/markdown/preview`: `MarkdownPreview`
|
|
35
55
|
- `@ootc/markdown/editor`: `MarkdownEditor`
|
|
56
|
+
- `@ootc/markdown/plugin-mermaid`: `mermaidPlugin` — renders ```mermaid fences as diagrams
|
|
57
|
+
- `@ootc/markdown/plugin-highlight`: `highlightPlugin` — syntax highlighting via starry-night
|
|
58
|
+
- `@ootc/markdown/plugin-katex`: `katexPlugin` — `$inline$` and `$$display$$` math
|
|
36
59
|
|
|
37
60
|
Each entrypoint has both a named and a default export, so it works with `React.lazy` directly:
|
|
38
61
|
|
|
@@ -51,13 +74,36 @@ export function Doc({content}: {content: string}) {
|
|
|
51
74
|
}
|
|
52
75
|
```
|
|
53
76
|
|
|
54
|
-
###
|
|
77
|
+
### Opt-in dependencies
|
|
78
|
+
|
|
79
|
+
The three heavy dependencies are **not bundled** into this package. Each lives behind
|
|
80
|
+
its own entrypoint and is an optional peer dependency, so a bundler can prove it
|
|
81
|
+
unreachable when you don't pass the plugin:
|
|
55
82
|
|
|
56
|
-
|
|
83
|
+
| Plugin | Peer dependency | Cost when opted in |
|
|
84
|
+
| --- | --- | --- |
|
|
85
|
+
| `plugin-mermaid` | `mermaid` | ~2.8 MB, loaded lazily on the first diagram |
|
|
86
|
+
| `plugin-highlight` | `@wooorm/starry-night` | ~1.7 MB of grammars, loaded lazily on the first code block |
|
|
87
|
+
| `plugin-katex` | `katex`, `remark-math`, `rehype-katex` | eager; KaTeX fonts load as needed |
|
|
57
88
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
89
|
+
Mermaid and the highlighting grammars stay behind dynamic imports even when enabled,
|
|
90
|
+
so they never enter your initial bundle. KaTeX loads eagerly with the plugin because
|
|
91
|
+
it participates in the markdown pipeline itself.
|
|
92
|
+
|
|
93
|
+
Plugins are consulted in array order; the first to claim a fence wins.
|
|
94
|
+
|
|
95
|
+
### Migrating from 0.1.x
|
|
96
|
+
|
|
97
|
+
`0.2.0` makes diagrams, highlighting and math opt-in. Previously they were always on.
|
|
98
|
+
To restore the old behavior, install the peers and pass all three plugins:
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
import {mermaidPlugin} from '@ootc/markdown/plugin-mermaid';
|
|
102
|
+
import {highlightPlugin} from '@ootc/markdown/plugin-highlight';
|
|
103
|
+
import {katexPlugin} from '@ootc/markdown/plugin-katex';
|
|
104
|
+
|
|
105
|
+
<MarkdownPreview content={md} plugins={[mermaidPlugin, highlightPlugin, katexPlugin]} />
|
|
106
|
+
```
|
|
61
107
|
|
|
62
108
|
### MarkdownPreview
|
|
63
109
|
|
|
@@ -65,6 +111,7 @@ Props:
|
|
|
65
111
|
- `content: string`
|
|
66
112
|
- `compact?: boolean`
|
|
67
113
|
- `theme?: "system" | "light" | "dark"` (default: `"system"`)
|
|
114
|
+
- `plugins?: MarkdownPlugin[]`
|
|
68
115
|
|
|
69
116
|
`compact` removes default spacing and reduces vertical rhythm for tighter layouts.
|
|
70
117
|
|
|
@@ -86,6 +133,7 @@ Props:
|
|
|
86
133
|
- `disabled?: boolean`
|
|
87
134
|
- `rows?: number`
|
|
88
135
|
- `className?: string`
|
|
136
|
+
- `plugins?: MarkdownPlugin[]` (forwarded to the preview pane)
|
|
89
137
|
|
|
90
138
|
### CodeBlock
|
|
91
139
|
|
|
@@ -94,6 +142,7 @@ Props:
|
|
|
94
142
|
- `language: string`
|
|
95
143
|
- `className?: string`
|
|
96
144
|
- `theme?: "system" | "light" | "dark"` (default: `"system"`)
|
|
145
|
+
- `plugins?: MarkdownPlugin[]` (only `highlight` hooks are used)
|
|
97
146
|
|
|
98
147
|
## Styles
|
|
99
148
|
|
|
@@ -107,12 +156,17 @@ Styles are split per entrypoint, so you can import only what the page uses:
|
|
|
107
156
|
| `@ootc/markdown/code.css` | `CodeBlock` |
|
|
108
157
|
| `@ootc/markdown/preview.css` | `MarkdownPreview` (includes `CodeBlock` and KaTeX) |
|
|
109
158
|
| `@ootc/markdown/editor.css` | `MarkdownEditor` (includes both of the above) |
|
|
159
|
+
| `@ootc/markdown/plugin-mermaid.css` | diagram container, pan/zoom (needed with `mermaidPlugin`) |
|
|
110
160
|
|
|
111
161
|
```ts
|
|
112
162
|
import '@ootc/markdown/preview.css';
|
|
113
163
|
```
|
|
114
164
|
|
|
115
|
-
Each of these is a thin file that `@import`s the underlying stylesheets in `dist/css
|
|
165
|
+
Each of these is a thin file that `@import`s the underlying stylesheets in `dist/css/`.
|
|
166
|
+
Bundlers resolve and copy them automatically.
|
|
167
|
+
|
|
168
|
+
`plugin-katex` has no stylesheet of its own — it imports `katex/dist/katex.min.css`
|
|
169
|
+
from your own KaTeX install, so the fonts come from there rather than from this package.
|
|
116
170
|
|
|
117
171
|
## Dark Mode
|
|
118
172
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const o=require("./jsx-runtime-nZSsnGb7.cjs"),a=require("react"),k="_container_8h8ah_1",S="_loadingCodeBlock_8h8ah_5",E="_copyButton_8h8ah_17",L="_copyButtonSingleLine_8h8ah_31",R="_codeBlock_8h8ah_41",i={container:k,loadingCodeBlock:S,copyButton:E,copyButtonSingleLine:L,codeBlock:R};function $({code:t,language:s,className:r="",theme:c="system",plugins:h}){const[y,l]=a.useState(""),[m,u]=a.useState(!0),[f,p]=a.useState(!1),B=!t.trimEnd().includes(`
|
|
2
|
+
`);a.useEffect(()=>{let n=!1;const g=(h??[]).map(e=>e.highlight).filter(e=>!!e);if(g.length===0){l(d(t)),u(!1);return}u(!0);async function C(){try{for(const e of g){const x=await e(t,s);if(n)return;if(x!==null){l(x);return}}l(d(t))}catch(e){console.error("Syntax highlighting error:",e),n||l(d(t))}finally{n||u(!1)}}return C(),()=>{n=!0}},[t,s,h]);const _=async()=>{try{await navigator.clipboard.writeText(t),p(!0),setTimeout(()=>p(!1),2e3)}catch(n){console.error("Failed to copy:",n)}},j=()=>o.jsxRuntimeExports.jsx("code",{dangerouslySetInnerHTML:{__html:y}});return m?o.jsxRuntimeExports.jsx("div",{className:i.container,"data-theme":c==="system"?void 0:c,children:o.jsxRuntimeExports.jsx("pre",{className:`${i.loadingCodeBlock} ${r}`,children:o.jsxRuntimeExports.jsx("code",{children:t})})}):o.jsxRuntimeExports.jsxs("div",{className:i.container,"data-theme":c==="system"?void 0:c,children:[o.jsxRuntimeExports.jsx("button",{onClick:_,className:`${i.copyButton} ${B?i.copyButtonSingleLine:""}`,title:"Copy code",children:f?"Copied!":"Copy"}),o.jsxRuntimeExports.jsx("pre",{className:`${i.codeBlock} ${r}`,children:j()})]})}function d(t){const s={"&":"&","<":"<",">":">",'"':""","'":"'"};return t.replace(/[&<>"']/g,r=>s[r])}exports.CodeBlock=$;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { j as o } from "./jsx-runtime-DXgJBoQh.js";
|
|
2
|
+
import { useState as h, useEffect as j } from "react";
|
|
3
|
+
const L = "_container_8h8ah_1", S = "_loadingCodeBlock_8h8ah_5", $ = "_copyButton_8h8ah_17", v = "_copyButtonSingleLine_8h8ah_31", N = "_codeBlock_8h8ah_41", i = {
|
|
4
|
+
container: L,
|
|
5
|
+
loadingCodeBlock: S,
|
|
6
|
+
copyButton: $,
|
|
7
|
+
copyButtonSingleLine: v,
|
|
8
|
+
codeBlock: N
|
|
9
|
+
};
|
|
10
|
+
function H({ code: t, language: c, className: r = "", theme: s = "system", plugins: u }) {
|
|
11
|
+
const [f, l] = h(""), [m, a] = h(!0), [B, g] = h(!1), _ = !t.trimEnd().includes(`
|
|
12
|
+
`);
|
|
13
|
+
j(() => {
|
|
14
|
+
let n = !1;
|
|
15
|
+
const p = (u ?? []).map((e) => e.highlight).filter((e) => !!e);
|
|
16
|
+
if (p.length === 0) {
|
|
17
|
+
l(d(t)), a(!1);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
a(!0);
|
|
21
|
+
async function k() {
|
|
22
|
+
try {
|
|
23
|
+
for (const e of p) {
|
|
24
|
+
const y = await e(t, c);
|
|
25
|
+
if (n) return;
|
|
26
|
+
if (y !== null) {
|
|
27
|
+
l(y);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
l(d(t));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error("Syntax highlighting error:", e), n || l(d(t));
|
|
34
|
+
} finally {
|
|
35
|
+
n || a(!1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return k(), () => {
|
|
39
|
+
n = !0;
|
|
40
|
+
};
|
|
41
|
+
}, [t, c, u]);
|
|
42
|
+
const C = async () => {
|
|
43
|
+
try {
|
|
44
|
+
await navigator.clipboard.writeText(t), g(!0), setTimeout(() => g(!1), 2e3);
|
|
45
|
+
} catch (n) {
|
|
46
|
+
console.error("Failed to copy:", n);
|
|
47
|
+
}
|
|
48
|
+
}, x = () => /* @__PURE__ */ o.jsx("code", { dangerouslySetInnerHTML: { __html: f } });
|
|
49
|
+
return m ? /* @__PURE__ */ o.jsx("div", { className: i.container, "data-theme": s === "system" ? void 0 : s, children: /* @__PURE__ */ o.jsx("pre", { className: `${i.loadingCodeBlock} ${r}`, children: /* @__PURE__ */ o.jsx("code", { children: t }) }) }) : /* @__PURE__ */ o.jsxs("div", { className: i.container, "data-theme": s === "system" ? void 0 : s, children: [
|
|
50
|
+
/* @__PURE__ */ o.jsx(
|
|
51
|
+
"button",
|
|
52
|
+
{
|
|
53
|
+
onClick: C,
|
|
54
|
+
className: `${i.copyButton} ${_ ? i.copyButtonSingleLine : ""}`,
|
|
55
|
+
title: "Copy code",
|
|
56
|
+
children: B ? "Copied!" : "Copy"
|
|
57
|
+
}
|
|
58
|
+
),
|
|
59
|
+
/* @__PURE__ */ o.jsx("pre", { className: `${i.codeBlock} ${r}`, children: x() })
|
|
60
|
+
] });
|
|
61
|
+
}
|
|
62
|
+
function d(t) {
|
|
63
|
+
const c = {
|
|
64
|
+
"&": "&",
|
|
65
|
+
"<": "<",
|
|
66
|
+
">": ">",
|
|
67
|
+
'"': """,
|
|
68
|
+
"'": "'"
|
|
69
|
+
};
|
|
70
|
+
return t.replace(/[&<>"']/g, (r) => c[r]);
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
H as C
|
|
74
|
+
};
|