Commit 7b08a9e8 authored by RawKStar77's avatar RawKStar77

Implement try/catch in the render function

parent cd5fa8ba
...@@ -264,7 +264,6 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc ...@@ -264,7 +264,6 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc
input.style.height = output.style.height input.style.height = output.style.height
$timeout -> inputEl.focus() $timeout -> inputEl.focus()
MathJaxFallback = false
renderMath = (textToCheck) -> renderMath = (textToCheck) ->
# Parses text for math as denoted by '$$' # Parses text for math as denoted by '$$'
i = 0 i = 0
...@@ -278,14 +277,7 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc ...@@ -278,14 +277,7 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc
endMath = i endMath = i
i++ i++
if startMath != null and endMath != null if startMath != null and endMath != null
try math = katex.renderToString(textToCheck.substring(startMath, endMath))
math = katex.renderToString(textToCheck.substring(startMath, endMath))
catch
# KaTex does not have full math support. In the case that we come across math we
# can't render, we load MathJax and render the Math with MathJax.
MathJaxFallback = true
loadMathJax()
return textToCheck
textToCheck = ( textToCheck = (
textToCheck.substring(0, (startMath - 2)) + math + textToCheck.substring(0, (startMath - 2)) + math +
textToCheck.substring((endMath + 2)) textToCheck.substring((endMath + 2))
...@@ -301,10 +293,14 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc ...@@ -301,10 +293,14 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc
inputEl.val (ctrl.$viewValue or '') inputEl.val (ctrl.$viewValue or '')
value = ctrl.$viewValue or '' value = ctrl.$viewValue or ''
markdown = $sanitize $filter('converter') value markdown = $sanitize $filter('converter') value
rendered = renderMath markdown try
scope.rendered = $sce.trustAsHtml rendered rendered = renderMath markdown
if MathJaxFallback catch
if !MathJax?
loadMathJax()
rendered = markdown
MathJax?.Hub.Queue(["Typeset", MathJax.Hub, output]) MathJax?.Hub.Queue(["Typeset", MathJax.Hub, output])
scope.rendered = $sce.trustAsHtml rendered
# React to the changes to the input # React to the changes to the input
inputEl.bind 'blur change keyup', -> inputEl.bind 'blur change keyup', ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment