Open vehka opened 1 month ago
Took me a while to get my head around Clojure, but I think I got it now. I also eliminated the extra square brackets from the links. Let me know if you want a pull request.
diff --git a/src/logseq_to_markdown/parser.cljs b/src/logseq_to_markdown/parser.cljs
index 5a0066b..4735d8f 100644
--- a/src/logseq_to_markdown/parser.cljs
+++ b/src/logseq_to_markdown/parser.cljs
@@ -184,7 +184,7 @@
(defn parse-links
[text]
- (let [link-pattern #"\[\[(.*?)\]\]"
+ (let [link-pattern #"(?:#\[\[(.*?)\]\])|(?<!#)#(\w+)"
link-res (re-seq link-pattern text)
desc-link-pattern #"\[(.*?)\]\(\[\[(.*?)\]\]\)"
desc-link-res (re-seq desc-link-pattern text)]
@@ -193,14 +193,14 @@
text
(reduce
#(let [current-text (first %2)
- current-link (last %2)
+ current-link (or (second %2) (nth %2 2)) ; adjusted to account for either match in the two patterns
namespace-pattern #"\[\[([^\/]*\/).*\]\]"
namespace-res (re-find namespace-pattern text)
namespace-link? (not-empty namespace-res)
link-text (or (and namespace-link? (config/entry :trim-namespaces)
(last (s/split current-link "/"))) current-link)
- replaced-str (or (and (graph/page-exists? current-link) (str "[[[" link-text "]]]({{< ref \"/pages/" (fs/->filename current-link)
"\" >}})"))
- (str link-text))]
+ replaced-str (or (and (graph/page-exists? current-link) (str "#[" link-text "]({{< ref \"/pages/" (fs/->filename current-link) "\"
>}})"))
+ (str "#" link-text))]
(s/replace %1 current-text replaced-str))
text
link-res))
Thanks for investigation, sure please create a pull request for it and I will try to crosscheck and merge it the next days😊
@vehka I also created this PR https://github.com/dom8509/logseq-to-markdown/pull/12 in the meantime. Could you check if this would also work for you? didn't find the time to test it yet, idea is to keep the formats more separate
Thanks, I'll try to test it in a few days.
I use a lot of inline tag links in my graph (the #hashtag format). At the moment, they are only converted to links if I enter the tag in double brackets, e.g., #[[tag]].
How difficult would it be to modify the export script to support tags that are not in double brackets? Would you be interested to add support for this? Could you point me in the right direction, if I'd attempted this myself?