@ootc/markdown 0.0.9 → 0.2.0
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 +96 -4
- 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.css +1 -0
- package/dist/code.d.ts +3 -1
- package/dist/code.js +3 -2
- 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/CodeBlock.css +1 -0
- package/dist/css/MarkdownPreview.css +1 -0
- package/dist/css/editor.css +1 -0
- package/dist/css/plugin-mermaid.css +1 -0
- package/dist/editor.cjs +1 -1
- package/dist/editor.css +3 -0
- package/dist/editor.d.ts +3 -1
- package/dist/editor.js +28 -25
- 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.css +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -2
- 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.js +20 -0
- package/dist/plugin-katex.cjs +1 -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.js +266 -0
- package/dist/plugins/types.d.ts +38 -0
- package/dist/preview.cjs +1 -1
- package/dist/preview.css +2 -0
- package/dist/preview.d.ts +3 -1
- package/dist/preview.js +4 -3
- package/dist/style.css +4 -1
- package/package.json +76 -21
- package/dist/CodeBlock-BYxQBfWO.js +0 -40827
- package/dist/CodeBlock-CJ6j8Wkl.cjs +0 -3934
- package/dist/MarkdownPreview-DcWMewhy.cjs +0 -295
- package/dist/MarkdownPreview-lqJAnu4B.js +0 -20424
- package/dist/_baseUniq-BfVwFITD.js +0 -477
- package/dist/_baseUniq-D-3LoSZp.cjs +0 -1
- package/dist/arc-CyzqoBTV.js +0 -83
- package/dist/arc-DrpGAtaq.cjs +0 -1
- package/dist/architecture-U656AL7Q-C8Bj_Ouy.cjs +0 -1
- package/dist/architecture-U656AL7Q-DTKdLHLe.js +0 -5
- package/dist/architectureDiagram-VXUJARFQ-B8EG6DIA.js +0 -4662
- package/dist/architectureDiagram-VXUJARFQ-DJ1ub7X0.cjs +0 -36
- package/dist/blockDiagram-VD42YOAC-CKNTgeZ8.js +0 -2256
- package/dist/blockDiagram-VD42YOAC-G-1iOwuq.cjs +0 -122
- package/dist/c4Diagram-YG6GDRKO-BJ1Ka924.cjs +0 -10
- package/dist/c4Diagram-YG6GDRKO-Bokkq4pO.js +0 -1580
- package/dist/channel-C4noxv-h.js +0 -5
- package/dist/channel-DvIIEA3u.cjs +0 -1
- package/dist/chunk-4BX2VUAB-B5M-5e_l.cjs +0 -1
- package/dist/chunk-4BX2VUAB-ByoAwp1j.js +0 -8
- package/dist/chunk-55IACEB6-BpG-_f0h.cjs +0 -1
- package/dist/chunk-55IACEB6-DRnx6y7F.js +0 -8
- package/dist/chunk-B4BG7PRW-0toVGVN-.js +0 -1375
- package/dist/chunk-B4BG7PRW-evUM3dip.cjs +0 -165
- package/dist/chunk-DI55MBZ5-CyInK_-M.js +0 -1370
- package/dist/chunk-DI55MBZ5-DKs4p2E0.cjs +0 -220
- package/dist/chunk-FMBD7UC4-BwUpmqhP.js +0 -19
- package/dist/chunk-FMBD7UC4-cpOVGF_2.cjs +0 -15
- package/dist/chunk-QN33PNHL-C7XXEbKU.js +0 -19
- package/dist/chunk-QN33PNHL-CEdYSNej.cjs +0 -1
- package/dist/chunk-QZHKN3VN-hppYv0Iu.cjs +0 -1
- package/dist/chunk-QZHKN3VN-qqHBDA_I.js +0 -15
- package/dist/chunk-TZMSLE5B-B9QqMSFM.js +0 -64
- package/dist/chunk-TZMSLE5B-Bklau4qu.cjs +0 -1
- package/dist/classDiagram-2ON5EDUG-CYKX_y1c.js +0 -16
- package/dist/classDiagram-2ON5EDUG-TgiEUsUn.cjs +0 -1
- package/dist/classDiagram-v2-WZHVMYZB-CYKX_y1c.js +0 -16
- package/dist/classDiagram-v2-WZHVMYZB-TgiEUsUn.cjs +0 -1
- package/dist/clone-CE64n2kf.js +0 -8
- package/dist/clone-jaW02xOC.cjs +0 -1
- package/dist/cose-bilkent-S5V4N54A-B_XAF1ZT.js +0 -2609
- package/dist/cose-bilkent-S5V4N54A-DSZx3rxe.cjs +0 -1
- package/dist/cytoscape.esm-CNUX3VTg.cjs +0 -321
- package/dist/cytoscape.esm-Cvf3sx9F.js +0 -18704
- package/dist/dagre-6UL2VRFP-Biy3Qm3K.js +0 -443
- package/dist/dagre-6UL2VRFP-C8MiPDEQ.cjs +0 -4
- package/dist/defaultLocale-D7EN2tov.js +0 -171
- package/dist/defaultLocale-DIVzfLaQ.cjs +0 -1
- package/dist/diagram-PSM6KHXK-B1y0Lt7Z.cjs +0 -24
- package/dist/diagram-PSM6KHXK-CIfbagcO.js +0 -531
- package/dist/diagram-QEK2KX5R-BJNTbg0b.cjs +0 -43
- package/dist/diagram-QEK2KX5R-BQz0yqem.js +0 -217
- package/dist/diagram-S2PKOQOG-BGsratMZ.js +0 -142
- package/dist/diagram-S2PKOQOG-BK_tj5Pz.cjs +0 -24
- package/dist/erDiagram-Q2GNP2WA-CJbuwIgY.cjs +0 -60
- package/dist/erDiagram-Q2GNP2WA-CurkAz8N.js +0 -841
- package/dist/flowDiagram-NV44I4VS-DAMyok8X.js +0 -1620
- package/dist/flowDiagram-NV44I4VS-DnmHUmh1.cjs +0 -162
- package/dist/ganttDiagram-JELNMOA3-DxXvW49B.cjs +0 -267
- package/dist/ganttDiagram-JELNMOA3-oVlSmAjl.js +0 -2671
- package/dist/gitGraph-F6HP7TQM-DUSMetNW.js +0 -5
- package/dist/gitGraph-F6HP7TQM-DveZcMpA.cjs +0 -1
- package/dist/gitGraphDiagram-NY62KEGX-CFdtd4Gb.js +0 -699
- package/dist/gitGraphDiagram-NY62KEGX-CspGhCdP.cjs +0 -65
- package/dist/graph-Bza-HyX6.js +0 -381
- package/dist/graph-CE_Z8OkL.cjs +0 -1
- package/dist/info-NVLQJR56-3ayytpiF.js +0 -5
- package/dist/info-NVLQJR56-D-IKjb_E.cjs +0 -1
- package/dist/infoDiagram-WHAUD3N6--LngDYSE.cjs +0 -2
- package/dist/infoDiagram-WHAUD3N6-BtO0qT6g.js +0 -24
- package/dist/init-CHZsXQcr.cjs +0 -1
- package/dist/init-DjUOC4st.js +0 -16
- package/dist/journeyDiagram-XKPGCS4Q-DCvKw6yJ.cjs +0 -139
- package/dist/journeyDiagram-XKPGCS4Q-Unrh_bjo.js +0 -834
- package/dist/kanban-definition-3W4ZIXB7-CRa6bR24.cjs +0 -89
- package/dist/kanban-definition-3W4ZIXB7-Vpm6gG9R.js +0 -719
- package/dist/layout-BJzrWbaG.cjs +0 -1
- package/dist/layout-D6Pf3Nys.js +0 -1441
- package/dist/linear-C0E_OSxf.js +0 -259
- package/dist/linear-TSwNFrBs.cjs +0 -1
- package/dist/mermaid-parser.core-B9wV8XMP.js +0 -14177
- package/dist/mermaid-parser.core-Ba9EAFlD.cjs +0 -128
- package/dist/mermaid.core-B1lFjYb9.js +0 -15269
- package/dist/mermaid.core-C8vi9eg6.cjs +0 -249
- package/dist/min-BC6TlZcq.cjs +0 -1
- package/dist/min-DT5Wu4V1.js +0 -38
- package/dist/mindmap-definition-VGOIOE7T-COA86V4i.js +0 -784
- package/dist/mindmap-definition-VGOIOE7T-D9oMyZ2M.cjs +0 -68
- package/dist/ordinal-B6-f3MAq.js +0 -61
- package/dist/ordinal-CagbB1m8.cjs +0 -1
- package/dist/packet-BFZMPI3H-BZI0_bZt.js +0 -5
- package/dist/packet-BFZMPI3H-D4pnK0Ol.cjs +0 -1
- package/dist/pie-7BOR55EZ-DS6huTOL.cjs +0 -1
- package/dist/pie-7BOR55EZ-DgzTX76e.js +0 -5
- package/dist/pieDiagram-ADFJNKIX-CYW3Diea.js +0 -161
- package/dist/pieDiagram-ADFJNKIX-CxPAjreR.cjs +0 -30
- package/dist/quadrantDiagram-AYHSOK5B-BT94kssD.js +0 -1022
- package/dist/quadrantDiagram-AYHSOK5B-ehLphI_D.cjs +0 -7
- package/dist/radar-NHE76QYJ-CKcVnf1I.cjs +0 -1
- package/dist/radar-NHE76QYJ-D8cZitaQ.js +0 -5
- package/dist/requirementDiagram-UZGBJVZJ-B4UYGl6e.js +0 -850
- package/dist/requirementDiagram-UZGBJVZJ-BDLj6-Do.cjs +0 -64
- package/dist/sankeyDiagram-TZEHDZUN-CAWsWdn8.js +0 -810
- package/dist/sankeyDiagram-TZEHDZUN-DUb360Ep.cjs +0 -10
- package/dist/sequenceDiagram-WL72ISMW-Bb4Tkhf2.cjs +0 -145
- package/dist/sequenceDiagram-WL72ISMW-DsmW0gAI.js +0 -2511
- package/dist/stateDiagram-FKZM4ZOC-Da-8DKdP.js +0 -263
- package/dist/stateDiagram-FKZM4ZOC-jOvG1Jmy.cjs +0 -1
- package/dist/stateDiagram-v2-4FDKWEC3-GMZ8nH4e.js +0 -16
- package/dist/stateDiagram-v2-4FDKWEC3-mWKIMY-b.cjs +0 -1
- package/dist/timeline-definition-IT6M3QCI-BdnDlTsf.cjs +0 -61
- package/dist/timeline-definition-IT6M3QCI-CvJDgHLW.js +0 -795
- package/dist/treemap-KMMF4GRG-BVy_kMp3.js +0 -5
- package/dist/treemap-KMMF4GRG-BsA9nu7r.cjs +0 -1
- package/dist/xychartDiagram-PRI3JC2R-CYXNZ7B0.cjs +0 -7
- package/dist/xychartDiagram-PRI3JC2R-wG1xpI1S.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,8 +53,57 @@ 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
|
|
59
|
+
|
|
60
|
+
Each entrypoint has both a named and a default export, so it works with `React.lazy` directly:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import {lazy, Suspense} from 'react';
|
|
64
|
+
import '@ootc/markdown/preview.css';
|
|
65
|
+
|
|
66
|
+
const MarkdownPreview = lazy(() => import('@ootc/markdown/preview'));
|
|
67
|
+
|
|
68
|
+
export function Doc({content}: {content: string}) {
|
|
69
|
+
return (
|
|
70
|
+
<Suspense fallback={null}>
|
|
71
|
+
<MarkdownPreview content={content} />
|
|
72
|
+
</Suspense>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Opt-in dependencies
|
|
36
78
|
|
|
37
|
-
|
|
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:
|
|
82
|
+
|
|
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 |
|
|
88
|
+
|
|
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
|
+
```
|
|
38
107
|
|
|
39
108
|
### MarkdownPreview
|
|
40
109
|
|
|
@@ -42,6 +111,7 @@ Props:
|
|
|
42
111
|
- `content: string`
|
|
43
112
|
- `compact?: boolean`
|
|
44
113
|
- `theme?: "system" | "light" | "dark"` (default: `"system"`)
|
|
114
|
+
- `plugins?: MarkdownPlugin[]`
|
|
45
115
|
|
|
46
116
|
`compact` removes default spacing and reduces vertical rhythm for tighter layouts.
|
|
47
117
|
|
|
@@ -63,6 +133,7 @@ Props:
|
|
|
63
133
|
- `disabled?: boolean`
|
|
64
134
|
- `rows?: number`
|
|
65
135
|
- `className?: string`
|
|
136
|
+
- `plugins?: MarkdownPlugin[]` (forwarded to the preview pane)
|
|
66
137
|
|
|
67
138
|
### CodeBlock
|
|
68
139
|
|
|
@@ -71,11 +142,32 @@ Props:
|
|
|
71
142
|
- `language: string`
|
|
72
143
|
- `className?: string`
|
|
73
144
|
- `theme?: "system" | "light" | "dark"` (default: `"system"`)
|
|
145
|
+
- `plugins?: MarkdownPlugin[]` (only `highlight` hooks are used)
|
|
74
146
|
|
|
75
147
|
## Styles
|
|
76
148
|
|
|
77
149
|
This package ships CSS modules. The preview also imports KaTeX styles internally.
|
|
78
150
|
|
|
151
|
+
Styles are split per entrypoint, so you can import only what the page uses:
|
|
152
|
+
|
|
153
|
+
| Import | Covers |
|
|
154
|
+
| --- | --- |
|
|
155
|
+
| `@ootc/markdown/style.css` | everything (safe default) |
|
|
156
|
+
| `@ootc/markdown/code.css` | `CodeBlock` |
|
|
157
|
+
| `@ootc/markdown/preview.css` | `MarkdownPreview` (includes `CodeBlock` and KaTeX) |
|
|
158
|
+
| `@ootc/markdown/editor.css` | `MarkdownEditor` (includes both of the above) |
|
|
159
|
+
| `@ootc/markdown/plugin-mermaid.css` | diagram container, pan/zoom (needed with `mermaidPlugin`) |
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
import '@ootc/markdown/preview.css';
|
|
163
|
+
```
|
|
164
|
+
|
|
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.
|
|
170
|
+
|
|
79
171
|
## Dark Mode
|
|
80
172
|
|
|
81
173
|
The components support both light and dark themes.
|
|
@@ -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
|
+
};
|