mirror of
https://github.com/logseq/logseq.git
synced 2026-04-28 16:15:21 +00:00
Add markdown support
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
(ns frontend.format.markdown
|
||||
(:require [frontend.format.protocol :as protocol]
|
||||
[frontend.config :as config]
|
||||
[frontend.loader :as loader]
|
||||
[cljs-bean.core :as bean]))
|
||||
|
||||
(defn loaded? []
|
||||
js/window.showdown)
|
||||
|
||||
(def default-config
|
||||
{:simpleLineBreaks true
|
||||
:tasklists true
|
||||
:tables true
|
||||
:strikethrough true
|
||||
:simplifiedAutoLink true})
|
||||
|
||||
(defn ->edn
|
||||
[content config]
|
||||
nil)
|
||||
|
||||
(defrecord MdMode []
|
||||
protocol/Format
|
||||
(toEdn [this content config]
|
||||
(->edn content config))
|
||||
(toHtml [this content config]
|
||||
(when (loaded?)
|
||||
(.makeHtml (js/window.showdown.Converter. (bean/->js (or config default-config))) content)))
|
||||
(loaded? [this]
|
||||
(some? (loaded?)))
|
||||
(lazyLoad [this ok-handler]
|
||||
(loader/load
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/showdown/1.9.1/showdown.min.js"
|
||||
ok-handler)))
|
||||
46
web/src/main/frontend/format/org_md.cljs
Normal file
46
web/src/main/frontend/format/org_md.cljs
Normal file
@@ -0,0 +1,46 @@
|
||||
(ns frontend.format.org-md
|
||||
(:require [frontend.format.protocol :as protocol]
|
||||
[frontend.util :as util]
|
||||
[frontend.config :as config]
|
||||
[clojure.string :as string]
|
||||
[frontend.loader :as loader]
|
||||
[cljs-bean.core :as bean]))
|
||||
|
||||
(defn default-config
|
||||
[format]
|
||||
(let [format (string/capitalize (name format))]
|
||||
(js/JSON.stringify
|
||||
(bean/->js
|
||||
(assoc {:toc false
|
||||
:heading_number false
|
||||
:keep_line_break true}
|
||||
:format format)))))
|
||||
|
||||
(defn loaded? []
|
||||
js/window.MldocOrg)
|
||||
|
||||
(defn parse-json
|
||||
[content config]
|
||||
(when (loaded?)
|
||||
(.parseJson js/window.MldocOrg content (or config default-config))))
|
||||
|
||||
(defn ->edn
|
||||
[content config]
|
||||
(if (string/blank? content)
|
||||
{}
|
||||
(-> content
|
||||
(parse-json config)
|
||||
(util/json->clj))))
|
||||
|
||||
(defrecord OrgMdMode []
|
||||
protocol/Format
|
||||
(toEdn [this content config]
|
||||
(->edn content config))
|
||||
(toHtml [this content config]
|
||||
(.parseHtml js/window.MldocOrg content config))
|
||||
(loaded? [this]
|
||||
(some? (loaded?)))
|
||||
(lazyLoad [this ok-handler]
|
||||
(loader/load
|
||||
(config/asset-uri "/static/js/mldoc_org.min.js")
|
||||
ok-handler)))
|
||||
@@ -1,45 +0,0 @@
|
||||
(ns frontend.format.org-mode
|
||||
(:require [frontend.format.protocol :as protocol]
|
||||
[frontend.util :as util]
|
||||
[frontend.config :as config]
|
||||
[clojure.string :as string]
|
||||
[frontend.loader :as loader]))
|
||||
|
||||
(def default-config
|
||||
(js/JSON.stringify
|
||||
#js {:toc false
|
||||
:heading_number false
|
||||
:keep_line_break true}))
|
||||
|
||||
(defn loaded? []
|
||||
js/window.MldocOrg)
|
||||
|
||||
(defn parse-json
|
||||
([content]
|
||||
(parse-json content default-config))
|
||||
([content config]
|
||||
(when (loaded?)
|
||||
(.parseJson js/window.MldocOrg content (or config default-config)))))
|
||||
|
||||
(defn ->edn
|
||||
([content]
|
||||
(->edn content default-config))
|
||||
([content config]
|
||||
(if (string/blank? content)
|
||||
{}
|
||||
(-> content
|
||||
(parse-json (or config default-config))
|
||||
(util/json->clj)))))
|
||||
|
||||
(defrecord OrgMode []
|
||||
protocol/Format
|
||||
(toEdn [this content config]
|
||||
(->edn content config))
|
||||
(toHtml [this content config]
|
||||
(.parseHtml js/window.MldocOrg content config))
|
||||
(loaded? [this]
|
||||
(some? (loaded?)))
|
||||
(lazyLoad [this ok-handler]
|
||||
(loader/load
|
||||
(config/asset-uri "/static/js/mldoc_org.min.js")
|
||||
ok-handler)))
|
||||
Reference in New Issue
Block a user