Skip to content

Commit

Permalink
First take at wikilink interations
Browse files Browse the repository at this point in the history
  • Loading branch information
zampino committed Aug 29, 2023
1 parent 74bb4c4 commit f092bf2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 27 additions & 1 deletion notebooks/doc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,30 @@
:else [:div "No namespaces found."]))]]])

#_(deref nextjournal.clerk.webserver/!doc)

#_ (clerk/clear-cache!)

(defn resolve-internal-link [link]
(viewer/resolve-internal-link (cond->> link
(not (qualified-symbol? (symbol link)))
(str @!active-ns "/"))))

(defn spy [x] (println :x x :cns @!active-ns) x)

(def custom-markdown-viewers
[{:name :nextjournal.markdown/internal-link
:transform-fn (comp clerk/mark-presented
(fn [wv]
(when-some [{:keys [ns var]} (-> wv :nextjournal/value :text resolve-internal-link spy)]
{:var (symbol var)})))
:render-fn '(fn [{:keys [var]} _]
[:a {:href (str "#" var)
:on-click (fn [e] (.stopPropagation e) (.preventDefault e)
(js/console.log :click/var var
:elm (js/document.getElementById (name var)))
(when-some [el (js/document.getElementById (name var))]
(.scrollIntoView el)))} var])}])

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

(viewer/add-viewers! [custom-internal-links])
2 changes: 1 addition & 1 deletion src/nextjournal/clerk/viewer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@
hide-result-viewer])

(defonce
^{:doc "atom containing a map of and per-namespace viewers or `:defaults` overridden viewers."}
^{:doc "atom containing a map of and per-namespace viewers or `:defaults` overridden viewers. See also [[get-default-viewers]]."}
!viewers
(#?(:clj atom :cljs ratom/atom) {}))

Expand Down

0 comments on commit f092bf2

Please sign in to comment.