|
31 | 31 | (java.nio.file Files StandardOpenOption)
|
32 | 32 | (javax.imageio ImageIO))))
|
33 | 33 |
|
| 34 | +(declare doc-url) |
| 35 | + |
34 | 36 | (defrecord ViewerEval [form])
|
35 | 37 |
|
36 | 38 | (defrecord ViewerFn [form #?(:cljs f)]
|
|
714 | 716 | (doto (java.text.SimpleDateFormat. "yyyy-MM-dd'T'HH:mm:ss.SSS-00:00")
|
715 | 717 | (.setTimeZone (java.util.TimeZone/getTimeZone "GMT")))))
|
716 | 718 |
|
| 719 | +#?(:clj (defn resolve-internal-link [link] |
| 720 | + (if (fs/exists? link) |
| 721 | + {:path link} |
| 722 | + (let [sym (symbol link)] |
| 723 | + (if (qualified-symbol? sym) |
| 724 | + (when-some [var (try (requiring-resolve sym) |
| 725 | + (catch Exception _ nil))] |
| 726 | + (merge {:var var} (resolve-internal-link (-> var symbol namespace)))) |
| 727 | + (when-some [ns (try (require sym) |
| 728 | + (find-ns sym) |
| 729 | + (catch Exception _ nil))] |
| 730 | + (cond-> {:ns ns} |
| 731 | + (fs/exists? (analyzer/ns->file sym)) |
| 732 | + (assoc :path (analyzer/ns->file sym))))))))) |
| 733 | + |
| 734 | +#_(resolve-internal-link "notebooks/hello.clj") |
| 735 | +#_(resolve-internal-link "nextjournal.clerk.tap") |
| 736 | +#_(resolve-internal-link "rule-30/board") |
| 737 | + |
| 738 | +(defn process-internal-link [link] |
| 739 | + #?(:clj |
| 740 | + (let [{:keys [path var]} (resolve-internal-link link)] |
| 741 | + {:path path |
| 742 | + :fragment (when var (str (-> var symbol str) "-code")) |
| 743 | + :title (or (when var (-> var symbol str)) |
| 744 | + (when path (:title (parser/parse-file {:doc? true} path))) |
| 745 | + link)}) |
| 746 | + :cljs |
| 747 | + {:path link :title link})) |
| 748 | + |
| 749 | +#_(process-internal-link "notebooks/rule_30.clj") |
| 750 | +#_(process-internal-link "viewers.html") |
| 751 | +#_(process-internal-link "how-clerk-works/hashes") |
| 752 | +#_(process-internal-link "rule-30/first-generation") |
| 753 | + |
| 754 | +(declare html) |
| 755 | + |
717 | 756 | (def markdown-viewers
|
718 | 757 | [{:name :nextjournal.markdown/doc
|
719 | 758 | :transform-fn (into-markup (fn [{:keys [id]}] [:div.viewer.markdown-viewer.w-full.max-w-prose.px-8 {:data-block-id id}]))}
|
|
742 | 781 | {:name :nextjournal.markdown/monospace :transform-fn (into-markup [:code])}
|
743 | 782 | {:name :nextjournal.markdown/strikethrough :transform-fn (into-markup [:s])}
|
744 | 783 | {:name :nextjournal.markdown/link :transform-fn (into-markup #(vector :a (:attrs %)))}
|
| 784 | + {:name :nextjournal.markdown/internal-link |
| 785 | + :transform-fn (update-val |
| 786 | + (fn [{:keys [text]}] |
| 787 | + (let [{:keys [path fragment title]} (process-internal-link text)] |
| 788 | + (html [:a.internal-link {:href (doc-url path fragment)} title]))))} |
745 | 789 |
|
746 | 790 | ;; inlines
|
747 | 791 | {:name :nextjournal.markdown/text :transform-fn (into-markup [:<>])}
|
|
1129 | 1173 |
|
1130 | 1174 | #_(update-if {:n "42"} :n #(Integer/parseInt %))
|
1131 | 1175 |
|
1132 |
| -(declare html doc-url) |
| 1176 | +(declare html) |
1133 | 1177 |
|
1134 | 1178 | (defn home? [{:keys [nav-path]}]
|
1135 | 1179 | (contains? #{"src/nextjournal/home.clj" "'nextjournal.clerk.home"} nav-path))
|
|
0 commit comments