Skip to content

Commit 1959ee5

Browse files
committed
Test extract_messages with backslashes
This is part of google#105, the test demonstrates how we extract backslashes: `\` (a single backslash) in the Markdown file becomes `\\` (a backslash-escaped backslash) afterwards. This is consistent with the Commonmark spec, which says that a backslash-escaped backslash is how you can represent a backslash in the document: https://spec.commonmark.org/0.30/#backslash-escapes. However, it can lead to problems if the LaTeX preprocessor doesn’t handle `\\` in the Markdown file as a `\`.
1 parent 1480904 commit 1959ee5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

i18n-helpers/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,24 @@ The document[^1] text.
10581058
);
10591059
}
10601060

1061+
#[test]
1062+
fn extract_messages_backslashes() {
1063+
// Demonstrate how a single backslash in the Markdown becomes
1064+
// a backslash-escaped backslash when we extract the text.
1065+
// This is consistent with the CommonMark spec:
1066+
// https://spec.commonmark.org/0.30/#backslash-escapes.
1067+
// However, it causes problems for LaTeX preprocessors:
1068+
// https://github.com/google/mdbook-i18n-helpers/issues/105.
1069+
assert_extract_messages(
1070+
r#"
1071+
$$
1072+
\sum_{n=1}^{\infty} 2^{-n} = 1
1073+
$$
1074+
"#,
1075+
vec![(2, r#"$$ \\sum\_{n=1}^{\infty} 2^{-n} = 1 $$"#)],
1076+
)
1077+
}
1078+
10611079
#[test]
10621080
fn test_is_comment_skip_directive_simple() {
10631081
assert_eq!(

0 commit comments

Comments
 (0)