discord-md

CI status crate version docs online MIT or Apache 2.0 Licenses

Parser and generator for Discord's markdown, written in Rust

Example

Parsing

```rust use discordmd::ast::*; use discordmd::parse;

fn main() { let message = "You can write italics text, *inline code*, and more!";

let ast = MarkdownDocument::new(vec![ MarkdownElement::Plain(Box::new( Plain::new("You can write ") )), MarkdownElement::ItalicsStar(Box::new( ItalicsStar::new(vec![ MarkdownElement::Plain(Box::new( Plain::new("italics text") )) ]) )), MarkdownElement::Plain(Box::new( Plain::new(", ") )), MarkdownElement::OneLineCode(Box::new( OneLineCode::new("inline code") )), MarkdownElement::Plain(Box::new( Plain::new(", and more!") )), ]);

assert_eq!( parse(message), ast ); } ```

Generating

```rust use discordmd::ast::MarkdownDocument; use discordmd::builder::*;

fn main() { let ast = MarkdownDocument::new(vec![ plain("generating "), onelinecode("markdown"), plain(" is "), underline(vec![ bold("easy"), plain(" and "), bold("fun!"), ]), ]);

asserteq!( ast.tostring(), "generating markdown is *easy* and *fun!*" ); } ```

Features

Installation

Add the following to your Cargo.toml file:

toml [dependencies] discord-md = "2.0.0-rc.1"

Documentation

Available at docs.rs

Parser limitations

The parser tries to mimic the behavior of the official Discord client's markdown parser, but it's not perfect. The following is the list of known limitations.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.