Skip to content

Commit 64f266e

Browse files
committed
Make links to namespace work
1 parent d433947 commit 64f266e

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/nextjournal/clerk.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
(ns nextjournal.clerk
2-
"Clerk's Public API."
2+
"Clerk's Public API.
3+
4+
Further API:
5+
* [[nextjournal.clerk.parser]]
6+
* [[nextjournal.clerk.viewer]]
7+
* [[nextjournal.clerk.analyzer]]"
38
(:require [babashka.fs :as fs]
49
[clojure.java.browse :as browse]
510
[clojure.java.io :as io]

src/nextjournal/clerk/doc.clj

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
(into [:div.text-sm.font-sans.px-5.mt-2]
162162
(map render-ns)
163163
(ns-tree (str-match-nss @!active-ns)))]])]]
164-
[:div.flex-auto.max-h-screen.overflow-y-auto.px-8.py-5
164+
[:div#main-column.flex-auto.max-h-screen.overflow-y-auto.px-8.py-5
165165
(let [ns (some-> @!active-ns symbol find-ns)]
166166
(cond
167167
ns [:<>
@@ -197,7 +197,9 @@
197197

198198
(defn resolve-internal-link [link]
199199
(viewer/resolve-internal-link (cond->> link
200-
(and (not (qualified-symbol? (symbol link))) @!active-ns)
200+
(and @!active-ns (not= :all @!active-ns)
201+
(not (find-ns (symbol link)))
202+
(not (qualified-symbol? (symbol link))))
201203
(str @!active-ns "/"))))
202204

203205
(def custom-markdown-viewers
@@ -211,13 +213,19 @@
211213
:render-fn '(fn [{:keys [var ns]} _]
212214
[:a {:href (str "#" var)
213215
:on-click (fn [e] (.stopPropagation e) (.preventDefault e)
214-
(when (and var ns)
215-
(let [scroll-to-target #(when-some [el (js/document.getElementById (name var))]
216-
(.scrollIntoView el))]
217-
(if (not= @!active-ns (str ns))
218-
(do (reset! !active-ns (str ns))
219-
(js/setTimeout scroll-to-target 500)) ;; TODO: smarter
220-
(scroll-to-target)))))} (str var)])}])
216+
(when (resolve '!active-ns)
217+
(let [scroll-to-target (fn []
218+
(if var
219+
(when-some [el (js/document.getElementById (name var))]
220+
(.scrollIntoView el))
221+
(when ns
222+
(when-some [page (js/document.getElementById "main-column")]
223+
(.scroll page (applied-science.js-interop/obj :top 0))))))]
224+
(when ns
225+
(if (not= @!active-ns (str ns))
226+
(do (reset! !active-ns (str ns))
227+
(js/setTimeout scroll-to-target 500)) ;; TODO: smarter
228+
(scroll-to-target))))))} (str (or var ns))])}])
221229

222230
(def custom-internal-links
223231
(update viewer/markdown-viewer :add-viewers viewer/add-viewers custom-markdown-viewers))

0 commit comments

Comments
 (0)