Commit 59cc23ce authored by RawKStar77's avatar RawKStar77

Add support for additional \\( block math \\)

Clean up code, add comments, and add CSS to hide MathJax rendered math in a collapsed annotation.
parent f27d8ced
...@@ -306,7 +306,8 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc ...@@ -306,7 +306,8 @@ 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 ''
convert = $filter('converter') convert = $filter('converter')
re = /(?:\$\$)|(?:\\\(|\\\))/g re = /(?:\$\$)|(?:\\?\\\(|\\?\\\))/g
htmlElement = /<[a-z]+>/
startMath = 0 startMath = 0
endMath = 0 endMath = 0
...@@ -318,7 +319,7 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc ...@@ -318,7 +319,7 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc
for match in indexes for match in indexes
if startMath > endMath if startMath > endMath
endMath = match.index + 2 endMath = match.index + match.toString().length
try try
parts.push katex.renderToString($sanitize value.substring(startMath, match.index)) parts.push katex.renderToString($sanitize value.substring(startMath, match.index))
catch catch
...@@ -326,7 +327,7 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc ...@@ -326,7 +327,7 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc
MathJaxFallback = true MathJaxFallback = true
parts.push $sanitize value.substring(startMath, match.index) parts.push $sanitize value.substring(startMath, match.index)
else else
startMath = match.index + 2 startMath = match.index + match.toString().length
# Inline math needs to fall inline, which can be tricky considering the markdown # Inline math needs to fall inline, which can be tricky considering the markdown
# converter will take the part that comes before a peice of math and surround it # converter will take the part that comes before a peice of math and surround it
# with markup: <p>Here is some inline math: </p>\(2 + 2 = 4\) # with markup: <p>Here is some inline math: </p>\(2 + 2 = 4\)
...@@ -336,19 +337,23 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc ...@@ -336,19 +337,23 @@ markdown = ['$filter', '$sanitize', '$sce', '$timeout', ($filter, $sanitize, $sc
# closing <p> tags since this is meant to be one paragraph. # closing <p> tags since this is meant to be one paragraph.
if i - 1 >= 0 and indexes[i - 1].toString() == "\\)" if i - 1 >= 0 and indexes[i - 1].toString() == "\\)"
markdown = $sanitize convert value.substring(endMath, match.index) markdown = $sanitize convert value.substring(endMath, match.index)
parts.push markdown.substring(3, markdown.length - 4) tagLength = htmlElement.exec(markdown)[0].length
parts.push markdown.substring(tagLength, markdown.length - (tagLength + 1))
# Text preceeds a case of inline math. We must remove the ending </p> tag # Text preceeds a case of inline math. We must remove the ending </p> tag
# so that the math is inline. # so that the math is inline.
else else
markdown = $sanitize convert value.substring(endMath, match.index) markdown = $sanitize convert value.substring(endMath, match.index)
parts.push markdown.substring(0, markdown.length - 4) tagLength = htmlElement.exec(markdown)[0].length
parts.push markdown.substring(0, markdown.length - (tagLength + 1))
# Text follows a case of inline math, we must remove opening <p> tag. # Text follows a case of inline math, we must remove opening <p> tag.
else if i - 1 >= 0 and indexes[i - 1].toString() == "\\)" else if i - 1 >= 0 and indexes[i - 1].toString() == "\\)"
markdown = $sanitize convert value.substring(endMath, match.index) markdown = $sanitize convert value.substring(endMath, match.index)
parts.push markdown.substring(3, markdown.length) tagLength = htmlElement.exec(markdown)[0].length
parts.push markdown.substring(tagLength, markdown.length)
else # Block Math or no math. else # Block Math or no math.
parts.push $sanitize convert value.substring(endMath, match.index) parts.push $sanitize convert value.substring(endMath, match.index)
i++ i++
scope.rendered = $sce.trustAsHtml parts.join('') scope.rendered = $sce.trustAsHtml parts.join('')
if MathJaxFallback if MathJaxFallback
$timeout (-> MathJax?.Hub.Queue ['Typeset', MathJax.Hub, output]), 0, false $timeout (-> MathJax?.Hub.Queue ['Typeset', MathJax.Hub, output]), 0, false
......
...@@ -86,6 +86,27 @@ $threadexp-width: .6em; ...@@ -86,6 +86,27 @@ $threadexp-width: .6em;
.thread &, .thread &,
.thread & .annotation-header, .thread & .annotation-header,
.thread & .annotation-section { margin: 0 } .thread & .annotation-section { margin: 0 }
.styled-text > .MathJax_Display {
display: none !important;
}
.styled-text > *:nth-child(2) {
&.MathJax_Display {
display: block !important;
}
}
.styled-text > * { display: none }
.styled-text > *:first-child {
display: block;
margin: 0;
overflow: hidden;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
white-space: nowrap;
}
.thread & footer { display: none } .thread & footer { display: none }
} }
} }
......
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