|
360 | 360 | state
|
361 | 361 | (info-store-keys info)))
|
362 | 362 |
|
| 363 | +(defn extract-file |
| 364 | + "Extracts the string file path from the given `resource` to for usage |
| 365 | + on the `:clojure.core/eval-file` form meta key." |
| 366 | + [^java.net.URL resource] |
| 367 | + (case (.getProtocol resource) |
| 368 | + "file" (str (.getFile resource)) |
| 369 | + "jar" (str (.getJarEntry ^java.net.JarURLConnection (.openConnection resource))))) |
| 370 | + |
| 371 | +#_(extract-file (io/resource "clojure/core.clj")) |
| 372 | +#_(extract-file (io/resource "nextjournal/clerk.clj")) |
| 373 | + |
363 | 374 | (defn analyze-doc
|
364 | 375 | "Goes through `:blocks` of `doc`, reads and analyzes block forms, populates `:->analysis-info`"
|
365 | 376 | ([doc]
|
|
380 | 391 | form+loc (cond-> form
|
381 | 392 | (instance? clojure.lang.IObj form)
|
382 | 393 | (vary-meta merge (cond-> loc
|
383 |
| - (:file doc) (assoc :clojure.core/eval-file (str (:file doc)))))) |
| 394 | + (:file doc) (assoc :clojure.core/eval-file |
| 395 | + (str (cond-> (:file doc) |
| 396 | + (instance? java.net.URL (:file doc)) extract-file)))))) |
384 | 397 | {:as analyzed :keys [ns-effect?]} (cond-> (analyze form+loc)
|
385 | 398 | (:file doc) (assoc :file (:file doc)))
|
386 |
| - _ (when ns-effect? ;; needs to run before setting doc `:ns` via `*ns*` |
| 399 | + _ (when ns-effect? ;; needs to run before setting doc `:ns` via `*ns*` |
387 | 400 | (eval form))
|
388 | 401 | block-id (get-block-id !id->count (merge analyzed block))
|
389 | 402 | analyzed (assoc analyzed :id block-id)]
|
|
394 | 407 | (update :blocks conj (-> block
|
395 | 408 | (merge (dissoc analyzed :deps :no-cache? :ns-effect?))
|
396 | 409 | (cond->
|
397 |
| - (parser/ns? form) (assoc :ns? true) |
398 |
| - doc? (assoc :text-without-meta (parser/text-with-clerk-metadata-removed text (ns-resolver notebook-ns)))))) |
| 410 | + (parser/ns? form) (assoc :ns? true) |
| 411 | + doc? (assoc :text-without-meta (parser/text-with-clerk-metadata-removed text (ns-resolver notebook-ns)))))) |
399 | 412 | (cond->
|
400 |
| - (and doc? (not (contains? state :ns))) |
| 413 | + (and doc? (not (contains? state :ns))) |
401 | 414 | (merge (parser/->doc-settings form) {:ns *ns*}))))))
|
402 | 415 |
|
403 | 416 | (-> state
|
|
0 commit comments