@soroush.tech/markdown 0.1.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/LICENSE +21 -0
- package/README.md +179 -0
- package/dist/CodeBlock-CVlrvVPP.mjs +159 -0
- package/dist/CodeBlock-Cymx1ZAY.cjs +176 -0
- package/dist/CodeBlock.cjs +5 -0
- package/dist/CodeBlock.d.cts +2 -0
- package/dist/CodeBlock.d.mts +2 -0
- package/dist/CodeBlock.mjs +2 -0
- package/dist/Control.cjs +61 -0
- package/dist/Control.d.cts +18 -0
- package/dist/Control.d.mts +18 -0
- package/dist/Control.mjs +60 -0
- package/dist/Editor.cjs +129 -0
- package/dist/Editor.d.cts +40 -0
- package/dist/Editor.d.mts +40 -0
- package/dist/Editor.mjs +128 -0
- package/dist/MarkdownContext.cjs +13 -0
- package/dist/MarkdownContext.d.cts +2 -0
- package/dist/MarkdownContext.d.mts +2 -0
- package/dist/MarkdownContext.mjs +11 -0
- package/dist/Mermaid-BclI9A7e.mjs +231 -0
- package/dist/Mermaid-DqP2Q0bt.cjs +236 -0
- package/dist/Mermaid.cjs +3 -0
- package/dist/Mermaid.d.cts +2 -0
- package/dist/Mermaid.d.mts +2 -0
- package/dist/Mermaid.mjs +2 -0
- package/dist/Preview-BVT70uXa.cjs +276 -0
- package/dist/Preview-C1CwRDj5.mjs +246 -0
- package/dist/Preview.cjs +3 -0
- package/dist/Preview.d.cts +53 -0
- package/dist/Preview.d.mts +53 -0
- package/dist/Preview.mjs +2 -0
- package/dist/Toolbar-Ba3l-oBU.cjs +600 -0
- package/dist/Toolbar-C0SNI-JK.mjs +589 -0
- package/dist/Toolbar.cjs +4 -0
- package/dist/Toolbar.d.cts +13 -0
- package/dist/Toolbar.d.mts +13 -0
- package/dist/Toolbar.mjs +2 -0
- package/dist/applyAction-BDkgYhOd.cjs +120 -0
- package/dist/applyAction-BGWMbUYT.mjs +115 -0
- package/dist/index-BO0LyUUG.d.cts +27 -0
- package/dist/index-BO0LyUUG.d.mts +27 -0
- package/dist/index-BtMTBOcM.d.cts +48 -0
- package/dist/index-BtMTBOcM.d.mts +48 -0
- package/dist/index-rGZIhUgj.d.cts +76 -0
- package/dist/index-rGZIhUgj.d.mts +76 -0
- package/dist/index.cjs +19 -0
- package/dist/index.d.cts +50 -0
- package/dist/index.d.mts +50 -0
- package/dist/index.mjs +8 -0
- package/package.json +110 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { r as CodeBlock } from "./CodeBlock-CVlrvVPP.mjs";
|
|
2
|
+
import { t as Mermaid } from "./Mermaid-BclI9A7e.mjs";
|
|
3
|
+
import { createContext, isValidElement, useContext } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { Typography } from "@soroush.tech/design-system/Typography";
|
|
6
|
+
import { styled } from "@soroush.tech/design-system";
|
|
7
|
+
import ReactMarkdown from "react-markdown";
|
|
8
|
+
import remarkGfm from "remark-gfm";
|
|
9
|
+
import rehypeHighlight from "rehype-highlight";
|
|
10
|
+
import { Quote } from "@soroush.tech/design-system/Quote";
|
|
11
|
+
import { Checkbox } from "@soroush.tech/design-system/Checkbox";
|
|
12
|
+
import { Image } from "@soroush.tech/design-system/Image";
|
|
13
|
+
import { Link } from "@soroush.tech/design-system/Link";
|
|
14
|
+
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from "@soroush.tech/design-system/Table";
|
|
15
|
+
import { View } from "@soroush.tech/design-system/View";
|
|
16
|
+
function mermaidSource(children) {
|
|
17
|
+
return (Array.isArray(children) ? children.join("") : String(children ?? "")).replace(/\n$/, "");
|
|
18
|
+
}
|
|
19
|
+
function isMermaidBlock(children) {
|
|
20
|
+
if (!isValidElement(children)) return false;
|
|
21
|
+
const { className } = children.props;
|
|
22
|
+
return typeof className === "string" && className.includes("language-mermaid");
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/Preview/Preview.tsx
|
|
26
|
+
const remarkPlugins = [remarkGfm];
|
|
27
|
+
const rehypePlugins = [[rehypeHighlight, { ignoreMissing: true }]];
|
|
28
|
+
const PreviewRoot = styled(View, {
|
|
29
|
+
name: "MarkdownPreview",
|
|
30
|
+
label: "MarkdownPreview"
|
|
31
|
+
})({
|
|
32
|
+
minWidth: 0,
|
|
33
|
+
maxWidth: "100%",
|
|
34
|
+
overflowWrap: "break-word"
|
|
35
|
+
});
|
|
36
|
+
const EMPTY_SLOT_PROPS = {};
|
|
37
|
+
const SlotPropsContext = createContext(EMPTY_SLOT_PROPS);
|
|
38
|
+
function slotted(render) {
|
|
39
|
+
function Slotted(props) {
|
|
40
|
+
return render(useContext(SlotPropsContext), props);
|
|
41
|
+
}
|
|
42
|
+
return Slotted;
|
|
43
|
+
}
|
|
44
|
+
const components = {
|
|
45
|
+
h1: slotted(({ h1 }, { children }) => /* @__PURE__ */ jsx(Typography, {
|
|
46
|
+
mt: 2,
|
|
47
|
+
variant: "h1",
|
|
48
|
+
color: "primary",
|
|
49
|
+
gutterBottom: true,
|
|
50
|
+
...h1,
|
|
51
|
+
children
|
|
52
|
+
})),
|
|
53
|
+
h2: slotted(({ h2 }, { children }) => /* @__PURE__ */ jsx(Typography, {
|
|
54
|
+
mt: 2,
|
|
55
|
+
variant: "h2",
|
|
56
|
+
color: "primary",
|
|
57
|
+
gutterBottom: true,
|
|
58
|
+
...h2,
|
|
59
|
+
children
|
|
60
|
+
})),
|
|
61
|
+
h3: slotted(({ h3 }, { children }) => /* @__PURE__ */ jsx(Typography, {
|
|
62
|
+
mt: 2,
|
|
63
|
+
variant: "h3",
|
|
64
|
+
color: "primary",
|
|
65
|
+
gutterBottom: true,
|
|
66
|
+
...h3,
|
|
67
|
+
children
|
|
68
|
+
})),
|
|
69
|
+
h4: slotted(({ h4 }, { children }) => /* @__PURE__ */ jsx(Typography, {
|
|
70
|
+
mt: 2,
|
|
71
|
+
variant: "h4",
|
|
72
|
+
gutterBottom: true,
|
|
73
|
+
...h4,
|
|
74
|
+
children
|
|
75
|
+
})),
|
|
76
|
+
h5: slotted(({ h5 }, { children }) => /* @__PURE__ */ jsx(Typography, {
|
|
77
|
+
mt: 2,
|
|
78
|
+
variant: "h5",
|
|
79
|
+
gutterBottom: true,
|
|
80
|
+
...h5,
|
|
81
|
+
children
|
|
82
|
+
})),
|
|
83
|
+
h6: slotted(({ h6 }, { children }) => /* @__PURE__ */ jsx(Typography, {
|
|
84
|
+
mt: 2,
|
|
85
|
+
variant: "h6",
|
|
86
|
+
gutterBottom: true,
|
|
87
|
+
...h6,
|
|
88
|
+
children
|
|
89
|
+
})),
|
|
90
|
+
p: slotted(({ p }, { children }) => /* @__PURE__ */ jsx(Typography, {
|
|
91
|
+
variant: "body1",
|
|
92
|
+
color: "secondary",
|
|
93
|
+
mb: 2,
|
|
94
|
+
lineHeight: "relaxed",
|
|
95
|
+
...p,
|
|
96
|
+
children
|
|
97
|
+
})),
|
|
98
|
+
a: slotted(({ a }, { href, children }) => /* @__PURE__ */ jsx(Link, {
|
|
99
|
+
href,
|
|
100
|
+
underline: "hover",
|
|
101
|
+
...a,
|
|
102
|
+
children
|
|
103
|
+
})),
|
|
104
|
+
strong: slotted(({ strong }, { children }) => /* @__PURE__ */ jsx(Typography, {
|
|
105
|
+
as: "strong",
|
|
106
|
+
variant: "inherit",
|
|
107
|
+
fontWeight: "extraBold",
|
|
108
|
+
...strong,
|
|
109
|
+
children
|
|
110
|
+
})),
|
|
111
|
+
em: slotted(({ em }, { children }) => /* @__PURE__ */ jsx(Typography, {
|
|
112
|
+
as: "em",
|
|
113
|
+
variant: "inherit",
|
|
114
|
+
fontStyle: "italic",
|
|
115
|
+
...em,
|
|
116
|
+
children
|
|
117
|
+
})),
|
|
118
|
+
ul: slotted(({ ul }, { children }) => /* @__PURE__ */ jsx(View, {
|
|
119
|
+
as: "ul",
|
|
120
|
+
pl: 3,
|
|
121
|
+
mb: 2,
|
|
122
|
+
...ul,
|
|
123
|
+
children
|
|
124
|
+
})),
|
|
125
|
+
ol: slotted(({ ol }, { children }) => /* @__PURE__ */ jsx(View, {
|
|
126
|
+
as: "ol",
|
|
127
|
+
pl: 3,
|
|
128
|
+
mb: 2,
|
|
129
|
+
...ol,
|
|
130
|
+
children
|
|
131
|
+
})),
|
|
132
|
+
li: slotted(({ li }, { children, className }) => /* @__PURE__ */ jsx(Typography, {
|
|
133
|
+
as: "li",
|
|
134
|
+
color: "secondary",
|
|
135
|
+
lineHeight: "base",
|
|
136
|
+
variant: "body1",
|
|
137
|
+
gutterBottom: true,
|
|
138
|
+
style: className?.includes("task-list-item") ? { listStyleType: "none" } : void 0,
|
|
139
|
+
...li,
|
|
140
|
+
children
|
|
141
|
+
})),
|
|
142
|
+
input: slotted(({ input }, { checked }) => /* @__PURE__ */ jsx(Checkbox, {
|
|
143
|
+
checked: Boolean(checked),
|
|
144
|
+
disabled: true,
|
|
145
|
+
color: "primary",
|
|
146
|
+
size: "sm",
|
|
147
|
+
"aria-label": "Task item",
|
|
148
|
+
mr: 1,
|
|
149
|
+
...input
|
|
150
|
+
})),
|
|
151
|
+
blockquote: slotted(({ blockquote }, { children }) => /* @__PURE__ */ jsx(Quote, {
|
|
152
|
+
as: "blockquote",
|
|
153
|
+
pl: 3,
|
|
154
|
+
py: 1,
|
|
155
|
+
my: 2,
|
|
156
|
+
...blockquote,
|
|
157
|
+
children
|
|
158
|
+
})),
|
|
159
|
+
code: slotted(({ code, mermaid }, { className, children }) => {
|
|
160
|
+
const classes = className ?? "";
|
|
161
|
+
if (classes.includes("language-mermaid")) return /* @__PURE__ */ jsx(Mermaid, {
|
|
162
|
+
chart: mermaidSource(children),
|
|
163
|
+
...mermaid
|
|
164
|
+
});
|
|
165
|
+
const isBlock = classes.includes("language-");
|
|
166
|
+
return /* @__PURE__ */ jsx(Typography, {
|
|
167
|
+
as: "code",
|
|
168
|
+
color: "initial",
|
|
169
|
+
variant: "inherit",
|
|
170
|
+
fontFamily: "mono",
|
|
171
|
+
display: isBlock ? "block" : "inline",
|
|
172
|
+
bg: isBlock ? "transparent" : "paper",
|
|
173
|
+
px: isBlock ? 0 : 1,
|
|
174
|
+
borderRadius: "sm",
|
|
175
|
+
...code,
|
|
176
|
+
children
|
|
177
|
+
});
|
|
178
|
+
}),
|
|
179
|
+
pre: slotted(({ pre }, { children }) => isMermaidBlock(children) ? children : /* @__PURE__ */ jsx(CodeBlock, {
|
|
180
|
+
...pre,
|
|
181
|
+
children
|
|
182
|
+
})),
|
|
183
|
+
table: slotted(({ table }, { children }) => /* @__PURE__ */ jsx(TableContainer, {
|
|
184
|
+
my: 2,
|
|
185
|
+
children: /* @__PURE__ */ jsx(Table, {
|
|
186
|
+
bg: "terminal",
|
|
187
|
+
borderRadius: "md",
|
|
188
|
+
...table,
|
|
189
|
+
children
|
|
190
|
+
})
|
|
191
|
+
})),
|
|
192
|
+
thead: slotted(({ thead }, { children }) => /* @__PURE__ */ jsx(TableHead, {
|
|
193
|
+
bg: "grid",
|
|
194
|
+
color: "primary",
|
|
195
|
+
...thead,
|
|
196
|
+
children
|
|
197
|
+
})),
|
|
198
|
+
tbody: slotted(({ tbody }, { children }) => /* @__PURE__ */ jsx(TableBody, {
|
|
199
|
+
...tbody,
|
|
200
|
+
children
|
|
201
|
+
})),
|
|
202
|
+
tr: slotted(({ tr }, { children }) => /* @__PURE__ */ jsx(TableRow, {
|
|
203
|
+
isHoverable: true,
|
|
204
|
+
...tr,
|
|
205
|
+
children
|
|
206
|
+
})),
|
|
207
|
+
th: slotted(({ th }, { children, style }) => /* @__PURE__ */ jsx(TableCell, {
|
|
208
|
+
style,
|
|
209
|
+
...th,
|
|
210
|
+
children
|
|
211
|
+
})),
|
|
212
|
+
td: slotted(({ td }, { children, style }) => /* @__PURE__ */ jsx(TableCell, {
|
|
213
|
+
style,
|
|
214
|
+
...td,
|
|
215
|
+
children
|
|
216
|
+
})),
|
|
217
|
+
hr: slotted(({ hr }) => /* @__PURE__ */ jsx(View, {
|
|
218
|
+
as: "hr",
|
|
219
|
+
my: 2,
|
|
220
|
+
height: "1px",
|
|
221
|
+
bg: "grid",
|
|
222
|
+
width: "100%",
|
|
223
|
+
border: "none",
|
|
224
|
+
...hr
|
|
225
|
+
})),
|
|
226
|
+
img: slotted(({ img }, { src, alt }) => /* @__PURE__ */ jsx(Image, {
|
|
227
|
+
src,
|
|
228
|
+
alt,
|
|
229
|
+
maxWidth: "100%",
|
|
230
|
+
...img
|
|
231
|
+
}))
|
|
232
|
+
};
|
|
233
|
+
/** Renders a markdown string with every element mapped to a design-system primitive. */
|
|
234
|
+
function Preview({ children, slotProps }) {
|
|
235
|
+
return /* @__PURE__ */ jsx(PreviewRoot, { children: /* @__PURE__ */ jsx(SlotPropsContext.Provider, {
|
|
236
|
+
value: slotProps ?? EMPTY_SLOT_PROPS,
|
|
237
|
+
children: /* @__PURE__ */ jsx(ReactMarkdown, {
|
|
238
|
+
components,
|
|
239
|
+
remarkPlugins,
|
|
240
|
+
rehypePlugins,
|
|
241
|
+
children
|
|
242
|
+
})
|
|
243
|
+
}) });
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
export { Preview as t };
|
package/dist/Preview.cjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { a as CodeBlockProps } from "./index-BtMTBOcM.cjs";
|
|
2
|
+
import { r as MermaidProps } from "./index-BO0LyUUG.cjs";
|
|
3
|
+
import { ViewProps } from "@soroush.tech/design-system/View";
|
|
4
|
+
import { QuoteProps } from "@soroush.tech/design-system/Quote";
|
|
5
|
+
import { CheckboxProps } from "@soroush.tech/design-system/Checkbox";
|
|
6
|
+
import { ImageProps } from "@soroush.tech/design-system/Image";
|
|
7
|
+
import { LinkProps } from "@soroush.tech/design-system/Link";
|
|
8
|
+
import { TableBodyProps, TableCellProps, TableHeadProps, TableProps, TableRowProps } from "@soroush.tech/design-system/Table";
|
|
9
|
+
import { TypographyProps } from "@soroush.tech/design-system/Typography";
|
|
10
|
+
//#region src/Preview/Preview.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Per-element prop overrides, merged over the design-system defaults (the caller's props win).
|
|
13
|
+
* Keyed by markdown element — e.g. `slotProps={{ p: { color: 'primary' }, h1: { variant: 'h2' } }}`.
|
|
14
|
+
*/
|
|
15
|
+
interface PreviewSlotProps {
|
|
16
|
+
h1?: TypographyProps;
|
|
17
|
+
h2?: TypographyProps;
|
|
18
|
+
h3?: TypographyProps;
|
|
19
|
+
h4?: TypographyProps;
|
|
20
|
+
h5?: TypographyProps;
|
|
21
|
+
h6?: TypographyProps;
|
|
22
|
+
p?: TypographyProps;
|
|
23
|
+
strong?: TypographyProps;
|
|
24
|
+
em?: TypographyProps;
|
|
25
|
+
li?: TypographyProps;
|
|
26
|
+
code?: TypographyProps;
|
|
27
|
+
a?: LinkProps;
|
|
28
|
+
ul?: ViewProps;
|
|
29
|
+
ol?: ViewProps;
|
|
30
|
+
hr?: ViewProps;
|
|
31
|
+
blockquote?: QuoteProps;
|
|
32
|
+
img?: ImageProps;
|
|
33
|
+
th?: TableCellProps;
|
|
34
|
+
td?: TableCellProps;
|
|
35
|
+
pre?: CodeBlockProps;
|
|
36
|
+
input?: CheckboxProps;
|
|
37
|
+
table?: TableProps;
|
|
38
|
+
thead?: TableHeadProps;
|
|
39
|
+
tbody?: TableBodyProps;
|
|
40
|
+
tr?: TableRowProps;
|
|
41
|
+
/** Props for a ` ```mermaid ` fence's `Mermaid` renderer — including `diagram` (viewer) props. */
|
|
42
|
+
mermaid?: Omit<MermaidProps, 'chart'>;
|
|
43
|
+
}
|
|
44
|
+
interface PreviewProps {
|
|
45
|
+
/** The markdown source to render. */
|
|
46
|
+
children: string;
|
|
47
|
+
/** Per-element prop overrides, merged over the defaults. */
|
|
48
|
+
slotProps?: PreviewSlotProps;
|
|
49
|
+
}
|
|
50
|
+
/** Renders a markdown string with every element mapped to a design-system primitive. */
|
|
51
|
+
declare function Preview({ children, slotProps }: Readonly<PreviewProps>): import("react").JSX.Element;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { Preview, PreviewProps, PreviewSlotProps };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { a as CodeBlockProps } from "./index-BtMTBOcM.mjs";
|
|
2
|
+
import { r as MermaidProps } from "./index-BO0LyUUG.mjs";
|
|
3
|
+
import { TypographyProps } from "@soroush.tech/design-system/Typography";
|
|
4
|
+
import { QuoteProps } from "@soroush.tech/design-system/Quote";
|
|
5
|
+
import { CheckboxProps } from "@soroush.tech/design-system/Checkbox";
|
|
6
|
+
import { ImageProps } from "@soroush.tech/design-system/Image";
|
|
7
|
+
import { LinkProps } from "@soroush.tech/design-system/Link";
|
|
8
|
+
import { TableBodyProps, TableCellProps, TableHeadProps, TableProps, TableRowProps } from "@soroush.tech/design-system/Table";
|
|
9
|
+
import { ViewProps } from "@soroush.tech/design-system/View";
|
|
10
|
+
//#region src/Preview/Preview.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Per-element prop overrides, merged over the design-system defaults (the caller's props win).
|
|
13
|
+
* Keyed by markdown element — e.g. `slotProps={{ p: { color: 'primary' }, h1: { variant: 'h2' } }}`.
|
|
14
|
+
*/
|
|
15
|
+
interface PreviewSlotProps {
|
|
16
|
+
h1?: TypographyProps;
|
|
17
|
+
h2?: TypographyProps;
|
|
18
|
+
h3?: TypographyProps;
|
|
19
|
+
h4?: TypographyProps;
|
|
20
|
+
h5?: TypographyProps;
|
|
21
|
+
h6?: TypographyProps;
|
|
22
|
+
p?: TypographyProps;
|
|
23
|
+
strong?: TypographyProps;
|
|
24
|
+
em?: TypographyProps;
|
|
25
|
+
li?: TypographyProps;
|
|
26
|
+
code?: TypographyProps;
|
|
27
|
+
a?: LinkProps;
|
|
28
|
+
ul?: ViewProps;
|
|
29
|
+
ol?: ViewProps;
|
|
30
|
+
hr?: ViewProps;
|
|
31
|
+
blockquote?: QuoteProps;
|
|
32
|
+
img?: ImageProps;
|
|
33
|
+
th?: TableCellProps;
|
|
34
|
+
td?: TableCellProps;
|
|
35
|
+
pre?: CodeBlockProps;
|
|
36
|
+
input?: CheckboxProps;
|
|
37
|
+
table?: TableProps;
|
|
38
|
+
thead?: TableHeadProps;
|
|
39
|
+
tbody?: TableBodyProps;
|
|
40
|
+
tr?: TableRowProps;
|
|
41
|
+
/** Props for a ` ```mermaid ` fence's `Mermaid` renderer — including `diagram` (viewer) props. */
|
|
42
|
+
mermaid?: Omit<MermaidProps, 'chart'>;
|
|
43
|
+
}
|
|
44
|
+
interface PreviewProps {
|
|
45
|
+
/** The markdown source to render. */
|
|
46
|
+
children: string;
|
|
47
|
+
/** Per-element prop overrides, merged over the defaults. */
|
|
48
|
+
slotProps?: PreviewSlotProps;
|
|
49
|
+
}
|
|
50
|
+
/** Renders a markdown string with every element mapped to a design-system primitive. */
|
|
51
|
+
declare function Preview({ children, slotProps }: Readonly<PreviewProps>): import("react").JSX.Element;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { Preview, PreviewProps, PreviewSlotProps };
|
package/dist/Preview.mjs
ADDED