Discussion forum doesn't work when mathjax is down

When mathjax is down discussion forum doesn't work
as we were using markdown.js with processor as
mathjax. Unavailability of mathjax raise error in
js which stops discussion to render. So I made
markdown independent of mathjax. Markdown now will
use mathjax when it is available otherwise ignore it.

TNL-1149
This commit is contained in:
Waqas Khalid
2015-01-16 01:31:39 +05:00
parent 2c60a1d546
commit 11159ba71e
7 changed files with 16 additions and 14 deletions

View File

@@ -10,7 +10,8 @@ if Backbone?
@$el.html(Mustache.render(@template, params))
@$("span.timeago").timeago()
element = @$(".post-body")
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element[0]]
if MathJax?
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element[0]]
@
convertMath: ->

View File

@@ -32,7 +32,8 @@ if Backbone?
convertMath: ->
element = @$(".post-body")
element.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight element.text()
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element[0]]
if MathJax?
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element[0]]
edit: (event) ->
@trigger "thread:edit", event

View File

@@ -33,7 +33,8 @@ if Backbone?
convertMath: ->
body = @$el.find(".response-body")
body.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight body.text()
MathJax.Hub.Queue ["Typeset", MathJax.Hub, body[0]]
if MathJax?
MathJax.Hub.Queue ["Typeset", MathJax.Hub, body[0]]
_delete: (event) =>
@trigger "comment:_delete", event

View File

@@ -27,7 +27,8 @@ if Backbone?
convertMath: ->
element = @$(".response-body")
element.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight element.text()
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element[0]]
if MathJax?
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element[0]]
edit: (event) ->
@trigger "response:edit", event

View File

@@ -12,6 +12,7 @@
tex2jax: {inlineMath: [ ['$','$'], ["\\(","\\)"]],
displayMath: [ ['$$','$$'], ["\\[","\\]"]]}
});
HUB = MathJax.Hub
</script>
%else:
<script type="text/x-mathjax-config">
@@ -27,6 +28,7 @@
]
}
});
HUB = MathJax.Hub
</script>
%endif

View File

@@ -2,11 +2,6 @@
$ ->
if not MathJax?
return
HUB = MathJax.Hub
class MathJaxProcessor
MATHSPLIT = /// (
@@ -116,10 +111,11 @@ $ ->
Markdown.getMathCompatibleConverter = (postProcessor) ->
postProcessor ||= ((text) -> text)
converter = Markdown.getSanitizingConverter()
processor = new MathJaxProcessor()
converter.hooks.chain "preConversion", MathJaxProcessor.removeMathWrapper(processor)
converter.hooks.chain "postConversion", (text) ->
postProcessor(MathJaxProcessor.replaceMathWrapper(processor)(text))
if MathJax?
processor = new MathJaxProcessor()
converter.hooks.chain "preConversion", MathJaxProcessor.removeMathWrapper(processor)
converter.hooks.chain "postConversion", (text) ->
postProcessor(MathJaxProcessor.replaceMathWrapper(processor)(text))
converter
Markdown.makeWmdEditor = (elem, appended_id, imageUploadUrl, postProcessor) ->

View File

@@ -57,7 +57,7 @@ class @MathJaxDelayRenderer
@$buffer.html(text)
curTime = getTime()
@elapsedTime = curTime - prevTime
if MathJax
if MathJax?
prevTime = getTime()
@mathjaxRunning = true
MathJax.Hub.Queue ["Typeset", MathJax.Hub, @$buffer.attr("id")], =>