working on rust svelte integration

This commit is contained in:
Iaphetes 2024-11-12 21:58:31 +01:00
parent 41f011ed58
commit 49deafd8a2
4 changed files with 5003 additions and 3 deletions

4966
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -22,4 +22,6 @@ tauri = { version = "2", features = [] }
tauri-plugin-shell = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-fs = "2"
comrak = "0.29.0"

View file

@ -2,9 +2,13 @@
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"windows": [
"main"
],
"permissions": [
"core:default",
"shell:allow-open"
"shell:allow-open",
"fs:default",
"fs:default"
]
}
}

View file

@ -1,14 +1,42 @@
use std::str::FromStr;
use comrak::{format_html, parse_document, Arena, Options};
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
#[tauri::command]
fn parse_markdown(document: &str) -> String {
let arena = Arena::new();
// Parse the document into a root `AstNode`
let root = parse_document(&arena, document, &Options::default());
// Iterate over all the descendants of root.
// for node in root.descendants() {
// if let NodeValue::Text(ref mut text) = node.data.borrow_mut().value {
// // If the node is a text node, perform the string replacement.
// *text = text.replace(orig_string, replacement);
// }
// }
let mut html = vec![];
format_html(root, &Options::default(), &mut html).unwrap();
println!("{:?}", String::from_utf8(html.clone()));
// String::from_utf8(html).unwrap()
String::from_str("lololo").unwrap()
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![greet])
.invoke_handler(tauri::generate_handler![parse_markdown])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}