Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Improve markdown code #6650

Merged
merged 2 commits into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rocketchat-katex/katex.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Katex
message.tokens ?= []

render_func = (latex, displayMode) =>
token = "=&=#{Random.id()}=&="
token = "=!=#{Random.id()}=!="

message.tokens.push
token: token
Expand Down
34 changes: 16 additions & 18 deletions packages/rocketchat-markdown/markdown.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
# @param {Object} message - The message object
###

class Markdown
constructor: (message) ->
msg = message

if not _.isString message
if _.trim message?.html
msg = message.html
else
return message
Markdown = new class MarkdownClass
parse: (text) ->
@parseNotEscaped(_.escapeHTML(text))

parseNotEscaped: (msg) ->
schemes = RocketChat.settings.get('Markdown_SupportSchemesForLink').split(',').join('|')

# Support ![alt text](http://image url)
Expand Down Expand Up @@ -68,19 +63,22 @@ class Markdown
# Remove new-line between blockquotes.
msg = msg.replace(/<\/blockquote>\n<blockquote/gm, '</blockquote><blockquote')

if not _.isString message
message.html = msg
else
message = msg

console.log 'Markdown', message if window?.rocketDebug
console.log 'Markdown', msg if window?.rocketDebug

return message
return msg


RocketChat.Markdown = Markdown
RocketChat.callbacks.add 'renderMessage', Markdown, RocketChat.callbacks.priority.HIGH, 'markdown'

# renderMessage already did html escape
MarkdownMessage = (message) ->
if _.trim message?.html
message.html = Markdown.parseNotEscaped(message.html)

return message

RocketChat.callbacks.add 'renderMessage', MarkdownMessage, RocketChat.callbacks.priority.HIGH, 'markdown'

if Meteor.isClient
Blaze.registerHelper 'RocketChatMarkdown', (text) ->
return RocketChat.Markdown _.escapeHTML text
return Markdown.parse text
4 changes: 2 additions & 2 deletions packages/rocketchat-markdown/markdowncode.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MarkdownCode
@handle_inlinecode: (message) ->
# Support `text`
message.html = message.html.replace /(^|&gt;|[ >_*~])\`([^`\r\n]+)\`([<_*~]|\B|\b|$)/gm, (match, p1, p2, p3, offset, text) ->
token = "=&=#{Random.id()}=&="
token = "=!=#{Random.id()}=!="

message.tokens.push
token: token
Expand Down Expand Up @@ -67,7 +67,7 @@ class MarkdownCode
else
result = hljs.highlight s.trim(lang), code

token = "=&=#{Random.id()}=&="
token = "=!=#{Random.id()}=!="

message.tokens.push
highlight: true
Expand Down
6 changes: 3 additions & 3 deletions packages/rocketchat-ui-message/client/message.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ Template.message.onCreated ->
msg = renderMessageBody msg

if isSystemMessage
return RocketChat.Markdown msg
else
return msg
msg.html = RocketChat.Markdown.parse msg.html

return msg

Template.message.onViewRendered = (context) ->
view = this
Expand Down