Skip to content

Commit d2d0529

Browse files
committed
feat (language): 支持 SVG 语言
1 parent 61e49ad commit d2d0529

File tree

8 files changed

+295
-0
lines changed

8 files changed

+295
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ CodeForge 是一款轻量级、高性能的桌面代码执行器,专为开发
4141
- **Ruby**
4242
- **Rust**
4343
- **Shell**
44+
- **SVG**
4445
- **Swift**
4546
- **TypeScript**
4647
- **TypeScript (Browser)**

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@codemirror/lang-javascript": "^6.2.4",
2020
"@codemirror/lang-python": "^6.2.1",
2121
"@codemirror/lang-rust": "^6.0.2",
22+
"@codemirror/lang-xml": "^6.1.0",
2223
"@codemirror/language": "^6.11.2",
2324
"@codemirror/legacy-modes": "^6.5.1",
2425
"@codemirror/state": "^6.5.2",

public/icons/svg.svg

Lines changed: 1 addition & 0 deletions
Loading

src-tauri/src/examples/svg.svg

Lines changed: 231 additions & 0 deletions
Loading

src-tauri/src/plugins/manager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::plugins::ruby::RubyPlugin;
1919
use crate::plugins::rust::RustPlugin;
2020
use crate::plugins::scala::ScalaPlugin;
2121
use crate::plugins::shell::ShellPlugin;
22+
use crate::plugins::svg::SvgPlugin;
2223
use crate::plugins::swift::SwiftPlugin;
2324
use crate::plugins::typescript::TypeScriptPlugin;
2425
use crate::plugins::typescript_browser::TypeScriptBrowserPlugin;
@@ -52,6 +53,7 @@ impl PluginManager {
5253
plugins.insert("groovy".to_string(), Box::new(GroovyPlugin));
5354
plugins.insert("html".to_string(), Box::new(HtmlPlugin));
5455
plugins.insert("css".to_string(), Box::new(CssPlugin));
56+
plugins.insert("svg".to_string(), Box::new(SvgPlugin));
5557
plugins.insert(
5658
"javascript-nodejs".to_string(),
5759
Box::new(JavaScriptNodeJsPlugin),

src-tauri/src/plugins/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ pub mod ruby;
390390
pub mod rust;
391391
pub mod scala;
392392
pub mod shell;
393+
pub mod svg;
393394
pub mod swift;
394395
pub mod typescript;
395396
pub mod typescript_browser;

src-tauri/src/plugins/svg.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use super::{LanguagePlugin, PluginConfig};
2+
use std::vec;
3+
4+
pub struct SvgPlugin;
5+
6+
impl LanguagePlugin for SvgPlugin {
7+
fn get_order(&self) -> i32 {
8+
22
9+
}
10+
11+
fn get_language_name(&self) -> &'static str {
12+
"SVG"
13+
}
14+
15+
fn get_language_key(&self) -> &'static str {
16+
"svg"
17+
}
18+
19+
fn get_file_extension(&self) -> String {
20+
self.get_config()
21+
.map(|config| config.extension.clone())
22+
.unwrap_or_else(|| "svg".to_string())
23+
}
24+
25+
fn get_version_args(&self) -> Vec<&'static str> {
26+
vec!["--"]
27+
}
28+
29+
fn get_path_command(&self) -> String {
30+
"--".to_string()
31+
}
32+
33+
fn get_default_config(&self) -> PluginConfig {
34+
PluginConfig {
35+
enabled: true,
36+
language: String::from("svg"),
37+
before_compile: None,
38+
extension: String::from("svg"),
39+
execute_home: None,
40+
run_command: Some(String::from("cat $filename")),
41+
after_compile: None,
42+
template: Some(String::from(
43+
"<!-- 在这里输入 SVG 代码 -->\n<!-- SVG (Scalable Vector Graphics) 矢量图形 -->",
44+
)),
45+
timeout: Some(30),
46+
console_type: Some(String::from("web")),
47+
}
48+
}
49+
50+
fn get_default_command(&self) -> String {
51+
self.get_config()
52+
.and_then(|config| config.run_command.clone())
53+
.unwrap_or_else(|| "cat".to_string())
54+
}
55+
}

src/composables/useCodeMirrorEditor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {rust} from '@codemirror/lang-rust'
77
import {cpp} from '@codemirror/lang-cpp'
88
import {html} from '@codemirror/lang-html'
99
import {css} from '@codemirror/lang-css'
10+
import {xml} from '@codemirror/lang-xml'
1011
import {shell} from '@codemirror/legacy-modes/mode/shell'
1112
import {swift} from '@codemirror/legacy-modes/mode/swift'
1213
import {kotlin, scala} from '@codemirror/legacy-modes/mode/clike'
@@ -203,6 +204,8 @@ export function useCodeMirrorEditor(props: Props)
203204
return html()
204205
case 'css':
205206
return css()
207+
case 'svg':
208+
return xml()
206209
default:
207210
return null
208211
}

0 commit comments

Comments
 (0)