diff options
Diffstat (limited to 'src/logbag.rs')
-rw-r--r-- | src/logbag.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/logbag.rs b/src/logbag.rs index f461007..b08098a 100644 --- a/src/logbag.rs +++ b/src/logbag.rs @@ -52,6 +52,14 @@ impl LogBag { input.parse().ok() } + pub fn parse_markdown(input: &str) -> Option<LogBag> { + let plain = input + .split('\n') + .map(|line| line.trim_matches('*')) + .join("\n"); + LogBag::parse_plain(&plain) + } + /// Renders the contents of this [`LogBag`] as plain text. /// /// The output of this can be fed back into [`LogBag::parse_plain`] to round-trip. @@ -179,6 +187,29 @@ line 2" } #[test] + fn parse_markdown() { + let mut logbag = LogBag::new(); + logbag.insert("cat 1", "line 1".to_string()); + logbag.insert("cat 1", "line 2".to_string()); + logbag.insert("cat 2", "line 1".to_string()); + logbag.insert("cat 2", "line 2".to_string()); + + assert_eq!( + LogBag::parse_markdown( + "\ +**cat 1** +line 1 +line 2 + +**cat 2** +line 1 +line 2" + ), + Some(logbag) + ); + } + + #[test] fn render_plain_single() { let mut logbag = LogBag::new(); logbag.insert("category", "line 1".to_string()); |