Skip to content

Commit

Permalink
fix non escaping '\' not being rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
Canop committed Sep 20, 2022
1 parent 09b34e8 commit 7e65d75
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "minimad"
version = "0.9.0"
version = "0.9.1"
authors = ["dystroy <denys.seguret@gmail.com>"]
repository = "https://github.com/Canop/minimad"
description = "light Markdown parser"
Expand Down
29 changes: 25 additions & 4 deletions src/line_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,18 @@ impl<'s> LineParser<'s> {
#[cfg(feature="escaping")]
if after_antislash {
after_antislash = false;
continue;
match char {
'*' | '~' | '|' | '`' => {
self.close_compound(idx-1, 1, &mut compounds);
continue;
}
'\\' => {
self.close_compound(idx, 1, &mut compounds);
continue;
}
_ => {} // we don't escape at all normal chars
}
} else if char=='\\' {
self.close_compound(idx, 1, &mut compounds);
after_antislash = true;
continue;
}
Expand Down Expand Up @@ -378,6 +387,7 @@ mod tests {
);
}

#[cfg(feature="escaping")]
#[test]
fn escapes() {
assert_eq!(
Expand All @@ -390,6 +400,17 @@ mod tests {
Compound::raw_str("* here"),
])
);
// check we're not removing chars with the escaping, and that
// we're not losing the '\' when it's not escaping something
// (only markdown modifiers can be escaped)
assert_eq!(
Line::from(
"a\\bc\\"
),
Line::new_paragraph(vec![
Compound::raw_str("a\\bc\\"),
])
);
assert_eq!(
Line::from(
"*italic\\*and\\*still\\*italic*"
Expand All @@ -406,8 +427,8 @@ mod tests {
Line::new_paragraph(vec![
Compound::raw_str("*"),
Compound::raw_str("Italic then ").italic(),
Compound::raw_str("bold").bold().italic(),
Compound::raw_str("\\ and ").bold().italic(),
Compound::raw_str("bold\\").bold().italic(),
Compound::raw_str(" and ").bold().italic(),
Compound::raw_str("`italic ").bold().italic(),
Compound::raw_str("and some *code*").bold().italic().code(),
Compound::raw_str(" and italic*").italic(),
Expand Down
11 changes: 11 additions & 0 deletions src/template/inline_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ impl<'a> InlineTemplate<'a> {
/// * arguments can be omited, repeated, or given in arbitrary order
/// * no support for fmt parameters or arguments other than `&str`
///
/// Example:
/// ```
/// use minimad::*;
///
/// let composite = mad_inline!(
/// "**$0 formula:** *$1*", // the markdown template, interpreted only once
/// "Disk", // fills $0
/// "2*π*r", // fills $1. Note that the stars don't mess the markdown
/// );
/// ```
///
#[macro_export]
macro_rules! mad_inline {
( $md: literal $(, $value: expr )* $(,)? ) => {{
Expand Down

0 comments on commit 7e65d75

Please sign in to comment.