Skip to content

Commit

Permalink
Merge pull request integrations#15 from integrations/escaping
Browse files Browse the repository at this point in the history
Fix unnecessary escaping
  • Loading branch information
bkeepers committed Mar 30, 2018
2 parents 4115f80 + eccf1a7 commit 60fbcaf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ const service = new TurnDown({
linkStyle: 'slack'
})

// override escaping
// https://api.slack.com/docs/message-formatting#how_to_escape_characters
service.escape = (string) => (
string.replace('&', '&')
.replace('<', '&lt;')
.replace('>', '&gt;')
)

service.use(strikethrough)
service.use(taskListItems)

Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/a.mrkdwn
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<a href="https://example.com">Hello</a>
<a href="https://example.com">Upcoming_Distrust_Actions wiki</a>
====
<https://example.com|Hello>
<https://example.com|Hello> <https://example.com|Upcoming_Distrust_Actions wiki>
9 changes: 9 additions & 0 deletions test/fixtures/escaping.mrkdwn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h2>1. First things first</h2>
<p>[Effort: M, Impact: L]</p>
<p>&lt;hello&gt;</p>
====
*1. First things first*

[Effort: M, Impact: L]

&lt;hello&gt;

0 comments on commit 60fbcaf

Please sign in to comment.