Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rocket.Chat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RocketChat
Rocket.Chat
Commits
d69dc2e9
Commit
d69dc2e9
authored
9 years ago
by
Rodrigo Nascimento
Browse files
Options
Downloads
Patches
Plain Diff
Improve message pre processing
parent
4690531f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/views/app/chatMessageDashboard.coffee
+39
-13
39 additions, 13 deletions
client/views/app/chatMessageDashboard.coffee
client/views/app/chatMessageDashboard.html
+1
-1
1 addition, 1 deletion
client/views/app/chatMessageDashboard.html
with
40 additions
and
14 deletions
client/views/app/chatMessageDashboard.coffee
+
39
−
13
View file @
d69dc2e9
...
...
@@ -11,23 +11,49 @@ Template.chatMessageDashboard.helpers
isEditing
:
->
return
this
.
_id
is
Session
.
get
(
'editingMessageId'
)
autolinkerAndMentions
:
->
preProcessingMessage
:
->
msg
=
this
.
msg
msg
=
Autolinker
.
link
(
_
.
escapeHTML
(
msg
),
{
stripPrefix
:
false
,
twitter
:
false
})
# TODO Create as very last helper, is braking MD
# msg = msg.replace /\n/g, '<br/>'
# Separate text in code blocks and non code blocks
msgParts
=
msg
.
split
(
/(```.*\n[\s\S]*?\n```)/
)
for
part
,
index
in
msgParts
# Verify if this part is code
codeMatch
=
part
.
match
(
/```(.*)\n([\s\S]*?)\n```/
)
if
codeMatch
?
# Process highlight if this part is code
lang
=
codeMatch
[
1
]
code
=
codeMatch
[
2
]
if
lang
not
in
hljs
.
listLanguages
()
result
=
hljs
.
highlightAuto
code
else
result
=
hljs
.
highlight
lang
,
code
msgParts
[
index
]
=
"<pre><code class='hljs "
+
result
.
language
+
"'>"
+
result
.
value
+
"</code></pre>"
else
# Escape html and fix line breaks for non code blocks
part
=
_
.
escapeHTML
part
part
=
part
.
replace
/\n/g
,
'<br/>'
msgParts
[
index
]
=
part
# Re-mount message
msg
=
msgParts
.
join
(
''
)
# Process links in message
msg
=
Autolinker
.
link
(
msg
,
{
stripPrefix
:
false
,
twitter
:
false
})
# Process MD like for strong, italic and strike
msg
=
msg
.
replace
(
/\*([^*]+)\*/g
,
'<strong>$1</strong>'
)
msg
=
msg
.
replace
(
/\_([^_]+)\_/g
,
'<i>$1</i>'
)
msg
=
msg
.
replace
(
/\~([^_]+)\~/g
,
'<strike>$1</strike>'
)
# Highlight mentions
if
not
this
.
mentions
?
or
this
.
mentions
.
length
is
0
return
msg
mentions
=
_
.
map
this
.
mentions
,
(
mention
)
->
return
mention
.
username
or
mention
mentions
=
_
.
map
this
.
mentions
,
(
mention
)
->
return
mention
.
username
or
mention
mentions
=
mentions
.
join
(
'|'
)
msg
=
msg
.
replace
new
RegExp
(
"(?:^|
\\
s)(@(
#{
mentions
}
))(?:
\\
s|$)"
,
'g'
),
(
match
,
mention
,
username
)
->
return
match
.
replace
mention
,
"<a href=
\"\"
class=
\"
mention-link
\"
data-username=
\"
#{
username
}
\"
>
#{
mention
}
</a>"
mentions
=
mentions
.
join
(
'|'
)
msg
=
msg
.
replace
new
RegExp
(
"(?:^|
\\
s)(@(
#{
mentions
}
))(?:
\\
s|$)"
,
'g'
),
(
match
,
mention
,
username
)
->
return
match
.
replace
mention
,
"<a href=
\"\"
class=
\"
mention-link
\"
data-username=
\"
#{
username
}
\"
>
#{
mention
}
</a>"
return
msg
...
...
This diff is collapsed.
Click to expand it.
client/views/app/chatMessageDashboard.html
+
1
−
1
View file @
d69dc2e9
...
...
@@ -22,7 +22,7 @@
</div>
{{else}}
<div>
{{#
markdown}}{{#emojione}}{{autolinkerAndMentions
message}}{{/emojione}}
{{/markdown}}
{{#
emojione}}{{preProcessingMessage
message}}{{/emojione}}
</div>
{{/if}}
{{/if}}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment