Skip to content

Commit

Permalink
escape first char as necessary (fixes #9)
Browse files Browse the repository at this point in the history
* escape `-` at start of inline code with `\-`
  • Loading branch information
guppy0130 committed Jul 13, 2021
1 parent 0232a36 commit d976901
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/renderer/jira.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ fn make_escape_list() -> HashMap<String, String> {
sub_map.insert(key.to_string(), value.to_string());
}

// we may not need to escape all; view [JiraWriter::write_escaped()]
add_escape(&mut escape_map, "{", "&#123;");
add_escape(&mut escape_map, "}", "&#125;");
add_escape(&mut escape_map, "*", "\\*");
Expand Down Expand Up @@ -201,6 +202,14 @@ where
for (key, value) in self.escape_map.iter() {
r = r.replace(key, value);
}
// if these characters are first, they break rendering, but it doesn't matter if they show
// up later, so you only need to replace the first!
match r.chars().nth(0).unwrap() {
'-' => {
r.replace_range(0..1, "\\-");
}
_ => (),
}
self.write(&r)
}

Expand Down Expand Up @@ -532,6 +541,13 @@ fn test_nested_markup_inline_code() {
"\n{{inline code with an asterisk \\*}} like {{rm -rf ./\\*.extension}}\n",
String::from_utf8(output).unwrap()
);
let input = "a flag like `-r`";
let mut output = Vec::new();
assert!(write_jira(&mut output, Parser::new_ext(input, Options::all()), 0).is_ok());
assert_eq!(
"\na flag like {{\\-r}}\n",
String::from_utf8(output).unwrap()
);
}

#[test]
Expand Down

0 comments on commit d976901

Please sign in to comment.