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 4.0.0 to 4.1.0

src/definitions.js

6

package.json
{
"name": "slackify-markdown",
"version": "4.0.0",
"version": "4.1.0",
"description": "Convert markdown into Slack-specific markdown",

@@ -41,3 +41,5 @@ "license": "MIT",

"remark-stringify": "^9.0.1",
"unified": "^9.0.0"
"unified": "^9.0.0",
"unist-util-remove": "^2.0.1",
"unist-util-visit": "^2.0.3"
},

@@ -44,0 +46,0 @@ "devDependencies": {

@@ -5,11 +5,21 @@ const gfm = require('remark-gfm');

const unified = require('unified');
const slackifyOptions = require('./slackify');
module.exports = (markdown, options) => unified()
.use(parse, options)
// 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();
const { collectDefinitions, removeDefinitions } = require('./definitions');
const createSlackifyOptions = require('./slackify');
module.exports = (markdown, options) => {
const definitions = {};
const slackifyOptions = createSlackifyOptions(definitions);
return unified()
.use(parse, options)
// Delete node is defined in GFM
// https://github.com/syntax-tree/mdast/blob/main/readme.md#gfm
.use(gfm)
.use(collectDefinitions, definitions)
.use(removeDefinitions)
.use(stringify, slackifyOptions)
.processSync(markdown)
.toString();
};

@@ -10,5 +10,11 @@ const defaultHandlers = require('mdast-util-to-markdown/lib/handle');

/**
* @type import('mdast-util-to-markdown').Handlers
* Creates custom `mdast-util-to-markdown` handlers that tailor the output for
* Slack Markdown.
*
* @param {Readonly<Record<string, { title: null | string, url: string }>>} definitions
* Record of `Definition`s in the Markdown document, keyed by identifier.
*
* @returns {import('mdast-util-to-markdown').Handlers}
*/
const handlers = {
const createHandlers = definitions => ({
heading: (node, _parent, context) => {

@@ -70,8 +76,8 @@ // make headers to be just *strong*

const exit = context.enter('link');
const text = node.title
|| phrasing(node, context, { before: '|', after: '>' });
const text = phrasing(node, context, { before: '|', after: '>' })
|| node.title;
const url = encodeURI(node.url);
exit();
if (!isURL(url)) return url;
if (!isURL(url)) return text || url;

@@ -81,9 +87,21 @@ return text ? `<${url}|${text}>` : `<${url}>`;

linkReference: (node, _parent, context) => {
const exit = context.enter('linkReference');
const definition = definitions[node.identifier];
const text = phrasing(node, context, { before: '|', after: '>' })
|| (definition ? definition.title : null);
exit();
if (!definition || !isURL(definition.url)) return text;
return text ? `<${definition.url}|${text}>` : `<${definition.url}>`;
},
image: (node, _parent, context) => {
const exit = context.enter('image');
const text = node.title || node.alt;
const text = node.alt || node.title;
const url = encodeURI(node.url);
exit();
if (!isURL(url)) return url;
if (!isURL(url)) return text || url;

@@ -93,2 +111,14 @@ return text ? `<${url}|${text}>` : `<${url}>`;

imageReference: (node, _parent, context) => {
const exit = context.enter('imageReference');
const definition = definitions[node.identifier];
const text = node.alt
|| (definition ? definition.title : null);
exit();
if (!definition || !isURL(definition.url)) return text;
return text ? `<${definition.url}|${text}>` : `<${definition.url}>`;
},
text: (node, _parent, context) => {

@@ -108,12 +138,18 @@ const exit = context.enter('text');

},
};
});
/**
* @type import('remark-stringify').RemarkStringifyOptions
* Creates options to be passed into a `remark-stringify` processor that tailor
* the output for Slack Markdown.
*
* @param {Readonly<Record<string, { title: null | string, url: string }>>} definitions
* Record of `Definition`s in the Markdown document, keyed by identifier.
*
* @returns {import('remark-stringify').RemarkStringifyOptions}
*/
const options = {
const createOptions = definitions => ({
bullet: '*',
handlers,
};
handlers: createHandlers(definitions),
});
module.exports = options;
module.exports = createOptions;
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