rewrite in vanilla js

This commit is contained in:
Adrian Osterwind 2024-11-13 14:59:13 +01:00
parent 5f35da27f2
commit 590aec5260
26 changed files with 223 additions and 3227 deletions

View file

@ -22,6 +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"
tauri-plugin-fs = "2"

View file

@ -8,7 +8,6 @@
"permissions": [
"core:default",
"shell:allow-open",
"fs:default",
"fs:default"
]
}

View file

@ -1,6 +1,9 @@
use std::str::FromStr;
use comrak::{format_html, parse_document, Arena, Options};
use comrak::{
format_html, nodes::NodeValue, parse_document, Arena, ExtensionOptions, Options, RenderOptions,
RenderOptionsBuilder,
};
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
@ -10,20 +13,23 @@ 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 root = parse_document(&arena, document, &Options::default());
let mut options = Options::default();
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::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);
// }
// }
for node in root.descendants() {
if let NodeValue::SoftBreak = node.data.borrow_mut().value {
println!("linebreak {:?}", node);
}
}
let mut html = vec![];
format_html(root, &Options::default(), &mut html).unwrap();
options.render.hardbreaks = true;
format_html(root, &options, &mut html).unwrap();
println!("{:?}", String::from_utf8(html.clone()));
String::from_utf8(html).unwrap()
// String::from_str("lololo").unwrap()

View file

@ -4,12 +4,10 @@
"version": "0.1.0",
"identifier": "com.apographe.app",
"build": {
"beforeDevCommand": "deno task dev",
"devUrl": "http://localhost:1420",
"beforeBuildCommand": "deno task build",
"frontendDist": "../build"
"frontendDist": "../src"
},
"app": {
"withGlobalTauri": true,
"windows": [
{
"title": "apographe",