slackify-markdown
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "slackify-markdown", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Convert markdown into Slack-specific markdown", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
const { Compiler } = require('remark-stringify'); | ||
const { isURL } = require('./utils'); | ||
const { isURL, wrap } = require('./utils'); | ||
// fixes slack in-word formatting (e.g. hel*l*o) | ||
const zeroWidthSpace = String.fromCharCode(0x200B); | ||
const visitors = { | ||
heading(node) { | ||
// make headers to be just *strong* | ||
return `*${this.content(node)}*`; | ||
return wrap(this.content(node), '*'); | ||
}, | ||
strong(node) { | ||
return `*${this.content(node)}*`; | ||
return wrap(this.content(node), zeroWidthSpace, '*'); | ||
}, | ||
delete(node) { | ||
return `~${this.content(node)}~`; | ||
return wrap(this.content(node), zeroWidthSpace, '~'); | ||
}, | ||
emphasis(node) { | ||
return `_${this.content(node)}_`; | ||
return wrap(this.content(node), zeroWidthSpace, '_'); | ||
}, | ||
@@ -33,7 +36,11 @@ | ||
code(node) { | ||
// delete language prefix for deprecated markdown formatters (old Bitbucket Editor) | ||
const content = node.value.replace(/^#![a-z]+\n/, ''); // ```\n#!javascript\ncode block\n``` | ||
return wrap(content, '```', '\n'); | ||
}, | ||
link(node) { | ||
const text = node.title || this.content(node); | ||
const url = this.encode(node.url || '', node); | ||
if (!isURL(url)) return url; | ||
return `<${url}|${text}>`; | ||
return this.visitors.url.call(this, node, text); | ||
}, | ||
@@ -43,2 +50,6 @@ | ||
const text = node.title || node.alt; | ||
return this.visitors.url.call(this, node, text); | ||
}, | ||
url(node, text) { | ||
const url = this.encode(node.url || '', node); | ||
@@ -48,7 +59,2 @@ if (!isURL(url)) return url; | ||
}, | ||
code(node) { | ||
const fence = '```'; | ||
return `${fence}\n${node.value}\n${fence}`; | ||
}, | ||
}; | ||
@@ -55,0 +61,0 @@ |
@@ -11,2 +11,10 @@ const { URL } = require('url'); | ||
}, | ||
wrap(string, ...wrappers) { | ||
return [ | ||
...wrappers, | ||
string, | ||
...wrappers.reverse(), | ||
].join(''); | ||
}, | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15973
427