Skip to content

Commit 4f02973

Browse files
author
Bruce Hauman
committed
use global-exports to supply vendored markdown and highlighting libs
1 parent 47fe3c4 commit 4f02973

File tree

10 files changed

+58
-27
lines changed

10 files changed

+58
-27
lines changed

project.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
[cljsjs/react "16.4.1-0"]
1111
[cljsjs/react-dom "16.4.1-0"]
1212
[cljsjs/create-react-class "15.6.3-1"]
13-
[sablono "0.8.4"]
14-
[cljsjs/marked "0.3.5-1"]]
13+
[sablono "0.8.4"]]
1514

1615
:source-paths ["src"]
1716

resources/public/devcards/js/highlight.pack.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/deps.cljs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{:foreign-libs
2+
[{:file "devcards/js_libs/highlight.pack.js"
3+
:provides ["devcards-syntax-highlighter"]
4+
:global-exports {devcards-syntax-highlighter DevcardsSyntaxHighlighter}}
5+
{:file "devcards/js_libs/marked.min.js"
6+
:provides ["devcards-marked"]
7+
:global-exports {devcards-marked DevcardsMarked}}]
8+
:externs ["devcards/js_libs/highlight.ext.js"
9+
"devcards/js_libs/marked.ext.js"]}

src/devcards/core.cljs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
(ns devcards.core
22
(:require
33
[devcards.system :as dev]
4-
54
[devcards.util.markdown :as mark]
65
[devcards.util.utils :as utils
76
:refer [html-env? define-react-class define-react-class-once]]
8-
97
[sablono.core :as sab :include-macros true]
108
[devcards.util.edn-renderer :as edn-rend]
119
[goog.object :as gobj]
1210
[clojure.string :as string]
1311
[cljs.test]
12+
[goog.labs.userAgent.device :as device]
1413
[react :as react]
1514
[react-dom :as react-dom]
1615
[create-react-class :as create-react-class]
16+
[devcards-syntax-highlighter :as devcards-syntax-highlighter]
1717
[cljs.core.async :refer [put! chan sliding-buffer timeout <! close! alts!] :as async])
1818
(:require-macros
1919
[devcards.core]
@@ -105,22 +105,18 @@
105105

106106
;; syntax highlighting
107107

108-
(defn get-hljs []
109-
(gobj/get js/goog.global "hljs"))
110-
111108
(defn highlight-node [this]
112-
(when-let [node (ref->node this "code-ref")]
113-
(when-let [hljs (get-hljs)]
114-
(when-let [highlight-block (gobj/get hljs "highlightBlock")]
115-
(highlight-block node)))))
109+
(when-not (device/isMobile)
110+
(when-let [node (ref->node this "code-ref")]
111+
(js/DevcardsSyntaxHighlighter.highlightBlock node))))
116112

117113
(define-react-class CodeHighlight
118114
(componentDidMount [this] (highlight-node this))
119115
(componentDidUpdate [this] (highlight-node this))
120116
(render
121117
[this]
122118
(sab/html
123-
[:pre {:className (if (get-hljs) "com-rigsomelight-devcards-code-highlighting" "")
119+
[:pre {:className (if-not (device/isMobile) "com-rigsomelight-devcards-code-highlighting" "")
124120
:key (hash (get-props this :code))}
125121
[:code {:className (or (get-props this :lang) "")
126122
:ref "code-ref"}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// copied from https://github.com/isagalaev/highlight.js/blob/6662b/src/highlight.js#L699-L711
2+
3+
var DevcardsSyntaxHighlighter = {};
4+
DevcardsSyntaxHighlighter.highlight = function (name, value, ignore_illegals, continuation) {};
5+
DevcardsSyntaxHighlighter.highlightAuto = function (text, languageSubset) {};
6+
DevcardsSyntaxHighlighter.fixMarkup = function (value) {};
7+
DevcardsSyntaxHighlighter.highlightBlock = function (block) {};
8+
DevcardsSyntaxHighlighter.configure = function (user_options) {};
9+
DevcardsSyntaxHighlighter.initHighlighting = function () {};
10+
DevcardsSyntaxHighlighter.initHighlightingOnLoad = function () {};
11+
DevcardsSyntaxHighlighter.registerLanguage = function (name, language) {};
12+
DevcardsSyntaxHighlighter.listLanguages = function () {};
13+
DevcardsSyntaxHighlighter.getLanguage = function (name) {};
14+
DevcardsSyntaxHighlighter.inherit = function (parent, obj) {};

src/devcards/js_libs/highlight.pack.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/devcards/js_libs/marked.ext.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
function DevcardsMarked() {};
3+
4+
DevcardsMarked.options = {};
5+
DevcardsMarked.defaults = {};
6+
7+
DevcardsMarked.parser = function() {};
8+
DevcardsMarked.parse = function() {};
9+
DevcardsMarked.Parser = function() {};
10+
11+
DevcardsMarked.lexer = function() {};
12+
DevcardsMarked.Lexer = function() {};
13+
14+
DevcardsMarked.inlineLexer = function() {};
15+
DevcardsMarked.InlineLexer = function() {};
16+
17+
DevcardsMarked.Renderer = function() {};
18+
DevcardsMarked.setOptions = function() {};

src/devcards/js_libs/marked.min.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/devcards/system.cljs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
[goog.object :as gobj]
88
[goog.events :as events]
99
[goog.history.EventType :as EventType]
10-
[goog.labs.userAgent.device :as device]
1110
[devcards.util.utils :as utils :refer-macros [define-react-class]]
1211
[react :as react]
1312
[react-dom :as react-dom])
@@ -64,7 +63,6 @@
6463
(create-style-element "com-rigsomelight-code-highlight-css"
6564
(inline-resouce-file "public/devcards/css/com_rigsomelight_github_highlight.css"))))
6665

67-
6866
(when-not (get-element-by-id "com-rigsomelight-devcards-css")
6967
(.appendChild head (create-style-element "com-rigsomelight-devcards-css"
7068
(inline-resouce-file "public/devcards/css/com_rigsomelight_devcards.css"))))
@@ -74,16 +72,7 @@
7472
(when-not (get-element-by-id "com-rigsomelight-edn-css")
7573
(.appendChild head
7674
(create-style-element "com-rigsomelight-edn-css"
77-
(inline-resouce-file "public/devcards/css/com_rigsomelight_edn_flex.css"))))
78-
79-
;; we are injecting conditionally so that we can skip mobile
80-
;; and skip node
81-
;; really not diggin this but ...
82-
(when-not (or (get-element-by-id "com-rigsomelight-code-highlighting")
83-
(device/isMobile))
84-
(.appendChild head
85-
(create-script-element "com-rigsomelight-code-highlighting"
86-
(inline-resouce-file "public/devcards/js/highlight.pack.js")))))))
75+
(inline-resouce-file "public/devcards/css/com_rigsomelight_edn_flex.css")))))))
8776

8877
(defn render-base-if-necessary! []
8978
(add-css-if-necessary!)

src/devcards/util/markdown.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns devcards.util.markdown
22
(:require
33
[clojure.string :as string]
4-
[cljsjs.marked]))
4+
[devcards-marked :as devcards-marked]))
55

66
(defn leading-space-count [s]
77
(when-let [ws (second (re-matches #"^([\s]*).*" s))]
@@ -25,7 +25,7 @@
2525
(string/trim s)))
2626

2727
(defn markdown-to-html [markdown-txt]
28-
(js/marked markdown-txt))
28+
(js/DevcardsMarked markdown-txt))
2929

3030
(defn matches-delim? [line]
3131
(re-matches #"^[\s]*```(\w*).*" line))

0 commit comments

Comments
 (0)