@wakeful-cloud/html-translator
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

HTML Translator

Publish NPM

Translate HTML5 to Discord flavored markdown

Features

  • Broad element support
  • Fully tested
  • Written in TypeScript
  • Thoroughly commented

Caveats

  • Ignores interactive elements (Buttons, inputs, switches, etc.)
  • Ignores CSS
  • Poor invalid HTML support
  • Provides no sanitization

Usage

  1. Install the package:
npm i @wakeful-cloud/html-translator
  1. Add the below to your Discord bot:
//Import
import translate from '@wakeful-cloud/html-translator'; //ES Modules
const translate = require('@wakeful-cloud/html-translator'); //CommonJS

//Translate
const html = '<b>Bold text</b> followed with <i>italicized text</i>.';
const {markdown, images} = translate(html); //"**Bold text** followed with *italicized text*."

//Compose the embed (With DiscordJS)
const embed = new MessageEmbed({
  title: 'Translator Test',
  description: markdown,
  color: '#005DAA'
});

//Add image (With DiscordJS)
if (images.length > 0)
{
  embed.image = {
    url: images[0].src
  };
}

//Send (With DiscordJS)
client.send(embed);

See src/test.html and src/test.txt for a more complex example.

Security

You should NOT call this package with unsanitized or untrusted HTML! This package provides absolutely no protection against any form of attack, you should use something like DOMPurify to sanitize HTML prior to calling this package.

Dependents (0)

Package Sidebar

Install

npm i @wakeful-cloud/html-translator

Weekly Downloads

6

Version

1.1.2

License

MIT

Unpacked Size

339 kB

Total Files

51

Last publish

Collaborators

  • wakeful-cloud