From 0d686a9b6338f000219dfd5ef0cb1ac33f7abc71 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Wed, 12 Feb 2020 12:35:18 +0000 Subject: [PATCH] #47: Something well broken here, but I'm on the right path Fragment indices are being returned instead of fragments, and it does not seem that the extension formatters are being called at all. But... config is definitely improved in the right direction. --- project.clj | 1 + resources/config.edn | 11 ++++++----- .../content/Simplified example gallery.md | 2 +- src/smeagol/extensions/photoswipe.clj | 17 +++++++++++------ src/smeagol/formatting.clj | 15 +++++++++++++-- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/project.clj b/project.clj index b753cd1..3898e1c 100644 --- a/project.clj +++ b/project.clj @@ -27,6 +27,7 @@ [org.clojure/core.memoize "0.5.9"] [org.clojure/data.json "0.2.6"] [org.clojure/tools.logging "0.4.0"] + [org.clojure/tools.trace "0.7.10"] [org.slf4j/slf4j-api "1.7.25"] [org.slf4j/log4j-over-slf4j "1.7.25"] [org.slf4j/jul-to-slf4j "1.7.25"] diff --git a/resources/config.edn b/resources/config.edn index 059dfeb..6ff0faf 100644 --- a/resources/config.edn +++ b/resources/config.edn @@ -32,11 +32,12 @@ :default-locale "en-GB" ;; default language used for messages :formatters ;; formatters for processing markdown ;; extensions. - {"vega" smeagol.formatting/process-vega - "vis" smeagol.formatting/process-vega - "mermaid" smeagol.extensions.mermaid/process-mermaid - "backticks" smeagol.formatting/process-backticks - "pswp" smeagol.extensions.photoswipe/process-photoswipe} + {:vega {:formatter "smeagol.extensions.vega/process-vega" } + :vis {:formatter "smeagol.extensions.vega/process-vega" } + :mermaid {:formatter "smeagol.extensions.mermaid/process-mermaid" } + :backticks {:formatter "smeagol.formatting/process-backticks" } + :pswp {:formatter "smeagol.extensions.photoswipe/process-photoswipe" } + } :log-level :info ;; the minimum logging level; one of ;; :trace :debug :info :warn :error :fatal :js-from :cdnjs ;; where to load JavaScript libraries diff --git a/resources/public/content/Simplified example gallery.md b/resources/public/content/Simplified example gallery.md index 4cff2da..eac0394 100644 --- a/resources/public/content/Simplified example gallery.md +++ b/resources/public/content/Simplified example gallery.md @@ -13,7 +13,7 @@ That's all there is to it - a sequence of image links just as you'd write them a ## The Gallery -This page holds another example Photoswipe gallery, this time using a simpler, Markdown-based specification. Processing this specification takes more work than the full syntax used in the other [Example gallery], so the gallery may be slower to load; but it's much easier to configure. +This page holds another example Photoswipe gallery, this time using a simpler, Markdown-based specification. Processing this specification takes more work than the full syntax used in the other [[Example gallery]], so the gallery may be slower to load; but it's much easier to configure. ```pswp ![Frost on a gate, Laurieston](content/uploads/g1.jpg) diff --git a/src/smeagol/extensions/photoswipe.clj b/src/smeagol/extensions/photoswipe.clj index 31c6e42..2df235e 100644 --- a/src/smeagol/extensions/photoswipe.clj +++ b/src/smeagol/extensions/photoswipe.clj @@ -174,10 +174,15 @@ ;; 1) (defn process-photoswipe - [^String url-or-pswp-spec ^Integer index] + [^String url-or-pswp-spec ^Integer index] + (log/info "process-photoswipe called with arg1 `" + url-or-pswp-spec "`; arg2 `" index "`.") (let [data (resource-url-or-data->data url-or-pswp-spec) - spec (cs/trim (:data data))] - (if - (cs/starts-with? spec "![") - (process-simple-photoswipe spec index) - (process-full-photoswipe spec index)))) + spec (cs/trim (:data data)) + result + (if + (cs/starts-with? spec "![") + (process-simple-photoswipe spec index) + (process-full-photoswipe spec index))] + (log/info "process-photoswipe returning `" result "`.") + )) diff --git a/src/smeagol/formatting.clj b/src/smeagol/formatting.clj index fa4f2f6..87d8f45 100644 --- a/src/smeagol/formatting.clj +++ b/src/smeagol/formatting.clj @@ -8,7 +8,8 @@ [markdown.core :as md] [smeagol.configuration :refer [config]] [smeagol.extensions.mermaid :refer [process-mermaid]] - [smeagol.extensions.photoswipe :refer [process-photoswipe]])) + [smeagol.extensions.photoswipe :refer [process-photoswipe]] + [taoensso.timbre :as log])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; @@ -149,7 +150,17 @@ ;; I need to put the backticks back in. remarked (if (odd? index) (str "```" fragment "\n```") fragment) first-token (get-first-token fragment) - formatter (eval ((:formatters config) first-token))] + formatter (if-not + (empty? first-token) + (try + (let [kw (keyword first-token)] + (read-string (-> config :formatters kw :formatter))) + (catch Exception _ + (do + (log/info "No formatter found for extension `" first-token "`") + ;; no extension registered - there sometimes won't be, + ;; and it doesn't matter + nil))))] (cond (empty? fragments) (assoc result :text