npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discord-markdown-embeds

v3.6.5

Published

This package allows you to create discord embeds from markdown.

Downloads

66

Readme

Discord Markdown Embeds

This package allows you to create discord embeds from markdown.

Install

npm i discord-markdown-embeds

Usage

import DME from 'discord-markdown-embeds';

const md = `
# Never gonna
- give you up
- let you down
- run around
- desert you
- make you cry
- say goodbye
- tell a lie
- hurt you
`;

// render directly (slow)
DME.parse(md, { ul: '-> ' });

// create template (still slow)
const template = DME.template(md);
// render template (fast)
template.render({ ul: '-> ' });

Syntax

---
content: This is yaml front matter, which is used to add things to the embeds and messages that don't fit well in the actual document, like embed color, webhook username and pfp, or message content.
author: The author and footer can be a string,
footer:
  text: or they can be an object.
  icon_url: https://leaf.moe/assets/sayuleaf.png
avatar_url: https://leaf.moe/assets/sayuleaf.png # can also be pfp or avatar
username: can also be name or nickname
color: # may also be a single value, multiple values repeat from the start if more embeds than colors are found
  - 0x442200 # this is a dark brown
  - 442200 # this is light green, because it thinks it's a decimal value instead of hexadecimal
  - '#442200' # this is dark brown again
---

# Embed Markdown

Titles and paragraphs get distributed over as little embeds as necessary.

##-in
Using `-` as title separator
##-line
makes it an inline field.

## Commands

Commands are written as follows: `{command:arg1,arg2,arg3 can have spaces too}`.
This will be executed through `options.commands.command('arg1', 'arg2', 'arg3 can have spaces too')`.
Commands may also be static values: `{user}`.
If `options.commands.user` is not a function it will be stringified and inserted directly.
Using a command in markdown when it's not defined in the options will cause an error.

## implemented:

- the above
- lists
- styling (*italics*, **bold**, __underline__ and ~~strikethrough~~)
- code blocks and inline code
- images anywhere within the document (won't render inline though)
- comments
- yaml front matter (for color, author, footer, timestamp etc)

## not going to implement:

- tables
- html syntax
- image links inside of regular links, styling, or lists

Documentation

DME.render(md: string, options?: renderOptions): embeds

parses and renders a markdown string into embeds
md: your markdown
options options for rendering embeds

DME.template(md: string): template

parses markdown into a template
md: your markdown

template

a template to quickly render the same markdown multiple times with different command values

template.render(options?: renderOptions): embeds

renders the template
options options for rendering embeds

embeds: object[]

an array of discord embed objects

embeds.messages(): object[]

divides the embeds into message objects, based on discord's restrictions (max 6000 chars / 10 embeds)

renderOptions: object

commands: an object of commands, commands can be functions or values with a .toString method
ul: a string or function, overrides the unordered list item icon ol: a string or function, overrides the ordered list item icon. If a string, the first occurrence of the character n is replaced with the item number. html: a boolean, if true, render to html instead of back to markdown. This only applies to strings inside returned objects, the object structure doesn't change.