@alicloud/appflow-chat 0.0.1-beta.8 → 0.0.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/appflow-chat.cjs.js +110 -110
- package/dist/appflow-chat.esm.js +1645 -1652
- package/package.json +1 -1
- package/src/markdown/components/SyntaxHighlight.tsx +0 -2
- package/src/utils/loadPrism.ts +21 -28
package/package.json
CHANGED
|
@@ -94,7 +94,6 @@ export const ASyntaxHighLight: React.FC<ASyntaxHighLightProps> = ({
|
|
|
94
94
|
return (
|
|
95
95
|
<div style={{ position: 'relative', ...style }}>
|
|
96
96
|
<pre
|
|
97
|
-
className="line-numbers"
|
|
98
97
|
style={{
|
|
99
98
|
margin: 0,
|
|
100
99
|
padding: '1em',
|
|
@@ -109,7 +108,6 @@ export const ASyntaxHighLight: React.FC<ASyntaxHighLightProps> = ({
|
|
|
109
108
|
>
|
|
110
109
|
{/* 行号 */}
|
|
111
110
|
<span
|
|
112
|
-
className="line-numbers-rows"
|
|
113
111
|
style={{
|
|
114
112
|
position: 'absolute',
|
|
115
113
|
left: 0,
|
package/src/utils/loadPrism.ts
CHANGED
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
* 用于代码语法高亮
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
// Prism CDN 基础路径
|
|
7
|
-
const PRISM_CDN_BASE = 'https://
|
|
6
|
+
// Prism CDN 基础路径 (使用 unpkg.com,国内访问更稳定)
|
|
7
|
+
const PRISM_CDN_BASE = 'https://unpkg.com/prismjs@1.29.0';
|
|
8
|
+
|
|
9
|
+
// Prism 主题 CDN 路径 (coldark-cold 主题在 prism-themes 包中)
|
|
10
|
+
const PRISM_THEME_URL = 'https://unpkg.com/prism-themes@1.9.0/themes/prism-coldark-cold.min.css';
|
|
8
11
|
|
|
9
12
|
// 已加载的语言缓存
|
|
10
13
|
const loadedLanguages = new Set<string>(['javascript', 'css', 'markup', 'clike']);
|
|
@@ -27,42 +30,32 @@ export async function loadPrism(): Promise<any> {
|
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
prismLoadPromise = new Promise((resolve, reject) => {
|
|
30
|
-
// 加载 CSS 主题
|
|
33
|
+
// 加载 CSS 主题 (使用 prism-themes 包中的 coldark-cold 主题)
|
|
31
34
|
const link = document.createElement('link');
|
|
32
35
|
link.rel = 'stylesheet';
|
|
33
|
-
link.href =
|
|
36
|
+
link.href = PRISM_THEME_URL;
|
|
34
37
|
document.head.appendChild(link);
|
|
35
38
|
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
lineNumbersCSS.rel = 'stylesheet';
|
|
39
|
-
lineNumbersCSS.href = `${PRISM_CDN_BASE}/plugins/line-numbers/prism-line-numbers.min.css`;
|
|
40
|
-
document.head.appendChild(lineNumbersCSS);
|
|
39
|
+
// 注意:不再加载 Prism 的 line-numbers 插件,改用手动渲染行号
|
|
40
|
+
// 这样可以避免与 React 组件的行号渲染冲突
|
|
41
41
|
|
|
42
42
|
// 加载 Prism 核心 JS
|
|
43
43
|
const script = document.createElement('script');
|
|
44
44
|
script.src = `${PRISM_CDN_BASE}/prism.min.js`;
|
|
45
45
|
script.onload = () => {
|
|
46
|
-
//
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// 配置自动加载器的语言路径
|
|
57
|
-
Prism.plugins.autoloader.languages_path = `${PRISM_CDN_BASE}/components/`;
|
|
58
|
-
}
|
|
59
|
-
resolve(Prism);
|
|
60
|
-
};
|
|
61
|
-
autoloaderScript.onerror = reject;
|
|
62
|
-
document.head.appendChild(autoloaderScript);
|
|
46
|
+
// 加载自动加载器(用于按需加载语言)
|
|
47
|
+
const autoloaderScript = document.createElement('script');
|
|
48
|
+
autoloaderScript.src = `${PRISM_CDN_BASE}/plugins/autoloader/prism-autoloader.min.js`;
|
|
49
|
+
autoloaderScript.onload = () => {
|
|
50
|
+
const Prism = (window as any).Prism;
|
|
51
|
+
if (Prism && Prism.plugins && Prism.plugins.autoloader) {
|
|
52
|
+
// 配置自动加载器的语言路径
|
|
53
|
+
Prism.plugins.autoloader.languages_path = `${PRISM_CDN_BASE}/components/`;
|
|
54
|
+
}
|
|
55
|
+
resolve(Prism);
|
|
63
56
|
};
|
|
64
|
-
|
|
65
|
-
document.head.appendChild(
|
|
57
|
+
autoloaderScript.onerror = reject;
|
|
58
|
+
document.head.appendChild(autoloaderScript);
|
|
66
59
|
};
|
|
67
60
|
script.onerror = reject;
|
|
68
61
|
document.head.appendChild(script);
|