fork of https://gitlab.com/mx-puppet/discord/discord-markdown to get around gitlab http errors
Find a file
2022-05-02 00:58:20 +02:00
.yarn Prepare for gitlab 2022-05-02 00:48:49 +02:00
test add emoji parsing for bots 2020-02-23 16:15:13 +01:00
.eslintrc.json 2.1.0 2018-12-14 18:49:28 -06:00
.gitignore Prepare for gitlab 2022-05-02 00:48:49 +02:00
.travis.yml Release 2.3.0 2020-02-04 13:03:13 -06:00
.yarnrc.yml Use correct Project ID 2022-05-02 00:58:20 +02:00
CHANGELOG.md 2.3.1 - Fix unescaped HTML in code blocks 2020-02-20 11:54:18 -06:00
index.js Add '+' character to regex for codeblock language 2020-04-05 14:11:12 +10:00
jest.config.js Prepare for gitlab 2022-05-02 00:48:49 +02:00
LICENSE Initial commit 2017-11-11 14:26:04 -06:00
package-lock.json audit fix 2021-06-24 11:24:03 +02:00
package.json Prepare for gitlab 2022-05-02 00:48:49 +02:00
README.md add emoji parsing for bots 2020-02-23 16:15:13 +01:00
yarn.lock Prepare for gitlab 2022-05-02 00:48:49 +02:00

discord-markdown

A markdown parser for Discord messages.

Using

yarn add discord-markdown
npm i discord-markdown
const { parser, htmlOutput, toHTML } = require('discord-markdown');

console.log(toHTML('This **is** a __test__'));
// => This <strong>is</strong> a <u>test</u>

Fenced codeblocks will include highlight.js tags and classes.

Options

const { toHTML } = require('discord-markdown');
toHTML('This **is** a __test__', options);

options is an object with the following properties (all are optional):

  • embed: Boolean (default: false), if it should parse embed contents (rules are slightly different)
  • isBot: Boolean (default: false), if the sender is a bot
  • escapeHTML: Boolean (default: true), if it should escape HTML
  • discordOnly: Boolean (default: false), if it should only parse the discord-specific stuff
  • discordCallback: Object, callbacks used for discord parsing. Each receive an object with different properties, and are expected to return an HTML escaped string
    • user: (id: Number) User mentions "@someperson"
    • channel: (id: Number) Channel mentions "#somechannel"
    • role: (id: Number) Role mentions "@somerole"
    • emoji: (animated: Boolean, name: String, id: Number) emojis ":emote":
    • everyone: () Everyone mention "@everyone"
    • here: () Here mention "@here"
    • spoiler: (content: String) Customize how the spoiler HTML will look like
  • cssModuleNames: Object, maps CSS class names to CSS module class names
  • noExtraSpanTags: Boolean (default: false), if it is true it disables the adding of extra <span>-tags around discord stuffs
  • noHighlightCode: Boolean (default: false), if it is true it disables rendering with highlight.js

Mention and Emoji Handling

Using the discordCallback option you can define custom functions to handle parsing mention and emoji content. You can use these to turn IDs into names.

Example:

const { toHTML } = require('discord-markdown');
toHTML('This is a mention for <@95286900801146880>', {
	discordCallback: {
		user: node => '@' + users[node.id];
	}
}); // -> This is a mention for @Brussell

Contributing

Find an inconsistency? File an issue or submit a pull request with the fix and updated test(s).