Skip to content

Commit

Permalink
Process href of regular links to resolve vars or nss
Browse files Browse the repository at this point in the history
  • Loading branch information
zampino committed Aug 30, 2023
1 parent 589e007 commit ff7ebc2
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/nextjournal/clerk/viewer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,24 @@
:cljs
{:path link :title link}))

(defn process-href [^String href]
#?(:cljs href
:clj (if (.getScheme (URI. href))
href
(let [{:keys [path fragment]} (process-internal-link href)]
(doc-url path fragment)))))

#_(process-href "foo.bar.dang")
#_(process-internal-link "foo.bar.dang")

#_(process-internal-link "notebooks/rule_30.clj")
#_(process-internal-link "viewers.html")
#_(process-internal-link "how-clerk-works/hashes")
#_(process-internal-link "rule-30/first-generation")

(defn update-if [m k f] (if (k m) (update m k f) m))
#_(update-if {:n "42"} :n #(Integer/parseInt %))

(declare html)

(def markdown-viewers
Expand Down Expand Up @@ -782,7 +795,7 @@
{:name :nextjournal.markdown/strong :transform-fn (into-markup [:strong])}
{:name :nextjournal.markdown/monospace :transform-fn (into-markup [:code])}
{:name :nextjournal.markdown/strikethrough :transform-fn (into-markup [:s])}
{:name :nextjournal.markdown/link :transform-fn (into-markup #(vector :a (:attrs %)))}
{:name :nextjournal.markdown/link :transform-fn (into-markup #(vector :a (update-if (:attrs %) :href process-href)))}
{:name :nextjournal.markdown/internal-link
:transform-fn (update-val
(fn [{:keys [text]}]
Expand Down Expand Up @@ -1169,13 +1182,6 @@
(map (juxt #(list 'quote (symbol %)) #(->> % deref deref (list 'quote))))
(extract-sync-atom-vars doc)))))

(defn update-if [m k f]
(if (k m)
(update m k f)
m))

#_(update-if {:n "42"} :n #(Integer/parseInt %))

(declare html)

(defn home? [{:keys [nav-path]}]
Expand Down

0 comments on commit ff7ebc2

Please sign in to comment.