worked on theming and image support
This commit is contained in:
parent
e1ea47052d
commit
ad8cd4339b
8 changed files with 372 additions and 93 deletions
|
|
@ -1,9 +1,5 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use comrak::{
|
||||
format_html, nodes::NodeValue, parse_document, Arena, ExtensionOptions, Options, RenderOptions,
|
||||
RenderOptionsBuilder,
|
||||
};
|
||||
use comrak::{format_html, nodes::NodeValue, parse_document, Arena, Options};
|
||||
use tauri_plugin_fs::FsExt;
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
#[tauri::command]
|
||||
|
|
@ -13,23 +9,24 @@ fn greet(name: &str) -> String {
|
|||
|
||||
#[tauri::command]
|
||||
fn parse_markdown(document: &str) -> String {
|
||||
println!("{:?}", document.bytes());
|
||||
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);
|
||||
|
||||
// Iterate over all the descendants of root.
|
||||
for node in root.descendants() {
|
||||
if let NodeValue::SoftBreak = node.data.borrow_mut().value {
|
||||
println!("linebreak {:?}", node);
|
||||
if let NodeValue::Image(ref mut image_node) = node.data.borrow_mut().value {
|
||||
// image_node.url = format!("file://{}", image_node.url);
|
||||
println!("{:?}", image_node);
|
||||
}
|
||||
}
|
||||
let mut html = vec![];
|
||||
format_html(root, &options, &mut html).unwrap();
|
||||
println!("{:?}", String::from_utf8(html.clone()));
|
||||
println!("{}", String::from_utf8(html.clone()).unwrap());
|
||||
String::from_utf8(html).unwrap()
|
||||
// String::from_str("lololo").unwrap()
|
||||
}
|
||||
|
|
@ -38,7 +35,16 @@ fn parse_markdown(document: &str) -> String {
|
|||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_log::Builder::new().build())
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.setup(|app| {
|
||||
// allowed the given directory
|
||||
let scope = app.fs_scope();
|
||||
scope.allow_directory("/home/toxotes", true);
|
||||
app.set_theme(Some(tauri::Theme::Dark));
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![greet])
|
||||
.invoke_handler(tauri::generate_handler![parse_markdown])
|
||||
.run(tauri::generate_context!())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue