Crates.io | discord-md |
lib.rs | discord-md |
version | 3.0.0 |
source | src |
created_at | 2021-09-03 10:12:32.888269 |
updated_at | 2023-11-12 14:56:14.184974 |
description | Parser and generator for Discord's markdown |
homepage | |
repository | https://github.com/ciffelia/discord-md |
max_upload_size | |
id | 446380 |
size | 96,006 |
Parser and generator for Discord's markdown, written in Rust
use discord_md::ast::*;
use discord_md::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
);
}
use discord_md::ast::MarkdownDocument;
use discord_md::builder::*;
fn main() {
let ast = MarkdownDocument::new(vec![
plain("generating "),
one_line_code("markdown"),
plain(" is "),
underline(vec![
bold("easy"),
plain(" and "),
bold("fun!"),
]),
]);
assert_eq!(
ast.to_string(),
"generating `markdown` is __**easy** and **fun!**__"
);
}
*italics*
, _italics_
)**bold**
)__underline__
)~~strikethrough~~
)||spoiler||
)`one line code`
)```sh
echo "multi line"
echo "code"
```
> block quote
> some text
Add the following to your Cargo.toml
file:
[dependencies]
discord-md = "3.0.0"
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.
>
will be treated as plain text.*italics **bold italics** italics*
, may not be parsed properly.foo_bar_baz
as emphasis, while Discord's parser does not.Licensed under either of
at your option.
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.