New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

revolt-markdown

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

revolt-markdown

A markdown parser for Revolt messages

  • 1.0.8
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

revolt-markdown

A markdown parser for Revolt messages.

This package is a fork of discord-markdown by odiffey, itself a fork of discord-markdown by brussell98.

Using

npm install revolt-markdown
yarn add revolt-markdown

For browser use, import revolt-markdown/dist/revolt-markdown.umd.js

import { parser, htmlOutput, toHTML } from 'revolt-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

import { toHTML } from 'revolt-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)
  • escapeHTML: Boolean (default: true), if it should escape HTML
  • revoltOnly: Boolean (default: false), if it should only parse the Revolt-specific stuff
  • emojiToUnicode: Boolean (default: true), if the default emojis should be converted to unicode
  • revoltCallback: Object, callbacks used for discord parsing. Each (except spoilerAttrib) receive an object with different properties, and (except emoji and tex) are expected to return an HTML escaped string
    • user: (id: String) User mentions "@someperson"
    • channel: (id: String) Channel mentions "#somechannel"
    • emoji: (id: String) Emoji mentions ":someemoji:". Expects a list of attributes for the img tag
    • tex: (content": String) TeX code. Expects a list of attributes for the span tag
    • timestamp: (timestamp: Number, style: String|undefined) Relative timestamp reference "<t:sometimestamp:somestyle>"
    • spoilerAttrib: object of HTML attributes for the spoiler span. Default is { class: 'd-spoiler' }
  • cssModuleNames: Object, maps CSS class names to CSS module class names

Mention and Emoji Handling

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

Example:

import { toHTML } from 'revolt-markdown';
toHTML('This is a mention for <@01FEEPCNQBZC7848B169BSYK39>', {
	revoltCallback: {
		user: node => '@' + users[node.id];
	}
}); // -> This is a mention for @Austin Huang

Customizing

It is possible to change the rules used by revolt-markdown. Take a look at the code to see how to create your own modified rule set.

Contributing

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

Keywords

FAQs

Package last updated on 17 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc