Refactoring markdowncode a bit and fixes messages showing unescaped when just sent

pull/7379/head
Gabriel Delavald 9 years ago
parent e40379b25c
commit d25a515f9e
  1. 31
      packages/rocketchat-markdown/markdowncode.js
  2. 3
      packages/rocketchat-mentions/Mentions.js
  3. 6
      packages/rocketchat-ui-message/client/renderMessageBody.js

@ -60,29 +60,16 @@ class MarkdownCode {
if (codeMatch != null) {
// Process highlight if this part is code
let code;
let lang;
let result;
const singleLine = codeMatch[0].indexOf('\n') === -1;
if (singleLine) {
lang = '';
code = _.unescapeHTML(codeMatch[1] + codeMatch[2]);
} else {
lang = codeMatch[1];
code = _.unescapeHTML(codeMatch[2]);
}
if (s.trim(lang) === '') {
lang = '';
}
if (!Array.from(hljs.listLanguages()).includes(s.trim(lang))) {
result = hljs.highlightAuto((lang + code));
} else {
result = hljs.highlight(s.trim(lang), code);
}
const lang = !singleLine && Array.from(hljs.listLanguages()).includes(s.trim(codeMatch[1])) ? s.trim(codeMatch[1]) : '';
const code =
singleLine ?
_.unescapeHTML(codeMatch[1]) :
lang === '' ?
_.unescapeHTML(codeMatch[1] + codeMatch[2]) :
_.unescapeHTML(codeMatch[2]);
const result = lang === '' ? hljs.highlightAuto((lang + code)) : hljs.highlight(lang, code);
const token = `=!=${ Random.id() }=!=`;
message.tokens.push({

@ -50,7 +50,8 @@ export default class {
});
}
replaceChannels(str, message) {
return str.replace(this.channelMentionRegex, (match, name) => {
//since apostrophe escaped contains # we need to unescape it
return str.replace(/'/g, '\'').replace(this.channelMentionRegex, (match, name) => {
if (message.temp == null && _.findWhere(message.channels, {name}) == null) {
return match;
}

@ -1,10 +1,8 @@
/* global renderMessageBody:true */
renderMessageBody = function(msg) {
msg.html = msg.msg;
if (_.trim(msg.html) !== '') {
msg.html = _.escapeHTML(msg.html);
if (_.trim(msg.msg) !== '') {
msg.html = _.escapeHTML(msg.msg);
}
const message = RocketChat.callbacks.run('renderMessage', msg);

Loading…
Cancel
Save