Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slackify-markdown

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slackify-markdown - npm Package Compare versions

Comparing version 3.1.0 to 4.0.0

2

index.d.ts
declare module "slackify-markdown" {
function slackify(markdown: string): string;
function slackify(markdown: string, parseOption?: any): string;
export = slackify;
}
{
"name": "slackify-markdown",
"version": "3.1.0",
"version": "4.0.0",
"description": "Convert markdown into Slack-specific markdown",

@@ -37,4 +37,6 @@ "license": "MIT",

"dependencies": {
"remark-parse": "^8.0.2",
"remark-stringify": "^8.0.0",
"mdast-util-to-markdown": "^0.6.2",
"remark-gfm": "^1.0.0",
"remark-parse": "^9.0.0",
"remark-stringify": "^9.0.1",
"unified": "^9.0.0"

@@ -41,0 +43,0 @@ },

# Slackify-Markdown
[![Build Status](https://travis-ci.org/jsarafajr/slackify-markdown.svg?branch=master)](https://travis-ci.org/jsarafajr/slackify-markdown)
![Build Status](https://github.com/jsarafajr/slackify-markdown/workflows/Build%20CI/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/jsarafajr/slackify-markdown/branch/master/graph/badge.svg)](https://codecov.io/gh/jsarafajr/slackify-markdown) [![Known Vulnerabilities](https://snyk.io/test/github/jsarafajr/slackify-markdown/badge.svg)](https://snyk.io/test/github/jsarafajr/slackify-markdown)

@@ -49,6 +49,3 @@

### Copyright and License
Copyright Yevhenii Baraniuk, 2019
[MIT Licence](LICENSE)

@@ -0,9 +1,14 @@

const gfm = require('remark-gfm');
const parse = require('remark-parse');
const stringify = require('remark-stringify');
const unified = require('unified');
const parse = require('remark-parse');
const slackify = require('./slackify');
const slackifyOptions = require('./slackify');
module.exports = (markdown, options) => unified()
.use(parse, options)
.use(slackify)
// Delete node is defined in GFM
// https://github.com/syntax-tree/mdast/blob/main/readme.md#gfm
.use(gfm)
.use(stringify, slackifyOptions)
.processSync(markdown)
.toString();

@@ -1,2 +0,4 @@

const { Compiler } = require('remark-stringify');
const defaultHandlers = require('mdast-util-to-markdown/lib/handle');
const phrasing = require('mdast-util-to-markdown/lib/util/container-phrasing');
const { wrap, isURL } = require('./utils');

@@ -7,75 +9,107 @@

const visitors = {
heading(node) {
/**
* @type import('mdast-util-to-markdown').Handlers
*/
const handlers = {
heading: (node, _parent, context) => {
// make headers to be just *strong*
return wrap(this.content(node), '*');
},
const marker = '*';
strong(node) {
return wrap(this.content(node), zeroWidthSpace, '*');
const exit = context.enter('heading');
const value = phrasing(node, context, { before: marker, after: marker });
exit();
return wrap(value, marker);
},
delete(node) {
return wrap(this.content(node), zeroWidthSpace, '~');
strong: (node, _parent, context) => {
const marker = '*';
const exit = context.enter('strong');
const value = phrasing(node, context, { before: marker, after: marker });
exit();
return wrap(value, zeroWidthSpace, marker);
},
emphasis(node) {
return wrap(this.content(node), zeroWidthSpace, '_');
delete(node, _parent, context) {
const marker = '~';
const exit = context.enter('delete');
const value = phrasing(node, context, { before: marker, after: marker });
exit();
return wrap(value, zeroWidthSpace, marker);
},
list(node) {
const listItem = this.visitors.listItem.bind(this);
emphasis: (node, _parent, context) => {
const marker = '_';
return node.children.map((child, index) => {
const bullet = node.ordered
? `${node.start + index}.`
: '•';
return listItem(child, node, index, bullet);
}).join('\n');
const exit = context.enter('emphasis');
const value = phrasing(node, context, { before: marker, after: marker });
exit();
return wrap(value, zeroWidthSpace, marker);
},
code(node) {
listItem: (...args) => defaultHandlers
.listItem(...args)
.replace(/^\*/, '•'),
code(node, _parent, context) {
const exit = context.enter('code');
// delete language prefix for deprecated markdown formatters (old Bitbucket Editor)
const content = node.value.replace(/^#![a-z]+\n/, ''); // ```\n#!javascript\ncode block\n```
exit();
return wrap(content, '```', '\n');
},
link(node) {
const text = node.title || this.content(node);
return this.visitors.url.call(this, node, text);
link: (node, _parent, context) => {
const exit = context.enter('link');
const text = node.title
|| phrasing(node, context, { before: '|', after: '>' });
const url = encodeURI(node.url);
exit();
if (!isURL(url)) return url;
return text ? `<${url}|${text}>` : `<${url}>`;
},
image(node) {
image: (node, _parent, context) => {
const exit = context.enter('image');
const text = node.title || node.alt;
return this.visitors.url.call(this, node, text);
},
const url = encodeURI(node.url);
exit();
url(node, text) {
const url = this.encode(node.url || '', node);
if (!isURL(url)) return url;
return text ? `<${url}|${text}>` : `<${url}>`;
},
};
class SlackCompiler extends Compiler {
constructor(...args) {
super(...args);
this.visitors = Object.assign(this.visitors, visitors);
this.escape = this.slackEscape.bind(this);
}
slackEscape(value, node, parent) {
return value
text: (node, _parent, context) => {
const exit = context.enter('text');
// https://api.slack.com/reference/surfaces/formatting#escaping
const text = node.value
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
exit();
content(node) {
return this.all(node).join('');
}
}
// Do we need more escaping like the default handler uses?
// https://github.com/syntax-tree/mdast-util-to-markdown/blob/main/lib/handle/text.js
// https://github.com/syntax-tree/mdast-util-to-markdown/blob/main/lib/unsafe.js
return text;
},
};
module.exports = function slackify() {
this.Compiler = SlackCompiler;
/**
* @type import('remark-stringify').RemarkStringifyOptions
*/
const options = {
bullet: '*',
handlers,
};
module.exports = options;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc