diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 2e53ff1..9b8e2fb 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -144,6 +144,7 @@ name = "apographe" version = "0.1.0" dependencies = [ "comrak", + "html_tag", "serde", "serde_json", "shellexpand", @@ -1582,6 +1583,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "html_tag" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258c462501ea394856d3c6cf7ca16f384dfb928766617bf018af0068c6935dee" + [[package]] name = "http" version = "1.1.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 3e97124..29393c6 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -26,4 +26,5 @@ comrak = "0.29.0" tauri-plugin-fs = "2" tauri-plugin-log = "2" shellexpand = "3.1.0" +html_tag = "0.1.3" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a59c361..35ff5b2 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,9 +1,16 @@ -use std::path::Path; - use comrak::{format_html, nodes::NodeValue, parse_document, Arena, Options}; +use html_tag::HtmlTag; use shellexpand; -use tauri::Manager; +use std::{ + collections::BTreeMap, + env, + ffi::{OsStr, OsString}, + fs, + path::{absolute, Path}, +}; +use tauri::{ipc::IpcResponse, Manager}; use tauri_plugin_fs::FsExt; + // Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ #[tauri::command] fn greet(name: &str) -> String { @@ -11,7 +18,7 @@ fn greet(name: &str) -> String { } #[tauri::command] -fn parse_markdown(document: &str, pathtemplate: &str) -> String { +fn parse_markdown(document: &str, pathtemplate: &str, basepath: &str) -> String { let mut rendered_markdown: String = String::new(); let path = "/foo/bar.txt"; println!("{:?}", shellexpand::full(path)); @@ -25,9 +32,16 @@ fn parse_markdown(document: &str, pathtemplate: &str) -> String { let root = parse_document(&arena, document, &options); // Iterate over all the descendants of root. + env::set_current_dir(basepath); for node in root.descendants() { if let NodeValue::Image(ref mut image_node) = node.data.borrow_mut().value { - if let Ok(resolved_path) = shellexpand::full(&image_node.url) { + let image_path = Path::new(&image_node.url).to_path_buf(); + let absolute_image_path = absolute(image_node.url.clone()); + let absolute_image_path = +.unwrap_or(image_path) + .as_path() + .to_string_lossy() + if let Ok(resolved_path) = shellexpand::full(&absolute_image_path) { image_node.url = pathtemplate.replace("FILEPATH", &resolved_path); } } @@ -39,7 +53,100 @@ fn parse_markdown(document: &str, pathtemplate: &str) -> String { return rendered_markdown.to_owned(); // String::from_str("lololo").unwrap() } +//
".concat("", ret).concat("", "");
+ }
+ );
+ var tag_id = document.getElementById('rendered_markdown');
+ tag_id.dispatchEvent(new Event("input"));
+ }
+}
+
+function dropdown(id) {
+ var dropdown_element = document.getElementById(id);
+ var dropdown_children = dropdown_element.children;
+ console.log(dropdown_element.getAttribute("expanded"));
+ if (dropdown_element.getAttribute("expanded") == "false") {
+ dropdown_element.setAttribute("expanded", "true");
+ }
+ else{
+ dropdown_element.setAttribute("expanded", "false");
+ }
+ for (var i = 0; i < dropdown_children.length; i++) {
+ var child = dropdown_children[i];
+ console.log(child.id);
+ if (child.className === "filetree-node") {
+ if (document.getElementById(id).getAttribute("expanded") == "true") {
+ document.getElementById(child.id).style.visibility = "visible";
+ document.getElementById(child.id).style.height = "auto";
+ } else {
+ document.getElementById(child.id).style.visibility = "hidden";
+ document.getElementById(child.id).style.height = 0;
+ }
+ }
+ }
+
+}
+window.onload = function () {
+ invoke("dir_tree_html", { basepath: "~/Documents/Knowledgebase", filter: ["*"]}).then(
+ (ret)=>{
+ var tag_id = document.getElementById('filetree');
+ tag_id.innerHTML = ret;
+ }
+ )
+}
+let filetree = document.getElementById('filetree');
+// Options for the observer (which mutations to observe)
+const config = { attributes: true, childList: true, subtree: true };
+
+// Callback function to execute when mutations are observed
+const callback = (mutationList, observer) => {
+ var anchors = document.getElementsByClassName("filetree-directory-button");
+ for (var i = 0; i < anchors.length; i++) {
+ var anchor = anchors[i];
+ anchor.onclick = function () {
+ dropdown(this.parentElement.id);
+ };
+ };
+ var anchors = document.getElementsByClassName("filetree-file-button");
+ for (var i = 0; i < anchors.length; i++) {
+ var anchor = anchors[i];
+ anchor.onclick = function () {
+ handle_file_select(this.parentElement.id);
+ };
+ };
+
+};
+
+// Create an observer instance linked to the callback function
+const observer = new MutationObserver(callback);
+
+// Start observing the target node for configured mutations
+observer.observe(filetree, config);
+
diff --git a/src/images/directory.svg b/src/images/directory.svg
new file mode 100644
index 0000000..174491a
--- /dev/null
+++ b/src/images/directory.svg
@@ -0,0 +1,30 @@
+
+
+
+
diff --git a/src/images/dropdown.svg b/src/images/dropdown.svg
new file mode 100644
index 0000000..231629b
--- /dev/null
+++ b/src/images/dropdown.svg
@@ -0,0 +1,23 @@
+
+
+
+
diff --git a/src/images/file.svg b/src/images/file.svg
new file mode 100644
index 0000000..21269a3
--- /dev/null
+++ b/src/images/file.svg
@@ -0,0 +1,26 @@
+
+
+
+
diff --git a/src/images/markdown.svg b/src/images/markdown.svg
new file mode 100644
index 0000000..10b51c0
--- /dev/null
+++ b/src/images/markdown.svg
@@ -0,0 +1,55 @@
+
+
+
+
diff --git a/src/images/menu_button.svg b/src/images/menu_button.svg
new file mode 100644
index 0000000..32f9392
--- /dev/null
+++ b/src/images/menu_button.svg
@@ -0,0 +1,39 @@
+
+
+
+
diff --git a/src/images/path6.svg b/src/images/path6.svg
new file mode 100644
index 0000000..174491a
--- /dev/null
+++ b/src/images/path6.svg
@@ -0,0 +1,30 @@
+
+
+
+
diff --git a/src/index.html b/src/index.html
index 472b9f3..6617c79 100644
--- a/src/index.html
+++ b/src/index.html
@@ -1,33 +1,68 @@
-
-
-
-
-