mirror of
https://github.com/journeyman-cc/smeagol.git
synced 2026-04-12 18:05:06 +00:00
Still no actual progress.
This commit is contained in:
parent
8032ad60af
commit
37d850d30a
7 changed files with 102 additions and 63 deletions
|
|
@ -32,7 +32,21 @@
|
|||
:default-locale "en-GB" ;; default language used for messages
|
||||
:formatters ;; formatters for processing markdown
|
||||
;; extensions.
|
||||
{:vega {:formatter "smeagol.extensions.vega/process-vega"
|
||||
{:backticks {:formatter "smeagol.formatting/process-backticks"
|
||||
:scripts {}
|
||||
:styles {}}
|
||||
:mermaid {:formatter "smeagol.extensions.mermaid/process-mermaid"
|
||||
:scripts {:core {:local "vendor/mermaid/dist/mermaid.js"}}
|
||||
:styles {}}
|
||||
:pswp {:formatter "smeagol.extensions.photoswipe/process-photoswipe"
|
||||
:scripts {:core {:local "/vendor/node_modules/photoswipe/dist/photoswipe.min.js"
|
||||
:remote "https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.3/photoswipe.min.js"}
|
||||
:ui {:local "/vendor/node_modules/photoswipe/dist/photoswipe-ui-default.min.js"
|
||||
:remote "https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.3/photoswipe-ui-default.min.js"}}
|
||||
:styles {:core {:local "/vendor/node_modules/photoswipe/dist/photoswipe.css"
|
||||
:remote "/vendor/node_modules/photoswipe/dist/default-skin/default-skin.css"}}}
|
||||
:test {:formatter "smeagol.extensions.test/process-test" }
|
||||
:vega {:formatter "smeagol.extensions.vega/process-vega"
|
||||
:scripts {:core {:remote "https://cdnjs.cloudflare.com/ajax/libs/vega/5.9.1/vega.min.js"}
|
||||
:lite {:remote "https://cdnjs.cloudflare.com/ajax/libs/vega-lite/4.1.1/vega-lite.min.js"}
|
||||
:embed {:remote "https://cdnjs.cloudflare.com/ajax/libs/vega-embed/6.2.2/vega-embed.min.js"}
|
||||
|
|
@ -42,19 +56,6 @@
|
|||
:lite {:remote "https://cdnjs.cloudflare.com/ajax/libs/vega-lite/4.1.1/vega-lite.min.js"}
|
||||
:embed {:remote "https://cdnjs.cloudflare.com/ajax/libs/vega-embed/6.2.2/vega-embed.min.js"}
|
||||
:styles {}}}
|
||||
:mermaid {:formatter "smeagol.extensions.mermaid/process-mermaid"
|
||||
:scripts {:core {:local "vendor/mermaid/dist/mermaid.js"}}
|
||||
:styles {}}
|
||||
:backticks {:formatter "smeagol.formatting/process-backticks"
|
||||
:scripts {}
|
||||
:styles {}}
|
||||
:pswp {:formatter "smeagol.extensions.photoswipe/process-photoswipe"
|
||||
:scripts {:core {:local "/vendor/node_modules/photoswipe/dist/photoswipe.min.js"
|
||||
:remote "https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.3/photoswipe.min.js"}
|
||||
:ui {:local "/vendor/node_modules/photoswipe/dist/photoswipe-ui-default.min.js"
|
||||
:remote "https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.3/photoswipe-ui-default.min.js"}}
|
||||
:styles {:core {:local "/vendor/node_modules/photoswipe/dist/photoswipe.css"
|
||||
:remote "/vendor/node_modules/photoswipe/dist/default-skin/default-skin.css"}}}
|
||||
}
|
||||
:log-level :info ;; the minimum logging level; one of
|
||||
;; :trace :debug :info :warn :error :fatal
|
||||
|
|
|
|||
|
|
@ -176,12 +176,8 @@
|
|||
(defn process-photoswipe
|
||||
[^String url-or-pswp-spec ^Integer index]
|
||||
(let [data (resource-url-or-data->data url-or-pswp-spec)
|
||||
spec (cs/trim (:data data))
|
||||
result
|
||||
spec (cs/trim (:data data))]
|
||||
(if
|
||||
(cs/starts-with? spec "![")
|
||||
(process-simple-photoswipe spec index)
|
||||
(process-full-photoswipe spec index))]
|
||||
;; (log/info "process-photoswipe returning `" result "`.")
|
||||
result
|
||||
))
|
||||
(process-full-photoswipe spec index))))
|
||||
|
|
|
|||
10
src/smeagol/extensions/test.clj
Normal file
10
src/smeagol/extensions/test.clj
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
(ns ^{:doc "Very simple extension for testing the extension processing flow."
|
||||
:author "Simon Brooke"}
|
||||
smeagol.extensions.test)
|
||||
|
||||
|
||||
(def process-test-return-value "<!-- The test extension has run and this is its output -->")
|
||||
|
||||
(defn process-test
|
||||
[^String fragment ^Integer index]
|
||||
process-test-return-value)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
(ns ^{:doc "Format Semagol's extended markdown format."
|
||||
(ns ^{:doc "Format vega/vis extensions to Semagol's extended markdown format."
|
||||
:author "Simon Brooke"}
|
||||
smeagol.extensions.vega
|
||||
(:require [clojure.data.json :as json]
|
||||
|
|
|
|||
|
|
@ -93,10 +93,20 @@
|
|||
fragments
|
||||
(cons fragment processed)))
|
||||
|
||||
(defn deep-merge [v & vs]
|
||||
"Cripped in its entirety from https://clojuredocs.org/clojure.core/merge."
|
||||
(letfn [(rec-merge [v1 v2]
|
||||
(if (and (map? v1) (map? v2))
|
||||
(merge-with deep-merge v1 v2)
|
||||
v2))]
|
||||
(if (some identity vs)
|
||||
(reduce #(rec-merge %1 %2) v vs)
|
||||
(last vs))))
|
||||
|
||||
|
||||
(defn apply-formatter
|
||||
"Within the context of `process-text`, process a fragment for which an explicit
|
||||
§formatter has been identified.
|
||||
`formatter` has been identified.
|
||||
|
||||
As with `process-text`, this function returns a map with two top-level keys:
|
||||
`:inclusions`, a map of constructed keywords to inclusion specifications,
|
||||
|
|
@ -104,16 +114,28 @@
|
|||
corresponding inclusion should be inserted."
|
||||
[index result fragments processed fragment token formatter]
|
||||
(let
|
||||
[kw (keyword (str "inclusion-" index))]
|
||||
(assoc-in
|
||||
(process-text
|
||||
(inc index)
|
||||
[ident (keyword (str "inclusion-" index))]
|
||||
(process-text
|
||||
(inc index)
|
||||
(deep-merge
|
||||
result
|
||||
(rest fragments)
|
||||
(cons kw processed))
|
||||
[:inclusions kw]
|
||||
(apply formatter (list (subs fragment (count token)) index)))))
|
||||
{:inclusions {ident (apply formatter (list (subs fragment (count token)) index))}
|
||||
:extensions (cons (keyword token) (:extensions result))})
|
||||
fragments
|
||||
(cons ident processed))))
|
||||
|
||||
(apply-formatter
|
||||
3
|
||||
{:inclusions {}}
|
||||
'()
|
||||
'()
|
||||
"pswp
|
||||

|
||||

|
||||

|
||||
"
|
||||
"pswp"
|
||||
smeagol.extensions.photoswipe/process-photoswipe)
|
||||
|
||||
(defn process-text
|
||||
"Process this `text`, assumed to be markdown potentially containing both local links
|
||||
|
|
@ -124,7 +146,7 @@
|
|||
inclusion specifications, and `:text`, an HTML text string with the keywords
|
||||
present where the corresponding inclusion should be inserted."
|
||||
([^String text]
|
||||
(process-text 0 {:inclusions {}} (cs/split (or text "") #"```") '()))
|
||||
(process-text 0 {} (cs/split (or text "") #"```") '()))
|
||||
([index result fragments processed]
|
||||
(let [fragment (first fragments)
|
||||
;; if I didn't find a formatter for a back-tick marked fragment,
|
||||
|
|
@ -154,24 +176,28 @@
|
|||
formatter
|
||||
;; We've found a formatter to apply to the current fragment, and recurse
|
||||
;; on down the list
|
||||
(let [result (apply-formatter
|
||||
index
|
||||
result
|
||||
fragments
|
||||
processed
|
||||
fragment
|
||||
first-token
|
||||
formatter)]
|
||||
;; TODO: consistency: either these things are `extensions`, or
|
||||
;; they're `formatters`. I incline to the view that they're
|
||||
;; `:extensions`
|
||||
(assoc-in result [:extensions kw] (-> config :formatters kw)))
|
||||
(let
|
||||
[ident (keyword (str "inclusion-" index))]
|
||||
(deep-merge
|
||||
(process-text
|
||||
(inc index)
|
||||
result
|
||||
(rest fragments)
|
||||
(cons ident processed))
|
||||
{:inclusions {ident (apply formatter (list (subs fragment (count first-token)) index))}
|
||||
:extensions (cons kw (:extensions result))}))
|
||||
:else
|
||||
;; Otherwise process the current fragment as markdown and recurse on
|
||||
;; down the list
|
||||
(process-markdown-fragment
|
||||
index result remarked (rest fragments) processed)))))
|
||||
|
||||
(process-text
|
||||
"pswp
|
||||

|
||||

|
||||

|
||||
" )
|
||||
|
||||
(defn reintegrate-inclusions
|
||||
"Given a map of the form produced by `process-text`, return a string of HTML text
|
||||
|
|
|
|||
|
|
@ -61,33 +61,31 @@
|
|||
:version (System/getProperty "smeagol.version")}))
|
||||
|
||||
|
||||
(defn- raw-get-messages
|
||||
(def get-messages
|
||||
"Return the most acceptable messages collection we have given the
|
||||
`Accept-Language` header in this `request`."
|
||||
[request]
|
||||
(let [specifier ((:headers request) "accept-language")
|
||||
messages (try
|
||||
(i18n/get-messages specifier "i18n" "en-GB")
|
||||
(catch Exception any
|
||||
(log/error
|
||||
any
|
||||
(str
|
||||
"Failed to parse accept-language header '"
|
||||
specifier
|
||||
"'"))
|
||||
{}))]
|
||||
(memoize
|
||||
(fn [request]
|
||||
(let [specifier ((:headers request) "accept-language")
|
||||
messages (try
|
||||
(i18n/get-messages specifier "i18n" "en-GB")
|
||||
(catch Exception any
|
||||
(log/error
|
||||
any
|
||||
(str
|
||||
"Failed to parse accept-language header '"
|
||||
specifier
|
||||
"'"))
|
||||
{}))]
|
||||
(merge
|
||||
messages
|
||||
config)))
|
||||
|
||||
|
||||
(def get-messages (memoize raw-get-messages))
|
||||
config)))))
|
||||
|
||||
|
||||
(defn get-message
|
||||
"Return the message with this `message-key` from this `request`.
|
||||
if not found, return this `default`, if provided; else return the
|
||||
`message-key`."
|
||||
if not found, return this `default`, if provided; else return the
|
||||
`message-key`."
|
||||
([message-key request]
|
||||
(get-message message-key message-key request))
|
||||
([message-key default request]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
(ns smeagol.test.formatting
|
||||
(:require [clojure.test :refer :all]
|
||||
[smeagol.formatting :refer [local-links no-text-error]]))
|
||||
[smeagol.formatting :refer [local-links no-text-error]]
|
||||
[smeagol.extensions.test :refer :all]))
|
||||
|
||||
(deftest test-local-links
|
||||
(testing "Rewriting of local links"
|
||||
|
|
@ -10,3 +11,10 @@
|
|||
(let [text (str "# This is a heading"
|
||||
"[This is a foreign link](http://to.somewhere)")]
|
||||
(is (= (local-links text) text) "Foreign links should be unchanged"))))
|
||||
|
||||
(deftest test-process-text
|
||||
(testing "The process-text flow"
|
||||
(let [expected process-test-return-value
|
||||
actual (process-text "```test
|
||||
```")]
|
||||
(is (= actual expected)))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue