Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Wakeful-Cloud/html-translator
Translate HTML5 to Discord flavored markdown
https://github.com/Wakeful-Cloud/html-translator
discord discord-flavored-markdown discordjs html html-to-markdown html-to-md html5 markdown
Last synced: 17 days ago
JSON representation
Translate HTML5 to Discord flavored markdown
- Host: GitHub
- URL: https://github.com/Wakeful-Cloud/html-translator
- Owner: Wakeful-Cloud
- License: mit
- Created: 2021-07-09T08:19:25.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-17T22:41:56.000Z (over 2 years ago)
- Last Synced: 2024-11-07T13:47:49.695Z (about 1 month ago)
- Topics: discord, discord-flavored-markdown, discordjs, html, html-to-markdown, html-to-md, html5, markdown
- Language: TypeScript
- Homepage:
- Size: 271 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- project-awesome - Wakeful-Cloud/html-translator - Translate HTML5 to Discord flavored markdown (TypeScript)
README
# HTML Translator
[![Publish](https://img.shields.io/github/workflow/status/wakeful-cloud/html-translator/Publish?label=Publish&style=flat-square)](https://github.com/wakeful-cloud/html-translator/actions/Publish)
[![NPM](https://img.shields.io/npm/v/@wakeful-cloud/html-translator?label=NPM&style=flat-square)](https://npm.im/@wakeful-cloud/html-translator)Translate [HTML5](https://developer.mozilla.org/en-US/docs/Glossary/HTML5) to [Discord flavored markdown](https://support.discord.com/hc/en-us/articles/210298617)
## 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:
```bash
npm i @wakeful-cloud/html-translator
```
2. Add the below to your Discord bot:
```javascript
//Import
import translate from '@wakeful-cloud/html-translator'; //ES Modules
const translate = require('@wakeful-cloud/html-translator'); //CommonJS//Translate
const html = 'Bold text followed with italicized text.';
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](src/test.html) and [src/test.txt](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](https://github.com/cure53/DOMPurify) to sanitize HTML prior to calling
this package.