Registry / serialization / slack-markdown

slack-markdown

JSON →
library0.3.0jsnpmunverified

slack-markdown is a JavaScript library designed to parse Slack's specific markdown syntax, known as `mrkdwn`, and convert it into standard HTML. This is crucial for applications that need to display Slack messages outside of the Slack client, as `mrkdwn` differs significantly from CommonMark or GitHub Flavored Markdown. For instance, `mrkdwn` uses single asterisks for bold (`*bold*`) and single underscores for italic (`_italic_`), unlike typical Markdown conventions. The library handles various `mrkdwn` elements, including basic formatting, special mentions (users, channels, user groups), and date mentions, translating them into appropriate HTML tags. It is currently at version 0.3.0. Given its low version number and limited activity, the project appears to be in an abandoned state, meaning there's no ongoing development or regular release cadence. Its key differentiator is its specialized focus on precisely interpreting Slack's unique `mrkdwn` format for HTML output, rather than converting standard Markdown to `mrkdwn` or generating Slack Block Kit JSON payloads.

npm install slack-markdown
INSTALL
IMPORT
SIG · SLACK-MARKDOWN
S
slack-markdown
serializationjavascriptv0.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

toHTML
import { toHTML } from 'slack-markdown';
const toHTML = require('slack-markdown').toHTML;
While the README shows CommonJS `require`, modern TypeScript projects typically use ESM `import`. Both are functionally equivalent for this package.
toHTML (CommonJS)
const { toHTML } = require('slack-markdown');
import toHTML from 'slack-markdown';
The `toHTML` function is a named export, not a default export. Ensure named destructuring when using `require` or `import`.
Options interface (TypeScript)
import type { Options } from 'slack-markdown';
For type-only imports in TypeScript, use `import type` for clarity and bundler optimization.

Demonstrates converting Slack's `mrkdwn` to HTML with default settings and custom callbacks for special mentions.

import { toHTML } from 'slack-markdown'; // Basic conversion of Slack's mrkdwn to HTML const slackMessage1 = "Hello, *world*! This is a _test_ with ~strikethrough~."; console.log('Default conversion:'); console.log(toHTML(slackMessage1)); // Expected: Hello, <strong>world</strong>! This is a <em>test</em> with <strike>strikethrough</strike>. // Conversion with custom options, e.g., disabling HTML escaping const slackMessage2 = "<@U12345678|user> mentioned <#C02ABCDFG|channel>. Priority: <!here|here>!"; const options = { escapeHTML: false, // Be cautious with untrusted input if setting to false slackCallbacks: { user: (id, name) => `<a href="https://slack.com/team/${id}">@${name}</a>`, channel: (id, name) => `<a href="https://slack.com/archives/${id}">#${name}</a>`, atHere: (name) => `<span class="mention">@${name}</span>` } }; console.log('\nCustom callbacks conversion:'); console.log(toHTML(slackMessage2, options)); // Expected (roughly): <a href="https://slack.com/team/U12345678">@user</a> mentioned <a href="https://slack.com/archives/C02ABCDFG">#channel</a>. Priority: <span class="mention">@here</span>!
Debug
Known issues
breakingThe package is at version 0.3.0 and has seen no development since October 2021. If development were to resume or if this library is forked, future minor versions (pre-1.0.0) could introduce breaking changes without adhering to strict semantic versioning.
fix
Monitor package activity and always test thoroughly when upgrading any pre-1.0.0 library, especially if it appears to be abandoned.
affects: >=0.3.0
gotchaSlack's markdown (`mrkdwn`) differs significantly from standard Markdown (CommonMark). This library correctly parses `mrkdwn` (e.g., `*bold*` for bold, `_italic_` for italic), but developers often mistakenly expect it to parse standard Markdown syntax (e.g., `**bold**`).
fix
Ensure your input strictly adheres to Slack's `mrkdwn` syntax. If you need to convert standard Markdown to Slack's format, consider a different library like `md-to-slack` or `slack-markdown-it`.
affects: >=0.1.0
gotchaSetting the `escapeHTML` option to `false` can introduce Cross-Site Scripting (XSS) vulnerabilities if the input Slack message content is not fully trusted and sanitized beforehand. The library itself does not sanitize input when `escapeHTML` is disabled.
fix
Always keep `escapeHTML: true` (the default) when processing untrusted input. If you must set `escapeHTML: false` for specific trusted scenarios, ensure rigorous input sanitization is performed *before* passing the content to `toHTML`.
affects: >=0.1.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require` in an ECMAScript Module (ESM) context without proper transpilation or configuration.
fix
For ESM environments, use `import { toHTML } from 'slack-markdown';`. For Node.js ESM projects, ensure your `package.json` specifies `"type": "module"` or use a `.mjs` file extension.
My markdown isn't rendering correctly in Slack, e.g., **bold** shows literal asterisks.
Confusion between standard Markdown syntax (e.g., `**bold**`) and Slack's `mrkdwn` syntax (e.g., `*bold*`). This library parses `mrkdwn` *from* Slack to HTML, it does not convert standard markdown *to* `mrkdwn` to be sent to Slack.
fix
Review Slack's `mrkdwn` formatting guidelines. If you intend to send messages *to* Slack, ensure your input follows `mrkdwn` rules. If you're using this library to parse, ensure the input it receives is already in valid `mrkdwn` format.
TypeError: (0 , slack_markdown__WEBPACK_IMPORTED_MODULE_0__.toHTML) is not a function
Incorrect import syntax, typically trying to use a default import when `toHTML` is a named export.
fix
Always use named imports with destructuring: `import { toHTML } from 'slack-markdown';` (ESM) or `const { toHTML } = require('slack-markdown');` (CommonJS).
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
slack-markdown — npm install slack-markdown · libregistry