Skip to content

Commit

Permalink
fix weird slack escaping for _
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorunome committed Apr 25, 2020
1 parent 9a2f776 commit 4bfcba8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ const rules = {
},
}),
newline: markdown.defaultRules.newline,
escape: markdown.defaultRules.escape,
autolink: Object.assign({}, markdown.defaultRules.autolink, {
order: markdown.defaultRules.strong.order + 1,
match: markdown.inlineRegex(/^<((?:https?:\/\/|mailto:)[^|>]+)(\|([^>]*))?>/),
Expand Down Expand Up @@ -134,6 +133,19 @@ const rules = {
return htmlTag("a", output(node.content, state), { href: markdown.sanitizeUrl(node.target) }, state);
},
}),
noem: {
order: markdown.defaultRules.text.order,
match: (source) => /^\\_/.exec(source),
parse: function(capture) {
return {
type: "text",
content: "\\_",
};
},
html: function(node, output, state) {
return output(node.content, state);
},
},
em: Object.assign({}, markdown.defaultRules.em, {
match: markdown.inlineRegex(/^\b_(\S(?:\\[\s\S]|[^\\])*?\S|\S)_(?!_)/),
parse: (capture, parse) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slack-markdown",
"version": "0.0.3",
"version": "0.0.4",
"description": "A markdown parser for Slack messages",
"keywords": [
"slack",
Expand Down
5 changes: 5 additions & 0 deletions test/escape.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ it("Should not escape HTML, if the flag is set", () => {
expect(markdown.toHTML("<b>test</b>", { escapeHTML: false }))
.toBe("<b>test</b>");
});

it("Should not lose arms", () => {
expect(markdown.toHTML("¯\\_(ツ)_/¯"))
.toBe("¯\\_(ツ)_/¯");
});
4 changes: 2 additions & 2 deletions test/single.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ it("Should HTML-escape fenced code blocks", () => {
.toBe("<code>test</code><br><br><pre><code>&lt;&gt;</code></pre>");
});

it("Should escape marks", () => {
it("Should not escape marks", () => {
expect(markdown.toHTML("Code: \\`1 + 1` = 2`"))
.toBe("Code: `1 + 1<code> = 2</code>");
.toBe("Code: \\<code>1 + 1</code> = 2`");
});

it("Should do simple block quotes", () => {
Expand Down

0 comments on commit 4bfcba8

Please sign in to comment.