refactor(desktop): move markdown rendering to rust (#10000)

This commit is contained in:
Shoubhit Dash
2026-01-22 16:18:39 +05:30
committed by GitHub
parent 7b0ad87781
commit c737776958
9 changed files with 237 additions and 5 deletions

View File

@@ -464,6 +464,15 @@ dependencies = [
"toml 0.9.8",
]
[[package]]
name = "caseless"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b6fd507454086c8edfd769ca6ada439193cdb209c7681712ef6275cccbfe5d8"
dependencies = [
"unicode-normalization",
]
[[package]]
name = "cc"
version = "1.2.47"
@@ -574,6 +583,23 @@ dependencies = [
"memchr",
]
[[package]]
name = "comrak"
version = "0.50.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "321d20bf105b6871a49da44c5fbb93e90a7cd6178ea5a9fe6cbc1e6d4504bc5e"
dependencies = [
"caseless",
"entities",
"jetscii",
"phf 0.13.1",
"phf_codegen 0.13.1",
"rustc-hash",
"smallvec",
"typed-arena",
"unicode_categories",
]
[[package]]
name = "concurrent-queue"
version = "2.5.0"
@@ -1053,6 +1079,12 @@ dependencies = [
"windows 0.51.1",
]
[[package]]
name = "entities"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5320ae4c3782150d900b79807611a59a99fc9a1d61d686faafc24b93fc8d7ca"
[[package]]
name = "enumflags2"
version = "0.7.12"
@@ -2153,6 +2185,12 @@ dependencies = [
"system-deps",
]
[[package]]
name = "jetscii"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47f142fe24a9c9944451e8349de0a56af5f3e7226dc46f3ed4d4ecc0b85af75e"
[[package]]
name = "jni"
version = "0.21.1"
@@ -2986,6 +3024,7 @@ dependencies = [
name = "opencode-desktop"
version = "0.0.0"
dependencies = [
"comrak",
"futures",
"gtk",
"listeners",
@@ -3187,6 +3226,16 @@ dependencies = [
"phf_shared 0.11.3",
]
[[package]]
name = "phf"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf"
dependencies = [
"phf_shared 0.13.1",
"serde",
]
[[package]]
name = "phf_codegen"
version = "0.8.0"
@@ -3207,6 +3256,16 @@ dependencies = [
"phf_shared 0.11.3",
]
[[package]]
name = "phf_codegen"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49aa7f9d80421bca176ca8dbfebe668cc7a2684708594ec9f3c0db0805d5d6e1"
dependencies = [
"phf_generator 0.13.1",
"phf_shared 0.13.1",
]
[[package]]
name = "phf_generator"
version = "0.8.0"
@@ -3237,6 +3296,16 @@ dependencies = [
"rand 0.8.5",
]
[[package]]
name = "phf_generator"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737"
dependencies = [
"fastrand",
"phf_shared 0.13.1",
]
[[package]]
name = "phf_macros"
version = "0.10.0"
@@ -3291,6 +3360,15 @@ dependencies = [
"siphasher 1.0.1",
]
[[package]]
name = "phf_shared"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266"
dependencies = [
"siphasher 1.0.1",
]
[[package]]
name = "pin-project-lite"
version = "0.2.16"
@@ -5478,6 +5556,12 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "typed-arena"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a"
[[package]]
name = "typeid"
version = "1.0.3"
@@ -5548,12 +5632,27 @@ version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]]
name = "unicode-normalization"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8"
dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
[[package]]
name = "unicode_categories"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e"
[[package]]
name = "untrusted"
version = "0.9.0"

View File

@@ -41,6 +41,7 @@ semver = "1.0.27"
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] }
uuid = { version = "1.19.0", features = ["v4"] }
tauri-plugin-decorum = "1.1.1"
comrak = { version = "0.50", default-features = false }
[target.'cfg(target_os = "linux")'.dependencies]

View File

@@ -1,6 +1,7 @@
mod cli;
#[cfg(windows)]
mod job_object;
mod markdown;
mod window_customizer;
use cli::{install_cli, sync_cli};
@@ -283,7 +284,8 @@ pub fn run() {
install_cli,
ensure_server_ready,
get_default_server_url,
set_default_server_url
set_default_server_url,
markdown::parse_markdown_command
])
.setup(move |app| {
let app = app.handle().clone();

View File

@@ -0,0 +1,17 @@
use comrak::{markdown_to_html, Options};
pub fn parse_markdown(input: &str) -> String {
let mut options = Options::default();
options.extension.strikethrough = true;
options.extension.table = true;
options.extension.tasklist = true;
options.extension.autolink = true;
options.render.r#unsafe = true;
markdown_to_html(input, &options)
}
#[tauri::command]
pub async fn parse_markdown_command(markdown: String) -> Result<String, String> {
Ok(parse_markdown(&markdown))
}

View File

@@ -316,6 +316,10 @@ const createPlatform = (password: Accessor<string | null>): Platform => ({
setDefaultServerUrl: async (url: string | null) => {
await invoke("set_default_server_url", { url })
},
parseMarkdown: async (markdown: string) => {
return invoke<string>("parse_markdown_command", { markdown })
},
})
createMenu()