-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Markdown parser to convert Discord formatting to Minecraft (#4)
Add a Markdown parser to convert Discord formatting to Minecraft Signed-off-by: Evan Maddock <[email protected]>
- Loading branch information
1 parent
e62f01a
commit 7839de1
Showing
14 changed files
with
799 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
This is a stripped down version of the Rust crate `markdown` written by Johann Hofmann, licensed under the Apache 2.0 license. You can find the original work [here](https://github.com/johannhof/markdown.rs). The vast majority of the credit here goes to him. | ||
|
||
# Differences | ||
|
||
Since this application only deals with Discord's flavor of Markdown and Minecraft formatting, there is a lot of the original crate that isn't needed here. On top of that, there are a couple of formatting types that Discord uses that aren't present in the upstream library. | ||
|
||
Only the following elements are implemented: | ||
|
||
- Blockquotes | ||
- Emphasis | ||
- Strikethrough | ||
- Strong | ||
- Underline | ||
|
||
# License | ||
|
||
All work **except** the strikethrough and underline parsers, and the Minecraft format conversion code is © Johann Hofmann. | ||
|
||
The license for the original work can be found [here](https://github.com/johannhof/markdown.rs/blob/master/LICENSE-APACHE). I really make no claims on top of that. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use super::Block; | ||
use super::Block::Blockquote; | ||
use crate::markdown::block::parse_blocks; | ||
|
||
pub fn parse_blockquote(line: &str) -> Option<Block> { | ||
if line.is_empty() || !line.starts_with("> ") { | ||
return None; | ||
} | ||
|
||
let mut content = String::new(); | ||
|
||
// Push the content of the quote after the opening `>` | ||
content.push_str(&line[2..line.len()]); | ||
|
||
Some(Blockquote(parse_blocks(&content))) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::parse_blockquote; | ||
use super::Block::Blockquote; | ||
|
||
#[test] | ||
fn finds_blockquote() { | ||
match parse_blockquote("> quote") { | ||
Some(Blockquote(_)) => (), | ||
_ => panic!(), | ||
} | ||
} | ||
|
||
#[test] | ||
fn no_false_positives() { | ||
assert_eq!(parse_blockquote(">shouldn't parse"), None); | ||
assert_eq!(parse_blockquote("shouldn't > parse"), None); | ||
} | ||
|
||
#[test] | ||
fn no_early_matching() { | ||
assert_eq!(parse_blockquote("first > quote > another blah"), None); | ||
} | ||
} |
Oops, something went wrong.