@pactor-app/markdown 1.21.0 → 1.23.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/dist/index.cjs +39 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +38 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -48,6 +48,7 @@ var import_remark_math = __toESM(require("remark-math"), 1);
|
|
|
48
48
|
|
|
49
49
|
// src/code-block.tsx
|
|
50
50
|
var import_react = require("react");
|
|
51
|
+
var import_react2 = require("react");
|
|
51
52
|
var import_react_syntax_highlighter = require("react-syntax-highlighter");
|
|
52
53
|
var import_bash = __toESM(require("react-syntax-highlighter/dist/esm/languages/prism/bash"), 1);
|
|
53
54
|
var import_css = __toESM(require("react-syntax-highlighter/dist/esm/languages/prism/css"), 1);
|
|
@@ -59,6 +60,7 @@ var import_python = __toESM(require("react-syntax-highlighter/dist/esm/languages
|
|
|
59
60
|
var import_tsx = __toESM(require("react-syntax-highlighter/dist/esm/languages/prism/tsx"), 1);
|
|
60
61
|
var import_typescript = __toESM(require("react-syntax-highlighter/dist/esm/languages/prism/typescript"), 1);
|
|
61
62
|
var import_yaml = __toESM(require("react-syntax-highlighter/dist/esm/languages/prism/yaml"), 1);
|
|
63
|
+
var import_one_dark = __toESM(require("react-syntax-highlighter/dist/esm/styles/prism/one-dark"), 1);
|
|
62
64
|
var import_one_light = __toESM(require("react-syntax-highlighter/dist/esm/styles/prism/one-light"), 1);
|
|
63
65
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
64
66
|
var LANGUAGES = {
|
|
@@ -91,12 +93,47 @@ function registerCodeLanguages() {
|
|
|
91
93
|
function isCodeLanguageRegistered(language) {
|
|
92
94
|
return language.toLowerCase() in LANGUAGES;
|
|
93
95
|
}
|
|
96
|
+
function resolveDarkMode() {
|
|
97
|
+
if (typeof document === "undefined") {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const theme = document.documentElement.getAttribute("data-pactor-theme");
|
|
101
|
+
if (theme === "dark") {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
if (theme === "light") {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
108
|
+
}
|
|
109
|
+
function useDarkMode() {
|
|
110
|
+
const [dark, setDark] = (0, import_react.useState)(resolveDarkMode);
|
|
111
|
+
(0, import_react.useEffect)(() => {
|
|
112
|
+
if (typeof document === "undefined") {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const update = () => setDark(resolveDarkMode());
|
|
116
|
+
const observer = new MutationObserver(update);
|
|
117
|
+
observer.observe(document.documentElement, {
|
|
118
|
+
attributes: true,
|
|
119
|
+
attributeFilter: ["data-pactor-theme"]
|
|
120
|
+
});
|
|
121
|
+
const media = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
122
|
+
media?.addEventListener?.("change", update);
|
|
123
|
+
return () => {
|
|
124
|
+
observer.disconnect();
|
|
125
|
+
media?.removeEventListener?.("change", update);
|
|
126
|
+
};
|
|
127
|
+
}, []);
|
|
128
|
+
return dark;
|
|
129
|
+
}
|
|
94
130
|
function CodeBlock({ language, children }) {
|
|
131
|
+
const dark = useDarkMode();
|
|
95
132
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
96
133
|
import_react_syntax_highlighter.PrismLight,
|
|
97
134
|
{
|
|
98
135
|
language: language.toLowerCase(),
|
|
99
|
-
style: import_one_light.default,
|
|
136
|
+
style: dark ? import_one_dark.default : import_one_light.default,
|
|
100
137
|
customStyle: { margin: 0, background: "transparent", fontSize: "0.85em" },
|
|
101
138
|
codeTagProps: { className: `language-${language.toLowerCase()}` },
|
|
102
139
|
children: children.replace(/\n$/, "")
|
|
@@ -104,7 +141,7 @@ function CodeBlock({ language, children }) {
|
|
|
104
141
|
);
|
|
105
142
|
}
|
|
106
143
|
function extractFencedCode(preChildren) {
|
|
107
|
-
if (!(0,
|
|
144
|
+
if (!(0, import_react2.isValidElement)(preChildren)) {
|
|
108
145
|
return null;
|
|
109
146
|
}
|
|
110
147
|
const { className, children } = preChildren.props;
|
package/dist/index.d.cts
CHANGED
|
@@ -65,7 +65,7 @@ interface CodeBlockProps {
|
|
|
65
65
|
language: string;
|
|
66
66
|
children: string;
|
|
67
67
|
}
|
|
68
|
-
/** fenced 代码块高亮渲染(Prism Light + one-light
|
|
68
|
+
/** fenced 代码块高亮渲染(Prism Light + one-light / one-dark 随深浅模式切换) */
|
|
69
69
|
declare function CodeBlock({ language, children }: CodeBlockProps): react.JSX.Element;
|
|
70
70
|
|
|
71
71
|
export { CodeBlock, type CodeBlockProps, MARKDOWN_DSL_TYPE, MarkdownDslComponent, type MarkdownDslComponentProps, MarkdownRenderer, type MarkdownRendererProps, isSafeUrl, registerCodeLanguages, registerMarkdownComponents };
|
package/dist/index.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ interface CodeBlockProps {
|
|
|
65
65
|
language: string;
|
|
66
66
|
children: string;
|
|
67
67
|
}
|
|
68
|
-
/** fenced 代码块高亮渲染(Prism Light + one-light
|
|
68
|
+
/** fenced 代码块高亮渲染(Prism Light + one-light / one-dark 随深浅模式切换) */
|
|
69
69
|
declare function CodeBlock({ language, children }: CodeBlockProps): react.JSX.Element;
|
|
70
70
|
|
|
71
71
|
export { CodeBlock, type CodeBlockProps, MARKDOWN_DSL_TYPE, MarkdownDslComponent, type MarkdownDslComponentProps, MarkdownRenderer, type MarkdownRendererProps, isSafeUrl, registerCodeLanguages, registerMarkdownComponents };
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import remarkGfm from "remark-gfm";
|
|
|
5
5
|
import remarkMath from "remark-math";
|
|
6
6
|
|
|
7
7
|
// src/code-block.tsx
|
|
8
|
+
import { useEffect, useState } from "react";
|
|
8
9
|
import { isValidElement } from "react";
|
|
9
10
|
import { PrismLight as SyntaxHighlighter } from "react-syntax-highlighter";
|
|
10
11
|
import bash from "react-syntax-highlighter/dist/esm/languages/prism/bash";
|
|
@@ -17,6 +18,7 @@ import python from "react-syntax-highlighter/dist/esm/languages/prism/python";
|
|
|
17
18
|
import tsx from "react-syntax-highlighter/dist/esm/languages/prism/tsx";
|
|
18
19
|
import typescript from "react-syntax-highlighter/dist/esm/languages/prism/typescript";
|
|
19
20
|
import yaml from "react-syntax-highlighter/dist/esm/languages/prism/yaml";
|
|
21
|
+
import oneDark from "react-syntax-highlighter/dist/esm/styles/prism/one-dark";
|
|
20
22
|
import oneLight from "react-syntax-highlighter/dist/esm/styles/prism/one-light";
|
|
21
23
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
22
24
|
var LANGUAGES = {
|
|
@@ -49,12 +51,47 @@ function registerCodeLanguages() {
|
|
|
49
51
|
function isCodeLanguageRegistered(language) {
|
|
50
52
|
return language.toLowerCase() in LANGUAGES;
|
|
51
53
|
}
|
|
54
|
+
function resolveDarkMode() {
|
|
55
|
+
if (typeof document === "undefined") {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const theme = document.documentElement.getAttribute("data-pactor-theme");
|
|
59
|
+
if (theme === "dark") {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
if (theme === "light") {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
66
|
+
}
|
|
67
|
+
function useDarkMode() {
|
|
68
|
+
const [dark, setDark] = useState(resolveDarkMode);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (typeof document === "undefined") {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const update = () => setDark(resolveDarkMode());
|
|
74
|
+
const observer = new MutationObserver(update);
|
|
75
|
+
observer.observe(document.documentElement, {
|
|
76
|
+
attributes: true,
|
|
77
|
+
attributeFilter: ["data-pactor-theme"]
|
|
78
|
+
});
|
|
79
|
+
const media = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
80
|
+
media?.addEventListener?.("change", update);
|
|
81
|
+
return () => {
|
|
82
|
+
observer.disconnect();
|
|
83
|
+
media?.removeEventListener?.("change", update);
|
|
84
|
+
};
|
|
85
|
+
}, []);
|
|
86
|
+
return dark;
|
|
87
|
+
}
|
|
52
88
|
function CodeBlock({ language, children }) {
|
|
89
|
+
const dark = useDarkMode();
|
|
53
90
|
return /* @__PURE__ */ jsx2(
|
|
54
91
|
SyntaxHighlighter,
|
|
55
92
|
{
|
|
56
93
|
language: language.toLowerCase(),
|
|
57
|
-
style: oneLight,
|
|
94
|
+
style: dark ? oneDark : oneLight,
|
|
58
95
|
customStyle: { margin: 0, background: "transparent", fontSize: "0.85em" },
|
|
59
96
|
codeTagProps: { className: `language-${language.toLowerCase()}` },
|
|
60
97
|
children: children.replace(/\n$/, "")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pactor-app/markdown",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "Pactor Markdown module: safe Markdown renderer (react-markdown AST, no raw HTML) and DSL Markdown component adapter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pactor",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"rehype-katex": "^7.0.1",
|
|
55
55
|
"remark-gfm": "^4.0.1",
|
|
56
56
|
"remark-math": "^6.0.0",
|
|
57
|
-
"@pactor-app/core": "1.
|
|
57
|
+
"@pactor-app/core": "1.23.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": ">=18"
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"jsdom": "^30.0.1",
|
|
69
69
|
"react": "^19.2.8",
|
|
70
70
|
"react-dom": "^19.2.8",
|
|
71
|
-
"@pactor-app/runtime": "1.
|
|
71
|
+
"@pactor-app/runtime": "1.23.0"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "tsup",
|