mirror of
https://github.com/logseq/logseq.git
synced 2026-04-29 08:26:40 +00:00
Fix #14
This commit is contained in:
30
web/src/main/frontend/format/adoc.cljs
Normal file
30
web/src/main/frontend/format/adoc.cljs
Normal file
@@ -0,0 +1,30 @@
|
||||
(ns frontend.format.adoc
|
||||
(:require [frontend.format.protocol :as protocol]
|
||||
[frontend.config :as config]
|
||||
[frontend.loader :as loader]))
|
||||
|
||||
(defn loaded? []
|
||||
js/window.Asciidoctor)
|
||||
|
||||
(defn to-html
|
||||
[content config]
|
||||
(when (loaded?)
|
||||
(.makeHtml (js/window.showdown.Converter.) content)))
|
||||
|
||||
(defrecord AdocMode []
|
||||
protocol/Format
|
||||
(toHtml [this content config]
|
||||
(when (loaded?)
|
||||
(let [config {:attributes {:showTitle false
|
||||
:hardbreaks true
|
||||
:icons "font"
|
||||
;; :source-highlighter "pygments"
|
||||
}}]
|
||||
(.convert (js/window.Asciidoctor) content (clj->js config)))))
|
||||
(loaded? [this]
|
||||
(some? (loaded?)))
|
||||
(lazyLoad [this ok-handler error-handler]
|
||||
(loader/load
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/asciidoctor.js/1.5.9/asciidoctor.min.js"
|
||||
ok-handler
|
||||
error-handler)))
|
||||
@@ -1,13 +1,25 @@
|
||||
(ns frontend.format.markdown
|
||||
(:require ["showdown" :refer [Converter]]
|
||||
[frontend.format.protocol :as protocol]))
|
||||
(:require [frontend.format.protocol :as protocol]
|
||||
[frontend.config :as config]
|
||||
[frontend.loader :as loader]))
|
||||
|
||||
(defonce converter (Converter.))
|
||||
(defn loaded? []
|
||||
js/window.showdown)
|
||||
|
||||
(defrecord Markdown [content]
|
||||
(defn to-html
|
||||
[content config]
|
||||
(when (loaded?)
|
||||
(.makeHtml (js/window.showdown.Converter.) content)))
|
||||
|
||||
(defrecord MdMode []
|
||||
protocol/Format
|
||||
(toHtml [this]
|
||||
(.makeHtml converter content))
|
||||
(toHtml [this config]
|
||||
;; TODO:
|
||||
(.makeHtml converter content)))
|
||||
(toHtml [this content config]
|
||||
(when (loaded?)
|
||||
(.makeHtml (js/window.showdown.Converter.) content)))
|
||||
(loaded? [this]
|
||||
(some? (loaded?)))
|
||||
(lazyLoad [this ok-handler error-handler]
|
||||
(loader/load
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/showdown/1.9.1/showdown.min.js"
|
||||
ok-handler
|
||||
error-handler)))
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
(ns frontend.format.org-mode
|
||||
(:require [frontend.format.protocol :as protocol]
|
||||
[frontend.util :as util]
|
||||
[clojure.string :as string]))
|
||||
[frontend.config :as config]
|
||||
[clojure.string :as string]
|
||||
[frontend.loader :as loader]))
|
||||
|
||||
(def default-config
|
||||
(js/JSON.stringify
|
||||
@@ -15,33 +17,43 @@
|
||||
:heading_number false
|
||||
:keep_line_break true}))
|
||||
|
||||
(def Org js/window.MldocOrg)
|
||||
(defn loaded? []
|
||||
js/window.MldocOrg)
|
||||
|
||||
(defrecord OrgMode [content]
|
||||
(defrecord OrgMode []
|
||||
protocol/Format
|
||||
(toHtml [this]
|
||||
(.parseHtml Org content default-config))
|
||||
(toHtml [this config]
|
||||
(.parseHtml Org content config)))
|
||||
(toHtml [this content config]
|
||||
(when (loaded?)
|
||||
(.parseHtml js/window.MldocOrg content config)))
|
||||
(loaded? [this]
|
||||
(some? (loaded?)))
|
||||
(lazyLoad [this ok-handler error-handler]
|
||||
(loader/load
|
||||
(config/asset-uri "/static/js/mldoc_org.min.js")
|
||||
ok-handler
|
||||
error-handler)))
|
||||
|
||||
(defn parse-json
|
||||
([content]
|
||||
(parse-json content default-config))
|
||||
([content config]
|
||||
(.parseJson Org content config)))
|
||||
(when (loaded?)
|
||||
(.parseJson js/window.MldocOrg content config))))
|
||||
|
||||
(defn ->clj
|
||||
[content]
|
||||
(if (string/blank? content)
|
||||
{}
|
||||
(-> content
|
||||
(parse-json)
|
||||
(util/json->clj))))
|
||||
(parse-json)
|
||||
(util/json->clj))))
|
||||
|
||||
(defn inline-list->html
|
||||
[json]
|
||||
(.inlineListToHtmlStr Org json))
|
||||
(when (loaded?)
|
||||
(.inlineListToHtmlStr js/window.MldocOrg json)))
|
||||
|
||||
(defn json->html
|
||||
[json]
|
||||
(.jsonToHtmlStr Org json default-config))
|
||||
(when (loaded?)
|
||||
(.jsonToHtmlStr js/window.MldocOrg json default-config)))
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
(ns frontend.format.protocol)
|
||||
|
||||
(defprotocol Format
|
||||
(toHtml [this] [this config]))
|
||||
(toHtml [this content config])
|
||||
(loaded? [this])
|
||||
(lazyLoad [this ok-handler error-handler]))
|
||||
|
||||
Reference in New Issue
Block a user