diff --git a/lms/static/coffee/src/customwmd.coffee b/lms/static/coffee/src/customwmd.coffee
index 6b3a040a35..8a3a2d7c97 100644
--- a/lms/static/coffee/src/customwmd.coffee
+++ b/lms/static/coffee/src/customwmd.coffee
@@ -6,10 +6,6 @@ $ ->
class MathJaxProcessor
- inlineMark = "$"
- math = null
- blocks = null
-
MATHSPLIT = /// (
\$\$? # normal inline or display delimiter
| \\(?:begin|end)\{[a-z]*\*?\} # \begin{} \end{} style
@@ -27,33 +23,26 @@ $ ->
(?!`)
///gm
- ###HUB.Queue ->
- console.log "initializing"
- renderReady = true
- HUB.processUpdateTime = 50
- HUB.Config
- "HTML-CSS":
- EqnChunk: 10
- EqnChunkFactor: 1
- SVG:
- EqnChunk: 10
- EqnChunkFactor: 1
- ###
+ constructor: (inlineMark, displayMark) ->
+ @inlineMark = inlineMark || "$"
+ @displayMark = displayMark || "$$"
+ @math = null
+ @blocks = null
- @processMath: (start, last, preProcess) =>
- block = blocks.slice(start, last + 1).join("").replace(/&/g, "&")
+ processMath: (start, last, preProcess) ->
+ block = @blocks.slice(start, last + 1).join("").replace(/&/g, "&")
.replace(//g, ">")
if HUB.Browser.isMSIE
block = block.replace /(%[^\n]*)\n/g, "$1
\n"
- blocks[i] = "" for i in [start+1..last]
- blocks[start] = "@@#{math.length}@@"
+ @blocks[i] = "" for i in [start+1..last]
+ @blocks[start] = "@@#{@math.length}@@"
block = preProcess(block) if preProcess
- math.push block
+ @math.push block
- @removeMath: (text) =>
+ removeMath: (text) ->
- math = []
+ @math = []
start = end = last = null
braces = 0
@@ -67,13 +56,13 @@ $ ->
else
deTilde = (text) -> text
- blocks = _split(text.replace(/\r\n?/g, "\n"), MATHSPLIT)
+ @blocks = _split(text.replace(/\r\n?/g, "\n"), MATHSPLIT)
- for current in [1...blocks.length] by 2
- block = blocks[current]
+ for current in [1...@blocks.length] by 2
+ block = @blocks[current]
if block.charAt(0) == "@"
- blocks[current] = "@@#{math.length}@@"
- math.push block
+ @blocks[current] = "@@#{@math.length}@@"
+ @math.push block
else if start
if block == end
if braces
@@ -92,7 +81,7 @@ $ ->
else if block == "}" and braces
--braces
else
- if block == inlineMark or block == "$$"
+ if block == @inlineMark or block == @displayMark
start = current
end = block
braces = 0
@@ -105,75 +94,38 @@ $ ->
@processMath(start, last, deTilde)
start = end = last = null
- deTilde(blocks.join(""))
+ deTilde(@blocks.join(""))
- @replaceMath: (text) =>
- text = text.replace /@@(\d+)@@/g, ($0, $1) => math[$1]
- math = null
+ replaceMath: (text) ->
+ text = text.replace /@@(\d+)@@/g, ($0, $1) => @math[$1]
+ @math = null
text
- @updateMathJax: =>
- HUB.Queue(["Typeset", HUB, "wmd-preview"])
-
-
-
- ###
- if not HUB.Cancel? #and 1 == 2
- HUB.cancelTypeset = false
- CANCELMESSAGE = "MathJax Canceled"
-
- HOOKS = [
- {
- name: "HTML-CSS Jax Config"
- engine: -> window["MathJax"].OutputJax["HTML-CSS"]
- },
- {
- name: "SVG Jax Config"
- engine: -> window["MathJax"].OutputJax["SVG"]
- },
- {
- name: "TeX Jax Config"
- engine: -> window["MathJax"].InputJax.TeX
- },
- ]
-
- for hook in HOOKS
- do (hook) ->
- HUB.Register.StartupHook hook.name, ->
- engine = hook.engine()
- engine.Augment
- Translate: (script, state) ->
- console.log "translating"
- if HUB.cancelTypeset or state.cancelled
- throw Error(CANCELMESSAGE)
- engine.Translate.call(engine, script, state)
-
- prevProcessError = HUB.processError
- HUB.processError = (error, state, type) ->
- if error.message != CANCELMESSAGE
- return prevProcessError.call(HUB, error, state, type)
- else
- console.log "handling message"
- MathJax.Message.Clear(0, 0)
- state.jaxIds = []
- state.jax = {}
- state.scripts = []
- state.i = state.j = 0
- state.cancelled = true
- return null
-
- HUB.Cancel = ->
- this.cancelTypeset = true
- ###
-
if Markdown?
- converter = Markdown.getSanitizingConverter()
- editor = new Markdown.Editor(converter)
- converter.hooks.chain "preConversion", MathJaxProcessor.removeMath
- converter.hooks.chain "postConversion", MathJaxProcessor.replaceMath
- delayRenderer = new MathJaxDelayRenderer()
- editor.hooks.chain "onPreviewPush", (text, previewSet) ->
- delayRenderer.render
- text: text
- previewSetter: previewSet
- editor.run()
+ Markdown.getMathCompatibleConverter = ->
+ converter = Markdown.getSanitizingConverter()
+ processor = new MathJaxProcessor()
+ converter.hooks.chain "preConversion", processor.removeMath
+ converter.hooks.chain "postConversion", processor.replaceMath
+ converter
+
+ Markdown.makeWmdEditor = (elem, appended_id) ->
+ $elem = $(elem)
+ if not $elem.length
+ console.log "warning: elem for makeWmdEditor doesn't exist"
+ return
+ if not $elem.find(".wmd-panel").length
+ _append = appended_id || ""
+ $wmdPanel = $("