Started work on markdown image support
This commit is contained in:
parent
a1de20f0ec
commit
4f7836d296
4 changed files with 49 additions and 26 deletions
|
|
@ -18,7 +18,7 @@ crate-type = ["staticlib", "cdylib", "rlib"]
|
|||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = ["protocol-asset"] }
|
||||
tauri = { version = "2", features = ["protocol-asset", "unstable"] }
|
||||
tauri-plugin-shell = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use comrak::{format_html, nodes::NodeValue, parse_document, Arena, Options};
|
||||
use tauri::Manager;
|
||||
use tauri_plugin_fs::FsExt;
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
|
|
@ -9,25 +10,31 @@ fn greet(name: &str) -> String {
|
|||
|
||||
#[tauri::command]
|
||||
fn parse_markdown(document: &str) -> String {
|
||||
let arena = Arena::new();
|
||||
let mut rendered_markdown: String = String::new();
|
||||
tauri::Builder::default().setup(move |app| {
|
||||
let webview = app.get_webview_window("main").unwrap();
|
||||
let arena = Arena::new();
|
||||
|
||||
// Parse the document into a root `AstNode`
|
||||
let mut options = Options::default();
|
||||
options.render.unsafe_ = true;
|
||||
// options.render.hardbreaks = true;
|
||||
let root = parse_document(&arena, document, &options);
|
||||
// Parse the document into a root `AstNode`
|
||||
let mut options = Options::default();
|
||||
options.render.unsafe_ = true;
|
||||
// options.render.hardbreaks = true;
|
||||
let root = parse_document(&arena, document, &options);
|
||||
|
||||
// Iterate over all the descendants of root.
|
||||
for node in root.descendants() {
|
||||
if let NodeValue::Image(ref mut image_node) = node.data.borrow_mut().value {
|
||||
// image_node.url = format!("file://{}", image_node.url);
|
||||
println!("{:?}", image_node);
|
||||
// Iterate over all the descendants of root.
|
||||
for node in root.descendants() {
|
||||
if let NodeValue::Image(ref mut image_node) = node.data.borrow_mut().value {
|
||||
// image_node.url = format!("file://{}", image_node.url);
|
||||
println!("{:?}", webview.eval(&image_node.url));
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut html = vec![];
|
||||
format_html(root, &options, &mut html).unwrap();
|
||||
println!("{}", String::from_utf8(html.clone()).unwrap());
|
||||
String::from_utf8(html).unwrap()
|
||||
let mut html = vec![];
|
||||
format_html(root, &options, &mut html).unwrap();
|
||||
println!("{}", String::from_utf8(html.clone()).unwrap());
|
||||
rendered_markdown = String::from_utf8(html).unwrap();
|
||||
Ok(())
|
||||
});
|
||||
return "".to_owned();
|
||||
// String::from_str("lololo").unwrap()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue