@object-ui/plugin-markdown 6.2.3 → 7.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/CHANGELOG.md +72 -0
- package/dist/{packages/plugin-markdown/src/MarkdownImpl.d.ts → MarkdownImpl.d.ts} +5 -3
- package/dist/MarkdownImpl.d.ts.map +1 -0
- package/dist/Mermaid.d.ts +12 -0
- package/dist/Mermaid.d.ts.map +1 -0
- package/dist/index.d.ts +21 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +213 -23
- package/dist/index.umd.cjs +121 -2
- package/dist/markdown-theme.d.ts +13 -0
- package/dist/markdown-theme.d.ts.map +1 -0
- package/dist/toc.d.ts +30 -0
- package/dist/toc.d.ts.map +1 -0
- package/dist/{packages/plugin-markdown/src/types.d.ts → types.d.ts} +1 -1
- package/dist/types.d.ts.map +1 -0
- package/package.json +14 -8
- package/dist/packages/plugin-markdown/src/MarkdownImpl.d.ts.map +0 -1
- package/dist/packages/plugin-markdown/src/index.d.ts +0 -19
- package/dist/packages/plugin-markdown/src/index.d.ts.map +0 -1
- package/dist/packages/plugin-markdown/src/types.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,77 @@
|
|
|
1
1
|
# @object-ui/plugin-markdown
|
|
2
2
|
|
|
3
|
+
## 7.1.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [677f7ed]
|
|
8
|
+
- Updated dependencies [08c47da]
|
|
9
|
+
- Updated dependencies [a71be60]
|
|
10
|
+
- Updated dependencies [cb03bc3]
|
|
11
|
+
- @object-ui/types@7.1.0
|
|
12
|
+
- @object-ui/core@7.1.0
|
|
13
|
+
- @object-ui/react@7.1.0
|
|
14
|
+
- @object-ui/components@7.1.0
|
|
15
|
+
|
|
16
|
+
## 7.0.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- c09f44e: Docs: mermaid diagrams + long-doc table of contents (ADR-0046).
|
|
21
|
+
|
|
22
|
+
- **plugin-markdown** renders ```mermaid fenced blocks as diagrams (`<Mermaid>`: lazy-loaded mermaid, `securityLevel: 'strict'`, rendered post-`rehype-sanitize`by a trusted component, degrades to the raw source on error). Mermaid is text → SVG, so it stays within the v1 image/binary ban. Adds`extractToc(markdown)`— a TOC builder whose slugs are generated with the same`github-slugger` `rehype-slug`uses, so`#id` links resolve to the rendered heading anchors.
|
|
23
|
+
- **console** `DocPage` shows a sticky right-rail table of contents (h2–h3) for docs with ≥3 headings, plus an app-independent `/apps/:packageId/docs` index already added earlier.
|
|
24
|
+
- **i18n** adds `help.onThisPage` (en/zh; other locales fall back).
|
|
25
|
+
|
|
26
|
+
- 1addfda: Markdown grammar v1.1 (ADR-0046): heading anchors, code highlighting, and GitHub-style alerts.
|
|
27
|
+
|
|
28
|
+
The shared markdown renderer now applies three enrichments, all behind the existing `rehype-sanitize` gate (which runs last and stays the final XSS boundary):
|
|
29
|
+
|
|
30
|
+
- **Heading anchors** (`rehype-slug` + `rehype-autolink-headings`) — headings get slug ids so intra-doc `#section` links resolve (fixes the ADR-0046 cross-reference anchors, which previously had no target). `clobberPrefix: ''` keeps ids verbatim.
|
|
31
|
+
- **Code highlighting** (`rehype-highlight`) — fenced code blocks get highlight.js token classes; colors are theme-aware (light/dark) via injected CSS using the console's shadcn variables.
|
|
32
|
+
- **GitHub-style alerts** (`remark-github-blockquote-alert`) — `> [!NOTE]` / `[!TIP]` / `[!IMPORTANT]` / `[!WARNING]` / `[!CAUTION]` render as styled callouts. The syntax is valid CommonMark, so it also renders natively in GitHub previews and degrades to a plain blockquote in any older renderer — no lint coordination needed.
|
|
33
|
+
|
|
34
|
+
Security posture is unchanged: class names and ids are inert; script/style/event-handler/`javascript:`/iframe vectors stay blocked, and the alert icon SVG is stripped (zero SVG surface in the sanitize schema — callout icons are CSS pseudo-elements). A `class → className` canonicalization step runs before sanitize so the alert plugin's raw `class` attribute survives the whitelist.
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- Updated dependencies [5976ba3]
|
|
39
|
+
- Updated dependencies [a00e16d]
|
|
40
|
+
- Updated dependencies [eaccefd]
|
|
41
|
+
- Updated dependencies [f7f325d]
|
|
42
|
+
- Updated dependencies [c12986e]
|
|
43
|
+
- Updated dependencies [71d7ce0]
|
|
44
|
+
- Updated dependencies [053c948]
|
|
45
|
+
- Updated dependencies [ddbe4a2]
|
|
46
|
+
- Updated dependencies [2d47e94]
|
|
47
|
+
- Updated dependencies [9049bbe]
|
|
48
|
+
- Updated dependencies [6c0c92c]
|
|
49
|
+
- Updated dependencies [cb2fdb1]
|
|
50
|
+
- Updated dependencies [c3749eb]
|
|
51
|
+
- Updated dependencies [6cfa330]
|
|
52
|
+
- Updated dependencies [ad8ade6]
|
|
53
|
+
- Updated dependencies [d54346c]
|
|
54
|
+
- Updated dependencies [3870c20]
|
|
55
|
+
- Updated dependencies [2eb3096]
|
|
56
|
+
- Updated dependencies [b88c560]
|
|
57
|
+
- Updated dependencies [d16566f]
|
|
58
|
+
- Updated dependencies [90acb7f]
|
|
59
|
+
- Updated dependencies [7913390]
|
|
60
|
+
- Updated dependencies [1394e34]
|
|
61
|
+
- Updated dependencies [e95cc25]
|
|
62
|
+
- Updated dependencies [abe8ebc]
|
|
63
|
+
- Updated dependencies [300d755]
|
|
64
|
+
- Updated dependencies [bd8b054]
|
|
65
|
+
- Updated dependencies [4eb9cb6]
|
|
66
|
+
- Updated dependencies [7c239fd]
|
|
67
|
+
- Updated dependencies [858ad94]
|
|
68
|
+
- Updated dependencies [2270239]
|
|
69
|
+
- Updated dependencies [8d1195d]
|
|
70
|
+
- @object-ui/core@7.0.0
|
|
71
|
+
- @object-ui/components@7.0.0
|
|
72
|
+
- @object-ui/react@7.0.0
|
|
73
|
+
- @object-ui/types@7.0.0
|
|
74
|
+
|
|
3
75
|
## 6.2.3
|
|
4
76
|
|
|
5
77
|
### Patch Changes
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import * as React from "react";
|
|
8
9
|
/**
|
|
9
10
|
* Props for the Markdown component implementation.
|
|
10
11
|
*
|
|
11
|
-
* This component renders markdown content using react-markdown with GitHub
|
|
12
|
-
* All content is sanitized to prevent XSS attacks.
|
|
12
|
+
* This component renders markdown content using react-markdown with GitHub
|
|
13
|
+
* Flavored Markdown support. All content is sanitized to prevent XSS attacks.
|
|
13
14
|
*/
|
|
14
15
|
export interface MarkdownImplProps {
|
|
15
16
|
/**
|
|
@@ -21,9 +22,10 @@ export interface MarkdownImplProps {
|
|
|
21
22
|
*/
|
|
22
23
|
className?: string;
|
|
23
24
|
}
|
|
25
|
+
export declare function parseMetadataFence(src: string): Record<string, string>;
|
|
24
26
|
/**
|
|
25
27
|
* Internal Markdown implementation component.
|
|
26
28
|
* This contains the actual react-markdown import (heavy ~100-200 KB).
|
|
27
29
|
*/
|
|
28
|
-
export default function MarkdownImpl({ content, className }: MarkdownImplProps):
|
|
30
|
+
export default function MarkdownImpl({ content, className }: MarkdownImplProps): React.JSX.Element;
|
|
29
31
|
//# sourceMappingURL=MarkdownImpl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkdownImpl.d.ts","sourceRoot":"","sources":["../src/MarkdownImpl.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAY9B;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AA2FD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAkBtE;AA8CD;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,iBAAiB,qBAwC7E"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
export declare function Mermaid({ chart }: {
|
|
10
|
+
chart: string;
|
|
11
|
+
}): React.JSX.Element;
|
|
12
|
+
//# sourceMappingURL=Mermaid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mermaid.d.ts","sourceRoot":"","sources":["../src/Mermaid.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AA8B9B,wBAAgB,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,qBAuEnD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
export {}
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export type { MarkdownSchema } from './types';
|
|
3
|
+
export { extractToc, type TocItem } from './toc';
|
|
4
|
+
export { Mermaid } from './Mermaid';
|
|
5
|
+
export interface MarkdownRendererProps {
|
|
6
|
+
schema: {
|
|
7
|
+
type: string;
|
|
8
|
+
id?: string;
|
|
9
|
+
className?: string;
|
|
10
|
+
content?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* MarkdownRenderer - The public API for the markdown component
|
|
15
|
+
* This wrapper handles lazy loading internally using React.Suspense
|
|
16
|
+
*/
|
|
17
|
+
export declare const MarkdownRenderer: React.FC<MarkdownRendererProps>;
|
|
18
|
+
export declare const markdownComponents: {
|
|
19
|
+
markdown: React.FC<MarkdownRendererProps>;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAmB,MAAM,OAAO,CAAC;AAKxC,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,KAAK,OAAO,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAS5D,CAAC;AA2BF,eAAO,MAAM,kBAAkB;;CAE9B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,166 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import a from "react-
|
|
6
|
-
import o from "
|
|
7
|
-
import s from "
|
|
1
|
+
import * as e from "react";
|
|
2
|
+
import t, { Suspense as n } from "react";
|
|
3
|
+
import { ComponentRegistry as r } from "@object-ui/core";
|
|
4
|
+
import { Skeleton as i } from "@object-ui/components";
|
|
5
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
6
|
+
import o from "github-slugger";
|
|
7
|
+
import s from "react-markdown";
|
|
8
|
+
import c from "remark-gfm";
|
|
9
|
+
import { remarkAlert as l } from "remark-github-blockquote-alert";
|
|
10
|
+
import u, { defaultSchema as d } from "rehype-sanitize";
|
|
11
|
+
import f from "rehype-slug";
|
|
12
|
+
import p from "rehype-highlight";
|
|
13
|
+
import m from "rehype-autolink-headings";
|
|
8
14
|
//#region \0rolldown/runtime.js
|
|
9
|
-
var
|
|
15
|
+
var h = Object.defineProperty, g = (e, t) => () => (e && (t = e(e = 0)), t), _ = (e, t) => {
|
|
10
16
|
let n = {};
|
|
11
|
-
for (var r in e)
|
|
17
|
+
for (var r in e) h(n, r, {
|
|
12
18
|
get: e[r],
|
|
13
19
|
enumerable: !0
|
|
14
20
|
});
|
|
15
|
-
return t ||
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
return t || h(n, Symbol.toStringTag, { value: "Module" }), n;
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/toc.ts
|
|
25
|
+
function v(e) {
|
|
26
|
+
return e.replace(/!\[[^\]]*\]\([^)]*\)/g, "").replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/`([^`]+)`/g, "$1").replace(/(\*\*|__)(.*?)\1/g, "$2").replace(/(\*|_)(.*?)\1/g, "$2").replace(/<[^>]+>/g, "").trim();
|
|
27
|
+
}
|
|
28
|
+
function y(e, t) {
|
|
29
|
+
let n = t?.minDepth ?? 2, r = t?.maxDepth ?? 3, i = new o(), a = [], s = null;
|
|
30
|
+
for (let t of (e ?? "").split(/\r?\n/)) {
|
|
31
|
+
let e = t.match(/^\s{0,3}(`{3,}|~{3,})/);
|
|
32
|
+
if (e) {
|
|
33
|
+
let t = e[1][0];
|
|
34
|
+
s === null ? s = t : t === s && (s = null);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (s !== null) continue;
|
|
38
|
+
let o = t.match(/^(#{1,6})\s+(.+?)\s*#*\s*$/);
|
|
39
|
+
if (!o) continue;
|
|
40
|
+
let c = o[1].length, l = v(o[2]);
|
|
41
|
+
if (!l) continue;
|
|
42
|
+
let u = i.slug(l);
|
|
43
|
+
c >= n && c <= r && a.push({
|
|
44
|
+
depth: c,
|
|
45
|
+
text: l,
|
|
46
|
+
id: u
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return a;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/Mermaid.tsx
|
|
53
|
+
function b() {
|
|
54
|
+
return C ||= import("mermaid").then((e) => e.default), C;
|
|
55
|
+
}
|
|
56
|
+
function x() {
|
|
57
|
+
return typeof document < "u" && document.documentElement.classList.contains("dark");
|
|
58
|
+
}
|
|
59
|
+
function S({ chart: t }) {
|
|
60
|
+
let [n, r] = e.useState(""), [i, o] = e.useState(null), [s, c] = e.useState(x);
|
|
61
|
+
return e.useEffect(() => {
|
|
62
|
+
if (typeof document > "u") return;
|
|
63
|
+
let e = document.documentElement, t = new MutationObserver(() => c(x()));
|
|
64
|
+
return t.observe(e, {
|
|
65
|
+
attributes: !0,
|
|
66
|
+
attributeFilter: ["class"]
|
|
67
|
+
}), () => t.disconnect();
|
|
68
|
+
}, []), e.useEffect(() => {
|
|
69
|
+
let e = !1, n = t.trim();
|
|
70
|
+
if (!n) {
|
|
71
|
+
r(""), o(null);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
return b().then(async (t) => {
|
|
75
|
+
t.initialize({
|
|
76
|
+
startOnLoad: !1,
|
|
77
|
+
securityLevel: "strict",
|
|
78
|
+
theme: s ? "dark" : "default"
|
|
79
|
+
});
|
|
80
|
+
let i = `os-mermaid-${w += 1}`, { svg: a } = await t.render(i, n);
|
|
81
|
+
e || (r(a), o(null));
|
|
82
|
+
}).catch((t) => {
|
|
83
|
+
e || o(t instanceof Error ? t.message : String(t));
|
|
84
|
+
}), () => {
|
|
85
|
+
e = !0;
|
|
86
|
+
};
|
|
87
|
+
}, [t, s]), i ? /* @__PURE__ */ a("pre", {
|
|
88
|
+
"data-mermaid": !0,
|
|
89
|
+
"data-mermaid-error": !0,
|
|
90
|
+
className: "my-4 overflow-auto rounded border border-destructive/40 bg-muted p-3 text-xs",
|
|
91
|
+
children: /* @__PURE__ */ a("code", { children: t })
|
|
92
|
+
}) : n ? /* @__PURE__ */ a("div", {
|
|
93
|
+
"data-mermaid": !0,
|
|
94
|
+
role: "img",
|
|
95
|
+
className: "my-4 flex justify-center overflow-auto [&_svg]:h-auto [&_svg]:max-w-full",
|
|
96
|
+
dangerouslySetInnerHTML: { __html: n }
|
|
97
|
+
}) : /* @__PURE__ */ a("div", {
|
|
98
|
+
"data-mermaid": !0,
|
|
99
|
+
"data-mermaid-pending": !0,
|
|
100
|
+
className: "my-4 text-sm text-muted-foreground",
|
|
101
|
+
children: /* @__PURE__ */ a("pre", {
|
|
102
|
+
className: "sr-only",
|
|
103
|
+
children: t
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
var C, w, T = g((() => {
|
|
108
|
+
C = null, w = 0;
|
|
109
|
+
}));
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/markdown-theme.ts
|
|
112
|
+
function E() {
|
|
113
|
+
if (typeof document > "u" || document.getElementById(D)) return;
|
|
114
|
+
let e = document.createElement("style");
|
|
115
|
+
e.id = D, e.textContent = O, document.head.appendChild(e);
|
|
116
|
+
}
|
|
117
|
+
var D, O, k = g((() => {
|
|
118
|
+
D = "os-markdown-styles", O = "\n.os-markdown .md-anchor {\n margin-left: 0.4ch;\n color: var(--muted-foreground);\n text-decoration: none;\n opacity: 0;\n transition: opacity 0.12s ease-in-out;\n}\n.os-markdown :is(h1,h2,h3,h4,h5,h6):hover .md-anchor { opacity: 0.6; }\n.os-markdown .md-anchor:hover { opacity: 1; }\n\n/* highlight.js tokens — light */\n.os-markdown .hljs-comment,\n.os-markdown .hljs-quote { color: var(--muted-foreground); font-style: italic; }\n.os-markdown .hljs-keyword,\n.os-markdown .hljs-selector-tag,\n.os-markdown .hljs-literal,\n.os-markdown .hljs-doctag { color: #8250df; }\n.os-markdown .hljs-string,\n.os-markdown .hljs-regexp,\n.os-markdown .hljs-addition { color: #0a7d33; }\n.os-markdown .hljs-number,\n.os-markdown .hljs-symbol,\n.os-markdown .hljs-bullet { color: #0550ae; }\n.os-markdown .hljs-title,\n.os-markdown .hljs-section,\n.os-markdown .hljs-name,\n.os-markdown .hljs-built_in { color: #6639ba; }\n.os-markdown .hljs-attr,\n.os-markdown .hljs-attribute,\n.os-markdown .hljs-variable,\n.os-markdown .hljs-template-variable { color: #953800; }\n.os-markdown .hljs-type,\n.os-markdown .hljs-class .hljs-title { color: #0550ae; }\n.os-markdown .hljs-meta { color: var(--muted-foreground); }\n.os-markdown .hljs-deletion { color: #b35900; }\n.os-markdown .hljs-emphasis { font-style: italic; }\n.os-markdown .hljs-strong { font-weight: 600; }\n\n/* highlight.js tokens — dark */\n.dark .os-markdown .hljs-keyword,\n.dark .os-markdown .hljs-selector-tag,\n.dark .os-markdown .hljs-literal,\n.dark .os-markdown .hljs-doctag { color: #d2a8ff; }\n.dark .os-markdown .hljs-string,\n.dark .os-markdown .hljs-regexp,\n.dark .os-markdown .hljs-addition { color: #7ee787; }\n.dark .os-markdown .hljs-number,\n.dark .os-markdown .hljs-symbol,\n.dark .os-markdown .hljs-bullet { color: #79c0ff; }\n.dark .os-markdown .hljs-title,\n.dark .os-markdown .hljs-section,\n.dark .os-markdown .hljs-name,\n.dark .os-markdown .hljs-built_in { color: #d2a8ff; }\n.dark .os-markdown .hljs-attr,\n.dark .os-markdown .hljs-attribute,\n.dark .os-markdown .hljs-variable,\n.dark .os-markdown .hljs-template-variable { color: #ffa657; }\n.dark .os-markdown .hljs-type,\n.dark .os-markdown .hljs-class .hljs-title { color: #79c0ff; }\n.dark .os-markdown .hljs-deletion { color: #ffa198; }\n\n/* GitHub-style alert callouts (icon = CSS pseudo-element, no SVG) */\n.os-markdown .markdown-alert {\n margin: 1em 0;\n padding: 0.6em 1em;\n border-left: 0.25em solid var(--border);\n border-radius: 0.375rem;\n background: color-mix(in srgb, var(--muted) 40%, transparent);\n}\n.os-markdown .markdown-alert > :first-child { margin-top: 0; }\n.os-markdown .markdown-alert > :last-child { margin-bottom: 0; }\n.os-markdown .markdown-alert-title {\n display: flex;\n align-items: center;\n font-weight: 600;\n line-height: 1;\n text-transform: capitalize;\n}\n.os-markdown .markdown-alert-title::before {\n margin-right: 0.5ch;\n font-weight: 700;\n}\n.os-markdown .markdown-alert-note { border-left-color: #0969da; }\n.os-markdown .markdown-alert-note .markdown-alert-title { color: #0969da; }\n.os-markdown .markdown-alert-note .markdown-alert-title::before { content: \"ⓘ\"; }\n.os-markdown .markdown-alert-tip { border-left-color: #1a7f37; }\n.os-markdown .markdown-alert-tip .markdown-alert-title { color: #1a7f37; }\n.os-markdown .markdown-alert-tip .markdown-alert-title::before { content: \"💡\"; }\n.os-markdown .markdown-alert-important { border-left-color: #8250df; }\n.os-markdown .markdown-alert-important .markdown-alert-title { color: #8250df; }\n.os-markdown .markdown-alert-important .markdown-alert-title::before { content: \"❖\"; }\n.os-markdown .markdown-alert-warning { border-left-color: #9a6700; }\n.os-markdown .markdown-alert-warning .markdown-alert-title { color: #9a6700; }\n.os-markdown .markdown-alert-warning .markdown-alert-title::before { content: \"⚠\"; }\n.os-markdown .markdown-alert-caution { border-left-color: var(--destructive); }\n.os-markdown .markdown-alert-caution .markdown-alert-title { color: var(--destructive); }\n.os-markdown .markdown-alert-caution .markdown-alert-title::before { content: \"⛔\"; }\n.dark .os-markdown .markdown-alert-note { border-left-color: #4493f8; }\n.dark .os-markdown .markdown-alert-note .markdown-alert-title { color: #4493f8; }\n.dark .os-markdown .markdown-alert-tip { border-left-color: #3fb950; }\n.dark .os-markdown .markdown-alert-tip .markdown-alert-title { color: #3fb950; }\n.dark .os-markdown .markdown-alert-important { border-left-color: #ab7df8; }\n.dark .os-markdown .markdown-alert-important .markdown-alert-title { color: #ab7df8; }\n.dark .os-markdown .markdown-alert-warning { border-left-color: #d29922; }\n.dark .os-markdown .markdown-alert-warning .markdown-alert-title { color: #d29922; }\n\n/* Bordered tables: @tailwindcss/typography zeroes padding on each row's\n first (inline-start) and last (inline-end) cell because it assumes\n borderless tables. We add cell borders (prose-th/td:border), so restore\n symmetric horizontal padding — otherwise the first column's text sits\n flush against the left border, misaligned with every other column. The\n 0.6666667em matches prose-sm's inner-cell padding. The .os-markdown\n class selector outranks typography's zero-specificity :where() rules. */\n.os-markdown table th:first-child,\n.os-markdown table td:first-child { padding-inline-start: 0.6666667em; }\n.os-markdown table th:last-child,\n.os-markdown table td:last-child { padding-inline-end: 0.6666667em; }\n";
|
|
119
|
+
})), A = /* @__PURE__ */ _({
|
|
120
|
+
default: () => F,
|
|
121
|
+
parseMetadataFence: () => N
|
|
122
|
+
});
|
|
123
|
+
function j() {
|
|
124
|
+
let e = (e) => typeof e == "string" ? e.split(/\s+/).filter(Boolean) : Array.isArray(e) ? e : [], t = (n) => {
|
|
125
|
+
if (!n || typeof n != "object") return;
|
|
126
|
+
let r = n.properties;
|
|
127
|
+
if (r && (typeof r.class == "string" || typeof r.className == "string") && (r.className = [...e(r.className), ...e(r.class)], delete r.class), Array.isArray(n.children)) for (let e of n.children) t(e);
|
|
128
|
+
};
|
|
129
|
+
return (e) => t(e);
|
|
130
|
+
}
|
|
131
|
+
function M(t) {
|
|
132
|
+
return typeof t == "string" ? t : typeof t == "number" ? String(t) : Array.isArray(t) ? t.map(M).join("") : e.isValidElement(t) ? M(t.props.children) : "";
|
|
133
|
+
}
|
|
134
|
+
function N(e) {
|
|
135
|
+
let t = {};
|
|
136
|
+
for (let n of e.split("\n")) {
|
|
137
|
+
let e = n.trim();
|
|
138
|
+
if (!e || e.startsWith("#")) continue;
|
|
139
|
+
let r = e.indexOf(":");
|
|
140
|
+
if (r < 1) continue;
|
|
141
|
+
let i = e.slice(0, r).trim(), a = e.slice(r + 1).trim();
|
|
142
|
+
(a.startsWith("\"") && a.endsWith("\"") || a.startsWith("'") && a.endsWith("'")) && (a = a.slice(1, -1)), i && (t[i] = a);
|
|
143
|
+
}
|
|
144
|
+
return t;
|
|
145
|
+
}
|
|
146
|
+
function P({ source: t }) {
|
|
147
|
+
let n = e.useMemo(() => N(t), [t]), i = r.get("element:metadata_viewer");
|
|
148
|
+
return i ? /* @__PURE__ */ a("div", {
|
|
149
|
+
className: "not-prose my-4",
|
|
150
|
+
children: /* @__PURE__ */ a(i, { schema: {
|
|
151
|
+
type: "element:metadata_viewer",
|
|
152
|
+
properties: n
|
|
153
|
+
} })
|
|
154
|
+
}) : /* @__PURE__ */ a("pre", { children: /* @__PURE__ */ a("code", { children: t }) });
|
|
155
|
+
}
|
|
156
|
+
function F({ content: e, className: t }) {
|
|
157
|
+
return E(), /* @__PURE__ */ a("div", {
|
|
19
158
|
"data-slot": "markdown",
|
|
20
|
-
className: ((...e) => e.filter(Boolean).join(" "))("prose prose-sm dark:prose-invert max-w-none", "prose-headings:font-semibold prose-headings:tracking-tight", "prose-h1:text-3xl prose-h2:text-2xl prose-h3:text-xl", "prose-p:leading-relaxed prose-p:text-foreground", "prose-a:text-primary prose-a:no-underline hover:prose-a:underline", "prose-code:text-foreground prose-code:bg-muted prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:before:content-none prose-code:after:content-none", "prose-pre:bg-muted prose-pre:text-foreground prose-pre:border", "prose-blockquote:border-l-primary prose-blockquote:text-muted-foreground", "prose-strong:text-foreground prose-strong:font-semibold", "prose-ul:list-disc prose-ol:list-decimal", "prose-li:text-foreground prose-li:marker:text-muted-foreground", "prose-table:border prose-th:border prose-th:bg-muted prose-td:border", "prose-img:rounded-md prose-img:border", t),
|
|
21
|
-
children: /* @__PURE__ */
|
|
22
|
-
remarkPlugins:
|
|
23
|
-
rehypePlugins:
|
|
159
|
+
className: ((...e) => e.filter(Boolean).join(" "))("prose prose-sm dark:prose-invert max-w-none", "prose-headings:font-semibold prose-headings:tracking-tight", "prose-h1:text-3xl prose-h2:text-2xl prose-h3:text-xl", "prose-p:leading-relaxed prose-p:text-foreground", "prose-a:text-primary prose-a:no-underline hover:prose-a:underline", "prose-code:text-foreground prose-code:bg-muted prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:before:content-none prose-code:after:content-none", "prose-pre:bg-muted prose-pre:text-foreground prose-pre:border", "prose-blockquote:border-l-primary prose-blockquote:text-muted-foreground", "prose-strong:text-foreground prose-strong:font-semibold", "prose-ul:list-disc prose-ol:list-decimal", "prose-li:text-foreground prose-li:marker:text-muted-foreground", "prose-table:border prose-th:border prose-th:bg-muted prose-td:border", "prose-img:rounded-md prose-img:border", "os-markdown", t),
|
|
160
|
+
children: /* @__PURE__ */ a(s, {
|
|
161
|
+
remarkPlugins: R,
|
|
162
|
+
rehypePlugins: z,
|
|
163
|
+
components: B,
|
|
24
164
|
disallowedElements: [
|
|
25
165
|
"script",
|
|
26
166
|
"style",
|
|
@@ -33,14 +173,64 @@ function d({ content: e, className: t }) {
|
|
|
33
173
|
})
|
|
34
174
|
});
|
|
35
175
|
}
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
|
|
176
|
+
var I, L, R, z, B, V = g((() => {
|
|
177
|
+
k(), T(), I = (e) => (e ?? []).filter((e) => !(Array.isArray(e) && e[0] === "className")), L = {
|
|
178
|
+
...d,
|
|
179
|
+
clobberPrefix: "",
|
|
180
|
+
tagNames: [
|
|
181
|
+
...d.tagNames ?? [],
|
|
182
|
+
"span",
|
|
183
|
+
"div"
|
|
184
|
+
],
|
|
185
|
+
attributes: {
|
|
186
|
+
...d.attributes,
|
|
187
|
+
"*": [...d.attributes?.["*"] ?? [], "className"],
|
|
188
|
+
a: [
|
|
189
|
+
...I(d.attributes?.a),
|
|
190
|
+
"ariaHidden",
|
|
191
|
+
"tabIndex"
|
|
192
|
+
]
|
|
193
|
+
}
|
|
194
|
+
}, R = [c, l], z = [
|
|
195
|
+
f,
|
|
196
|
+
j,
|
|
197
|
+
[p, {
|
|
198
|
+
detect: !0,
|
|
199
|
+
ignoreMissing: !0,
|
|
200
|
+
plainText: ["mermaid", "metadata"]
|
|
201
|
+
}],
|
|
202
|
+
[m, {
|
|
203
|
+
behavior: "append",
|
|
204
|
+
properties: {
|
|
205
|
+
className: ["md-anchor"],
|
|
206
|
+
ariaHidden: !0,
|
|
207
|
+
tabIndex: -1
|
|
208
|
+
},
|
|
209
|
+
content: {
|
|
210
|
+
type: "text",
|
|
211
|
+
value: "#"
|
|
212
|
+
}
|
|
213
|
+
}],
|
|
214
|
+
[u, L]
|
|
215
|
+
], B = { pre({ node: t, children: n, ...r }) {
|
|
216
|
+
let i = e.Children.toArray(n)[0], o = e.isValidElement(i) && typeof i.props.className == "string" ? i.props.className : "";
|
|
217
|
+
return /\blanguage-mermaid\b/.test(o) ? /* @__PURE__ */ a(S, { chart: M(i.props.children) }) : /\blanguage-metadata\b/.test(o) ? /* @__PURE__ */ a(P, { source: M(i.props.children) }) : /* @__PURE__ */ a("pre", {
|
|
218
|
+
...r,
|
|
219
|
+
children: n
|
|
220
|
+
});
|
|
221
|
+
} };
|
|
222
|
+
}));
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/index.tsx
|
|
225
|
+
T();
|
|
226
|
+
var H = t.lazy(() => Promise.resolve().then(() => (V(), A))), U = ({ schema: e }) => /* @__PURE__ */ a(n, {
|
|
227
|
+
fallback: /* @__PURE__ */ a(i, { className: "w-full h-[200px]" }),
|
|
228
|
+
children: /* @__PURE__ */ a(H, {
|
|
39
229
|
content: e.content || "",
|
|
40
230
|
className: e.className
|
|
41
231
|
})
|
|
42
232
|
});
|
|
43
|
-
|
|
233
|
+
r.register("markdown", U, {
|
|
44
234
|
namespace: "plugin-markdown",
|
|
45
235
|
label: "Markdown",
|
|
46
236
|
category: "plugin",
|
|
@@ -57,6 +247,6 @@ n.register("markdown", m, {
|
|
|
57
247
|
}],
|
|
58
248
|
defaultProps: { content: "# Hello World\n\nThis is a **markdown** component with *formatting* support.\n\n- Item 1\n- Item 2\n- Item 3" }
|
|
59
249
|
});
|
|
60
|
-
var
|
|
250
|
+
var W = { markdown: U };
|
|
61
251
|
//#endregion
|
|
62
|
-
export {
|
|
252
|
+
export { U as MarkdownRenderer, S as Mermaid, y as extractToc, W as markdownComponents };
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,7 +1,126 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("@object-ui/core"),require("@object-ui/components"),require("react/jsx-runtime"),require("react-markdown"),require("remark-gfm"),require("rehype-sanitize")):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/components`,`react/jsx-runtime`,`react-markdown`,`remark-gfm`,`rehype-sanitize`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginMarkdown={},e.React,e.ObjectUICore,e.ObjectUIComponents,e.react_jsx_runtime,e.
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("@object-ui/core"),require("@object-ui/components"),require("react/jsx-runtime"),require("github-slugger"),require("react-markdown"),require("remark-gfm"),require("remark-github-blockquote-alert"),require("rehype-sanitize"),require("rehype-slug"),require("rehype-highlight"),require("rehype-autolink-headings")):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/components`,`react/jsx-runtime`,`github-slugger`,`react-markdown`,`remark-gfm`,`remark-github-blockquote-alert`,`rehype-sanitize`,`rehype-slug`,`rehype-highlight`,`rehype-autolink-headings`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginMarkdown={},e.React,e.ObjectUICore,e.ObjectUIComponents,e.react_jsx_runtime,e.github_slugger,e.ReactMarkdown,e.remarkGfm,e.remarkGithubBlockquoteAlert,e.rehypeSanitize,e.rehypeSlug,e.rehypeHighlight,e.rehypeAutolinkHeadings))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var p=Object.create,m=Object.defineProperty,h=Object.getOwnPropertyDescriptor,g=Object.getOwnPropertyNames,_=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty,y=(e,t)=>()=>(e&&(t=e(e=0)),t),b=(e,t)=>{let n={};for(var r in e)m(n,r,{get:e[r],enumerable:!0});return t||m(n,Symbol.toStringTag,{value:`Module`}),n},x=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=g(t),a=0,o=i.length,s;a<o;a++)s=i[a],!v.call(e,s)&&s!==n&&m(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=h(t,s))||r.enumerable});return e},S=(e,t,n)=>(n=e==null?{}:p(_(e)),x(t||!e||!e.__esModule?m(n,`default`,{value:e,enumerable:!0}):n,e));t=S(t,1),a=S(a,1),o=S(o,1),s=S(s,1),l=S(l,1),u=S(u,1),d=S(d,1),f=S(f,1);function C(e){return e.replace(/!\[[^\]]*\]\([^)]*\)/g,``).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/`([^`]+)`/g,`$1`).replace(/(\*\*|__)(.*?)\1/g,`$2`).replace(/(\*|_)(.*?)\1/g,`$2`).replace(/<[^>]+>/g,``).trim()}function w(e,t){let n=t?.minDepth??2,r=t?.maxDepth??3,i=new a.default,o=[],s=null;for(let t of(e??``).split(/\r?\n/)){let e=t.match(/^\s{0,3}(`{3,}|~{3,})/);if(e){let t=e[1][0];s===null?s=t:t===s&&(s=null);continue}if(s!==null)continue;let a=t.match(/^(#{1,6})\s+(.+?)\s*#*\s*$/);if(!a)continue;let c=a[1].length,l=C(a[2]);if(!l)continue;let u=i.slug(l);c>=n&&c<=r&&o.push({depth:c,text:l,id:u})}return o}function T(){return O||=import(`mermaid`).then(e=>e.default),O}function E(){return typeof document<`u`&&document.documentElement.classList.contains(`dark`)}function D({chart:e}){let[n,r]=t.useState(``),[a,o]=t.useState(null),[s,c]=t.useState(E);return t.useEffect(()=>{if(typeof document>`u`)return;let e=document.documentElement,t=new MutationObserver(()=>c(E()));return t.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]),t.useEffect(()=>{let t=!1,n=e.trim();if(!n){r(``),o(null);return}return T().then(async e=>{e.initialize({startOnLoad:!1,securityLevel:`strict`,theme:s?`dark`:`default`});let i=`os-mermaid-${k+=1}`,{svg:a}=await e.render(i,n);t||(r(a),o(null))}).catch(e=>{t||o(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e,s]),a?(0,i.jsx)(`pre`,{"data-mermaid":!0,"data-mermaid-error":!0,className:`my-4 overflow-auto rounded border border-destructive/40 bg-muted p-3 text-xs`,children:(0,i.jsx)(`code`,{children:e})}):n?(0,i.jsx)(`div`,{"data-mermaid":!0,role:`img`,className:`my-4 flex justify-center overflow-auto [&_svg]:h-auto [&_svg]:max-w-full`,dangerouslySetInnerHTML:{__html:n}}):(0,i.jsx)(`div`,{"data-mermaid":!0,"data-mermaid-pending":!0,className:`my-4 text-sm text-muted-foreground`,children:(0,i.jsx)(`pre`,{className:`sr-only`,children:e})})}var O,k,A=y((()=>{O=null,k=0}));function j(){if(typeof document>`u`||document.getElementById(M))return;let e=document.createElement(`style`);e.id=M,e.textContent=N,document.head.appendChild(e)}var M,N,P=y((()=>{M=`os-markdown-styles`,N=`
|
|
2
|
+
.os-markdown .md-anchor {
|
|
3
|
+
margin-left: 0.4ch;
|
|
4
|
+
color: var(--muted-foreground);
|
|
5
|
+
text-decoration: none;
|
|
6
|
+
opacity: 0;
|
|
7
|
+
transition: opacity 0.12s ease-in-out;
|
|
8
|
+
}
|
|
9
|
+
.os-markdown :is(h1,h2,h3,h4,h5,h6):hover .md-anchor { opacity: 0.6; }
|
|
10
|
+
.os-markdown .md-anchor:hover { opacity: 1; }
|
|
11
|
+
|
|
12
|
+
/* highlight.js tokens — light */
|
|
13
|
+
.os-markdown .hljs-comment,
|
|
14
|
+
.os-markdown .hljs-quote { color: var(--muted-foreground); font-style: italic; }
|
|
15
|
+
.os-markdown .hljs-keyword,
|
|
16
|
+
.os-markdown .hljs-selector-tag,
|
|
17
|
+
.os-markdown .hljs-literal,
|
|
18
|
+
.os-markdown .hljs-doctag { color: #8250df; }
|
|
19
|
+
.os-markdown .hljs-string,
|
|
20
|
+
.os-markdown .hljs-regexp,
|
|
21
|
+
.os-markdown .hljs-addition { color: #0a7d33; }
|
|
22
|
+
.os-markdown .hljs-number,
|
|
23
|
+
.os-markdown .hljs-symbol,
|
|
24
|
+
.os-markdown .hljs-bullet { color: #0550ae; }
|
|
25
|
+
.os-markdown .hljs-title,
|
|
26
|
+
.os-markdown .hljs-section,
|
|
27
|
+
.os-markdown .hljs-name,
|
|
28
|
+
.os-markdown .hljs-built_in { color: #6639ba; }
|
|
29
|
+
.os-markdown .hljs-attr,
|
|
30
|
+
.os-markdown .hljs-attribute,
|
|
31
|
+
.os-markdown .hljs-variable,
|
|
32
|
+
.os-markdown .hljs-template-variable { color: #953800; }
|
|
33
|
+
.os-markdown .hljs-type,
|
|
34
|
+
.os-markdown .hljs-class .hljs-title { color: #0550ae; }
|
|
35
|
+
.os-markdown .hljs-meta { color: var(--muted-foreground); }
|
|
36
|
+
.os-markdown .hljs-deletion { color: #b35900; }
|
|
37
|
+
.os-markdown .hljs-emphasis { font-style: italic; }
|
|
38
|
+
.os-markdown .hljs-strong { font-weight: 600; }
|
|
39
|
+
|
|
40
|
+
/* highlight.js tokens — dark */
|
|
41
|
+
.dark .os-markdown .hljs-keyword,
|
|
42
|
+
.dark .os-markdown .hljs-selector-tag,
|
|
43
|
+
.dark .os-markdown .hljs-literal,
|
|
44
|
+
.dark .os-markdown .hljs-doctag { color: #d2a8ff; }
|
|
45
|
+
.dark .os-markdown .hljs-string,
|
|
46
|
+
.dark .os-markdown .hljs-regexp,
|
|
47
|
+
.dark .os-markdown .hljs-addition { color: #7ee787; }
|
|
48
|
+
.dark .os-markdown .hljs-number,
|
|
49
|
+
.dark .os-markdown .hljs-symbol,
|
|
50
|
+
.dark .os-markdown .hljs-bullet { color: #79c0ff; }
|
|
51
|
+
.dark .os-markdown .hljs-title,
|
|
52
|
+
.dark .os-markdown .hljs-section,
|
|
53
|
+
.dark .os-markdown .hljs-name,
|
|
54
|
+
.dark .os-markdown .hljs-built_in { color: #d2a8ff; }
|
|
55
|
+
.dark .os-markdown .hljs-attr,
|
|
56
|
+
.dark .os-markdown .hljs-attribute,
|
|
57
|
+
.dark .os-markdown .hljs-variable,
|
|
58
|
+
.dark .os-markdown .hljs-template-variable { color: #ffa657; }
|
|
59
|
+
.dark .os-markdown .hljs-type,
|
|
60
|
+
.dark .os-markdown .hljs-class .hljs-title { color: #79c0ff; }
|
|
61
|
+
.dark .os-markdown .hljs-deletion { color: #ffa198; }
|
|
62
|
+
|
|
63
|
+
/* GitHub-style alert callouts (icon = CSS pseudo-element, no SVG) */
|
|
64
|
+
.os-markdown .markdown-alert {
|
|
65
|
+
margin: 1em 0;
|
|
66
|
+
padding: 0.6em 1em;
|
|
67
|
+
border-left: 0.25em solid var(--border);
|
|
68
|
+
border-radius: 0.375rem;
|
|
69
|
+
background: color-mix(in srgb, var(--muted) 40%, transparent);
|
|
70
|
+
}
|
|
71
|
+
.os-markdown .markdown-alert > :first-child { margin-top: 0; }
|
|
72
|
+
.os-markdown .markdown-alert > :last-child { margin-bottom: 0; }
|
|
73
|
+
.os-markdown .markdown-alert-title {
|
|
74
|
+
display: flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
font-weight: 600;
|
|
77
|
+
line-height: 1;
|
|
78
|
+
text-transform: capitalize;
|
|
79
|
+
}
|
|
80
|
+
.os-markdown .markdown-alert-title::before {
|
|
81
|
+
margin-right: 0.5ch;
|
|
82
|
+
font-weight: 700;
|
|
83
|
+
}
|
|
84
|
+
.os-markdown .markdown-alert-note { border-left-color: #0969da; }
|
|
85
|
+
.os-markdown .markdown-alert-note .markdown-alert-title { color: #0969da; }
|
|
86
|
+
.os-markdown .markdown-alert-note .markdown-alert-title::before { content: "ⓘ"; }
|
|
87
|
+
.os-markdown .markdown-alert-tip { border-left-color: #1a7f37; }
|
|
88
|
+
.os-markdown .markdown-alert-tip .markdown-alert-title { color: #1a7f37; }
|
|
89
|
+
.os-markdown .markdown-alert-tip .markdown-alert-title::before { content: "💡"; }
|
|
90
|
+
.os-markdown .markdown-alert-important { border-left-color: #8250df; }
|
|
91
|
+
.os-markdown .markdown-alert-important .markdown-alert-title { color: #8250df; }
|
|
92
|
+
.os-markdown .markdown-alert-important .markdown-alert-title::before { content: "❖"; }
|
|
93
|
+
.os-markdown .markdown-alert-warning { border-left-color: #9a6700; }
|
|
94
|
+
.os-markdown .markdown-alert-warning .markdown-alert-title { color: #9a6700; }
|
|
95
|
+
.os-markdown .markdown-alert-warning .markdown-alert-title::before { content: "⚠"; }
|
|
96
|
+
.os-markdown .markdown-alert-caution { border-left-color: var(--destructive); }
|
|
97
|
+
.os-markdown .markdown-alert-caution .markdown-alert-title { color: var(--destructive); }
|
|
98
|
+
.os-markdown .markdown-alert-caution .markdown-alert-title::before { content: "⛔"; }
|
|
99
|
+
.dark .os-markdown .markdown-alert-note { border-left-color: #4493f8; }
|
|
100
|
+
.dark .os-markdown .markdown-alert-note .markdown-alert-title { color: #4493f8; }
|
|
101
|
+
.dark .os-markdown .markdown-alert-tip { border-left-color: #3fb950; }
|
|
102
|
+
.dark .os-markdown .markdown-alert-tip .markdown-alert-title { color: #3fb950; }
|
|
103
|
+
.dark .os-markdown .markdown-alert-important { border-left-color: #ab7df8; }
|
|
104
|
+
.dark .os-markdown .markdown-alert-important .markdown-alert-title { color: #ab7df8; }
|
|
105
|
+
.dark .os-markdown .markdown-alert-warning { border-left-color: #d29922; }
|
|
106
|
+
.dark .os-markdown .markdown-alert-warning .markdown-alert-title { color: #d29922; }
|
|
107
|
+
|
|
108
|
+
/* Bordered tables: @tailwindcss/typography zeroes padding on each row's
|
|
109
|
+
first (inline-start) and last (inline-end) cell because it assumes
|
|
110
|
+
borderless tables. We add cell borders (prose-th/td:border), so restore
|
|
111
|
+
symmetric horizontal padding — otherwise the first column's text sits
|
|
112
|
+
flush against the left border, misaligned with every other column. The
|
|
113
|
+
0.6666667em matches prose-sm's inner-cell padding. The .os-markdown
|
|
114
|
+
class selector outranks typography's zero-specificity :where() rules. */
|
|
115
|
+
.os-markdown table th:first-child,
|
|
116
|
+
.os-markdown table td:first-child { padding-inline-start: 0.6666667em; }
|
|
117
|
+
.os-markdown table th:last-child,
|
|
118
|
+
.os-markdown table td:last-child { padding-inline-end: 0.6666667em; }
|
|
119
|
+
`})),F=b({default:()=>B,parseMetadataFence:()=>R});function I(){let e=e=>typeof e==`string`?e.split(/\s+/).filter(Boolean):Array.isArray(e)?e:[],t=n=>{if(!n||typeof n!=`object`)return;let r=n.properties;if(r&&(typeof r.class==`string`||typeof r.className==`string`)&&(r.className=[...e(r.className),...e(r.class)],delete r.class),Array.isArray(n.children))for(let e of n.children)t(e)};return e=>t(e)}function L(e){return typeof e==`string`?e:typeof e==`number`?String(e):Array.isArray(e)?e.map(L).join(``):t.isValidElement(e)?L(e.props.children):``}function R(e){let t={};for(let n of e.split(`
|
|
120
|
+
`)){let e=n.trim();if(!e||e.startsWith(`#`))continue;let r=e.indexOf(`:`);if(r<1)continue;let i=e.slice(0,r).trim(),a=e.slice(r+1).trim();(a.startsWith(`"`)&&a.endsWith(`"`)||a.startsWith(`'`)&&a.endsWith(`'`))&&(a=a.slice(1,-1)),i&&(t[i]=a)}return t}function z({source:e}){let r=t.useMemo(()=>R(e),[e]),a=n.ComponentRegistry.get(`element:metadata_viewer`);return a?(0,i.jsx)(`div`,{className:`not-prose my-4`,children:(0,i.jsx)(a,{schema:{type:`element:metadata_viewer`,properties:r}})}):(0,i.jsx)(`pre`,{children:(0,i.jsx)(`code`,{children:e})})}function B({content:e,className:t}){return j(),(0,i.jsx)(`div`,{"data-slot":`markdown`,className:((...e)=>e.filter(Boolean).join(` `))(`prose prose-sm dark:prose-invert max-w-none`,`prose-headings:font-semibold prose-headings:tracking-tight`,`prose-h1:text-3xl prose-h2:text-2xl prose-h3:text-xl`,`prose-p:leading-relaxed prose-p:text-foreground`,`prose-a:text-primary prose-a:no-underline hover:prose-a:underline`,`prose-code:text-foreground prose-code:bg-muted prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:before:content-none prose-code:after:content-none`,`prose-pre:bg-muted prose-pre:text-foreground prose-pre:border`,`prose-blockquote:border-l-primary prose-blockquote:text-muted-foreground`,`prose-strong:text-foreground prose-strong:font-semibold`,`prose-ul:list-disc prose-ol:list-decimal`,`prose-li:text-foreground prose-li:marker:text-muted-foreground`,`prose-table:border prose-th:border prose-th:bg-muted prose-td:border`,`prose-img:rounded-md prose-img:border`,`os-markdown`,t),children:(0,i.jsx)(o.default,{remarkPlugins:U,rehypePlugins:W,components:G,disallowedElements:[`script`,`style`,`iframe`,`object`,`embed`],unwrapDisallowed:!0,children:e})})}var V,H,U,W,G,K=y((()=>{P(),A(),V=e=>(e??[]).filter(e=>!(Array.isArray(e)&&e[0]===`className`)),H={...l.defaultSchema,clobberPrefix:``,tagNames:[...l.defaultSchema.tagNames??[],`span`,`div`],attributes:{...l.defaultSchema.attributes,"*":[...l.defaultSchema.attributes?.[`*`]??[],`className`],a:[...V(l.defaultSchema.attributes?.a),`ariaHidden`,`tabIndex`]}},U=[s.default,c.remarkAlert],W=[u.default,I,[d.default,{detect:!0,ignoreMissing:!0,plainText:[`mermaid`,`metadata`]}],[f.default,{behavior:`append`,properties:{className:[`md-anchor`],ariaHidden:!0,tabIndex:-1},content:{type:`text`,value:`#`}}],[l.default,H]],G={pre({node:e,children:n,...r}){let a=t.Children.toArray(n)[0],o=t.isValidElement(a)&&typeof a.props.className==`string`?a.props.className:``;return/\blanguage-mermaid\b/.test(o)?(0,i.jsx)(D,{chart:L(a.props.children)}):/\blanguage-metadata\b/.test(o)?(0,i.jsx)(z,{source:L(a.props.children)}):(0,i.jsx)(`pre`,{...r,children:n})}}}));A();var q=t.default.lazy(()=>Promise.resolve().then(()=>(K(),F))),J=({schema:e})=>(0,i.jsx)(t.Suspense,{fallback:(0,i.jsx)(r.Skeleton,{className:`w-full h-[200px]`}),children:(0,i.jsx)(q,{content:e.content||``,className:e.className})});n.ComponentRegistry.register(`markdown`,J,{namespace:`plugin-markdown`,label:`Markdown`,category:`plugin`,inputs:[{name:`content`,type:`string`,label:`Markdown Content`,required:!0,inputType:`textarea`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{content:`# Hello World
|
|
2
121
|
|
|
3
122
|
This is a **markdown** component with *formatting* support.
|
|
4
123
|
|
|
5
124
|
- Item 1
|
|
6
125
|
- Item 2
|
|
7
|
-
- Item 3`}});var
|
|
126
|
+
- Item 3`}});var Y={markdown:J};e.MarkdownRenderer=J,e.Mermaid=D,e.extractToc=w,e.markdownComponents=Y});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Inject the markdown enrichment styles once. No-op on the server (no
|
|
10
|
+
* `document`) and idempotent across many rendered markdown instances.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ensureMarkdownStyles(): void;
|
|
13
|
+
//# sourceMappingURL=markdown-theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-theme.d.ts","sourceRoot":"","sources":["../src/markdown-theme.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA0IH;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAO3C"}
|
package/dist/toc.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export interface TocItem {
|
|
9
|
+
/** Heading level (1–6). */
|
|
10
|
+
depth: number;
|
|
11
|
+
/** Visible heading text, inline markdown stripped. */
|
|
12
|
+
text: string;
|
|
13
|
+
/** Slug id, identical to what `rehype-slug` puts on the rendered heading. */
|
|
14
|
+
id: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Build a table of contents from Markdown source.
|
|
18
|
+
*
|
|
19
|
+
* Slugs are generated with the SAME `github-slugger` that `rehype-slug` uses,
|
|
20
|
+
* walking every heading in document order so duplicate-heading `-1/-2` suffixes
|
|
21
|
+
* line up — that is what makes a `#id` TOC link resolve to the rendered
|
|
22
|
+
* heading's anchor. Headings inside fenced code blocks are ignored. Only
|
|
23
|
+
* `minDepth..maxDepth` (default h2–h3) are returned, but all headings still
|
|
24
|
+
* advance the slugger so ids stay in sync.
|
|
25
|
+
*/
|
|
26
|
+
export declare function extractToc(markdown: string, opts?: {
|
|
27
|
+
minDepth?: number;
|
|
28
|
+
maxDepth?: number;
|
|
29
|
+
}): TocItem[];
|
|
30
|
+
//# sourceMappingURL=toc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc.d.ts","sourceRoot":"","sources":["../src/toc.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,WAAW,OAAO;IACtB,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAA;IACZ,6EAA6E;IAC7E,EAAE,EAAE,MAAM,CAAA;CACX;AAcD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9C,OAAO,EAAE,CA0BX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,IAAI,EAAE,UAAU,CAAC;IAEjB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-markdown",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Markdown rendering plugin for Object UI, powered by react-markdown",
|
|
@@ -24,25 +24,31 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"github-slugger": "^2.0.0",
|
|
28
|
+
"mermaid": "^11.15.0",
|
|
27
29
|
"react-markdown": "^10.1.0",
|
|
30
|
+
"rehype-autolink-headings": "^7.1.0",
|
|
31
|
+
"rehype-highlight": "^7.0.2",
|
|
28
32
|
"rehype-sanitize": "^6.0.0",
|
|
33
|
+
"rehype-slug": "^6.0.0",
|
|
29
34
|
"remark-gfm": "^4.0.1",
|
|
30
|
-
"
|
|
31
|
-
"@object-ui/
|
|
32
|
-
"@object-ui/
|
|
33
|
-
"@object-ui/
|
|
35
|
+
"remark-github-blockquote-alert": "^2.1.0",
|
|
36
|
+
"@object-ui/components": "7.1.0",
|
|
37
|
+
"@object-ui/core": "7.1.0",
|
|
38
|
+
"@object-ui/react": "7.1.0",
|
|
39
|
+
"@object-ui/types": "7.1.0"
|
|
34
40
|
},
|
|
35
41
|
"peerDependencies": {
|
|
36
42
|
"react": "^18.0.0 || ^19.0.0",
|
|
37
43
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
38
44
|
},
|
|
39
45
|
"devDependencies": {
|
|
40
|
-
"@types/react": "19.2.
|
|
46
|
+
"@types/react": "19.2.17",
|
|
41
47
|
"@types/react-dom": "19.2.3",
|
|
42
48
|
"@vitejs/plugin-react": "^6.0.2",
|
|
43
49
|
"typescript": "^6.0.3",
|
|
44
|
-
"vite": "^8.0.
|
|
45
|
-
"vite-plugin-dts": "^5.0.
|
|
50
|
+
"vite": "^8.0.16",
|
|
51
|
+
"vite-plugin-dts": "^5.0.2"
|
|
46
52
|
},
|
|
47
53
|
"keywords": [
|
|
48
54
|
"objectui",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownImpl.d.ts","sourceRoot":"","sources":["../../../../src/MarkdownImpl.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,iBAAiB,2CAoC7E"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
export type { MarkdownSchema } from './types';
|
|
3
|
-
export interface MarkdownRendererProps {
|
|
4
|
-
schema: {
|
|
5
|
-
type: string;
|
|
6
|
-
id?: string;
|
|
7
|
-
className?: string;
|
|
8
|
-
content?: string;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* MarkdownRenderer - The public API for the markdown component
|
|
13
|
-
* This wrapper handles lazy loading internally using React.Suspense
|
|
14
|
-
*/
|
|
15
|
-
export declare const MarkdownRenderer: React.FC<MarkdownRendererProps>;
|
|
16
|
-
export declare const markdownComponents: {
|
|
17
|
-
markdown: React.FC<MarkdownRendererProps>;
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAmB,MAAM,OAAO,CAAC;AAKxC,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAM9C,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAS5D,CAAC;AA2BF,eAAO,MAAM,kBAAkB;;CAE9B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,IAAI,EAAE,UAAU,CAAC;IAEjB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|