slack-markdown
Advanced tools
Comparing version 0.0.1 to 0.0.2
62
index.js
@@ -37,2 +37,36 @@ const markdown = require("simple-markdown"); | ||
const rulesUniversal = { | ||
emoji: { | ||
order: markdown.defaultRules.strong.order, | ||
match: (source) => /^:(\w+):/.exec(source), | ||
parse: (capture) => { | ||
const code = capture[1]; | ||
let e = emoji.get(code); | ||
if (e === ":" + code + ":") { | ||
e = emoji.get(code + "_face"); | ||
if (e === ":" + code + "_face:") { | ||
e = ":" + code + ":"; | ||
} | ||
} | ||
return { | ||
content: e, | ||
}; | ||
}, | ||
html: (node) => { | ||
return markdown.sanitizeText(node.content); | ||
}, | ||
}, | ||
text: Object.assign({}, markdown.defaultRules.text, { | ||
match: (source) => /^[\s\S]+?(?=[^0-9A-Za-z\s\u00c0-\uffff-]|\n\n|\n|\w+:\S|$)/.exec(source), | ||
html: (node, output, state) => { | ||
const content = emoji.emojify(node.content); | ||
if (state.escapeHTML) { | ||
return markdown.sanitizeText(content); | ||
} | ||
return content; | ||
}, | ||
}), | ||
}; | ||
const rules = { | ||
@@ -116,17 +150,6 @@ blockQuote: Object.assign({}, markdown.defaultRules.blockQuote, { | ||
}), | ||
strike: Object.assign({ }, markdown.defaultRules.del, { | ||
strike: Object.assign({}, markdown.defaultRules.del, { | ||
match: markdown.inlineRegex(/^~(\S(?:\\[\s\S]|[^\\])*?\S|\S)~(?!~)/), | ||
}), | ||
inlineCode: markdown.defaultRules.inlineCode, | ||
text: Object.assign({}, markdown.defaultRules.text, { | ||
match: (source) => /^[\s\S]+?(?=[^0-9A-Za-z\s\u00c0-\uffff-]|\n\n|\n|\w+:\S|$)/.exec(source), | ||
html: (node, output, state) => { | ||
const content = emoji.emojify(node.content); | ||
if (state.escapeHTML) { | ||
return markdown.sanitizeText(content); | ||
} | ||
return content; | ||
}, | ||
}), | ||
br: Object.assign({ }, markdown.defaultRules.br, { | ||
@@ -277,17 +300,6 @@ match: markdown.anyScopeRegex(/^\n/), | ||
Object.assign(rules, rulesSlack); | ||
Object.assign(rules, rulesUniversal); | ||
const rulesSlackOnly = Object.assign({}, rulesSlack, { | ||
text: Object.assign({ }, markdown.defaultRules.text, { | ||
match: (source) => /^[\s\S]+?(?=[^0-9A-Za-z\s\u00c0-\uffff-]|\n\n|\n|\w+:\S|$)/.exec(source), | ||
html: (node, output, state) => { | ||
const content = emoji.emojify(node.content); | ||
if (state.escapeHTML) { | ||
return markdown.sanitizeText(content); | ||
} | ||
const rulesSlackOnly = Object.assign({}, rulesSlack, rulesUniversal); | ||
return content; | ||
}, | ||
}), | ||
}); | ||
const parser = markdown.parserFor(rules); | ||
@@ -294,0 +306,0 @@ const htmlOutput = markdown.htmlFor(markdown.ruleOutput(rules, "html")); |
{ | ||
"name": "slack-markdown", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A markdown parser for Slack messages", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -85,1 +85,14 @@ const markdown = require("../index"); | ||
}); | ||
it("Should emojify things", () => { | ||
expect(markdown.toHTML("blah :fox: blah")) | ||
.toBe("blah 🦊 blah"); | ||
expect(markdown.toHTML("blah :fox_face: blah")) | ||
.toBe("blah 🦊 blah"); | ||
}); | ||
it("Should leave unknown emojis alone", () => { | ||
expect(markdown.toHTML("blah :asdf: blah")) | ||
.toBe("blah :asdf: blah"); | ||
}); |
@@ -73,2 +73,2 @@ const markdown = require("../index"); | ||
.toBe("hey @user!"); | ||
}) | ||
}); |
30875
532