Registry / messaging / html2slack

html2slack

JSON →
library1.9.1jsnpmunverified

A Node.js library (v1.9.1) that converts a subset of HTML to JSON formatted Slack attachments using html-minifier and fast-html-parser. It supports bold, italic, strikethrough, inline and multi-line code, quotes, links, ordered/unordered lists, and basic tables. The HTML must contain a <body> with <section> elements. Slack mrkdwn formatting is applied automatically. Release cadence is low, no major changes in recent history. Differentiator: allows reusing HTML templating for Slack bot messages.

npm install html2slack
INSTALL
IMPORT
SIG · HTML2SLACK
H
html2slack
messagingjavascriptv1.9.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
import html2slack from 'html2slack'
const html2slack = require('html2slack')
Library ships CommonJS, but default import works in ESM environments.
html2slack (CommonJS)
const html2slack = require('html2slack')
Standard CommonJS require for Node < 14 or CJS projects.
TypeScript types
import html2slack from 'html2slack'
import * as html2slack from 'html2slack'
Library does not ship TypeScript types; use a .d.ts or @types package if needed.

Demonstrates basic usage: converts an HTML snippet with a <body> containing a <section> to a Slack attachment JSON object.

const html2slack = require('html2slack'); const html = `<body> <section> <p>Hello <b>world</b>!</p> </section> </body>`; const slack = html2slack(html); console.log(JSON.stringify(slack, null, 2));
Debug
Known issues
gotchaHTML must have a <body> tag containing one or more <section> tags. Omitting these will cause parsing errors or empty output.
fix
Wrap your content in <body><section>...</section></body>.
affects: >=0.0.0
gotchaThe library uses html-minifier which may strip or modify whitespace, affecting <pre> and <textarea> content.
fix
Use <pre> or <textarea> tags specifically for whitespace-sensitive content.
affects: >=0.0.0
breakingSupport for Node < 8.0.0 is dropped in v1.0.0.
fix
Update to Node >= 8.0.0 or use an older version of the library.
affects: <1.0.0
deprecatedThe <table> tag support is experimental and <th> may cause unexpected side effects.
fix
Use only <td> within tables, avoid <th>.
affects: >=1.0.0
Errors
Common errors & fixes
html2slack is not a function
Using named import instead of default import in ESM or missing require/import.
fix
Use import html2slack from 'html2slack' or const html2slack = require('html2slack')
Unexpected token < in JSON at position 0
Trying to parse the output as JSON when html2slack returns an object already.
fix
Do not JSON.parse the result; html2slack returns a JavaScript object.
Cannot read property 'map' of undefined
The HTML input lacks a <body> or <section> tag.
fix
Ensure your HTML has a <body> with <section> inside.
Upgrade
Version history
1.9.1latest on npm
Audit
Dependencies
html-minifierrequiredUsed to minify and parse HTML input
fast-html-parserrequiredUsed to build a DOM tree from HTML
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
html2slack — npm install html2slack · libregistry