@wakeful-cloud/html-translator
v1.1.2
Published
Translate HTML5 to Discord flavored markdown
Downloads
9
Maintainers
Readme
HTML Translator
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
- Install the package:
npm i @wakeful-cloud/html-translator
- 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.