Skip to content
Snippets Groups Projects
Commit 11c9b715 authored by Itamar Schen's avatar Itamar Schen
Browse files

Allow katex to work with $...$ and $$...$$

parent a2f73cca
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,7 @@ class Highlight
else
result = hljs.highlight lang, code
token = "$#{Random.id()}$"
token = "=&=#{Random.id()}=&="
message.tokens.push
highlight: true
......
......@@ -9,8 +9,8 @@ class Katex
'\\(': { closer: '\\)', displayMode: false },
# Conflicts with message tokens syntax: $token$
#'$$' : { closer: '$$' , displayMode: true },
#'$' : { closer: '$' , displayMode: false },
'$$' : { closer: '$$' , displayMode: true },
'$' : { closer: '$' , displayMode: false },
}
# Searches for the first opening delimiter in the string
......@@ -80,7 +80,7 @@ class Katex
latex = str.substr match.inner.start, match.inner.length()
latex = s.unescapeHTML latex
return { before: before, latex : latex, after : after }
return { before: before, latex : latex, after : after }
# Takes a latex math string and the desired display mode and renders it
# to HTML using the KaTeX library
......
......@@ -19,7 +19,7 @@ class Markdown
else
message.tokens ?= []
msg = msg.replace /(^|&gt;|[ >_*~])\`([^`\r\n]+)\`([<_*~]|\B|\b|$)/gm, (match, p1, p2, p3, offset, text) ->
token = "$#{Random.id()}$"
token = "=&=#{Random.id()}=&="
message.tokens.push
token: token
......
......@@ -13,10 +13,8 @@ renderMessageBody = function(msg) {
message = RocketChat.callbacks.run('renderMessage', msg);
if (message.tokens && message.tokens.length > 0) {
for (var i = 0, len = message.tokens.length; i < len; i++) {
let token = message.tokens[i];
token.text = token.text.replace(/([^\$])(\$[^\$])/gm, '$1$$$2');
message.html = message.html.replace(token.token, token.text);
for(let {token, text} of message.tokens){
message.html = message.html.replace(token, () => text); // Uses lambda so doesn't need to escape $
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment