Nonstick Pancake Maker

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

    1.2.3 • Public • Published

    HTML Translator

    Publish NPM

    Translate HTML5 to Discord flavored markdown

    This is a modified version of @Wakeful-Cloud/html-translator intended for myself.

    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.

    Install

    npm i @apteryxxyz/html-translator

    DownloadsWeekly Downloads

    64

    Version

    1.2.3

    License

    MIT

    Unpacked Size

    340 kB

    Total Files

    53

    Last publish

    Collaborators

    • apteryxxyz