Skip to content

Commit 6af7edf

Browse files
authored
feat(文本编辑器): 支持SVG文件语法高亮并优化路径处理 (#133)
添加SVG文件扩展名到HTML语言支持列表,使其能够进行语法高亮 修改路径处理逻辑,允许可选路径参数并提供默认值
1 parent 7ad925f commit 6af7edf

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@coze-editor/preset-code-languages",
5+
"comment": "支持SVG文件语法高亮并优化路径处理",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@coze-editor/preset-code-languages",
10+
"email": "hanchayi@163.com"
11+
}

packages/text-editor/dev/src/pages/highlight/examples.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ export default App;
6161
},
6262
{
6363
code: `
64+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
65+
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
66+
</svg>
67+
`,
68+
path: 'a.svg',
69+
},
70+
{
71+
code: `
6472
body {
6573
background-color: #f0f0f0;
6674
}

packages/text-editor/preset-code-languages/src/languages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const supportedLanguages = [
5050
}),
5151
LanguageDescription.of({
5252
name: 'HTML',
53-
extensions: ['html'],
53+
extensions: ['html', 'svg'],
5454
async load() {
5555
return import('@codemirror/lang-html').then(module => module.html());
5656
},

packages/text-editor/preset-code-languages/src/preset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { asyncOption } from '@coze-editor/core';
33
import { getLanguage } from './languages';
44

55
export const preset = [
6-
...asyncOption('path', (path: string) => getLanguage(path), {
6+
...asyncOption('path', (path?: string) => getLanguage(path ?? ''), {
77
reset: true,
88
}),
99
];

0 commit comments

Comments
 (0)