Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(core): don't replace non-alphanumeric characters when title-casing (#2454)

Elijah Pottera99ae2d85ca6
diff --git a/harper-core/src/title_case.rs b/harper-core/src/title_case.rs
index 736f5e001..85d4f55c9 100644
--- a/harper-core/src/title_case.rs
+++ b/harper-core/src/title_case.rs
@@ -77,7 +77,9 @@ pub fn try_make_title_case(
if let Some(correct_caps) = dict.get_correct_capitalization_of(orig_text) {
// It should match the dictionary verbatim
for (i, c) in correct_caps.iter().enumerate() {
- set_output_char(word.span.start - start_index + i, *c);
+ if c.is_alphabetic() {
+ set_output_char(word.span.start - start_index + i, *c);
+ }
}
}
};
@@ -505,4 +507,16 @@ mod tests {
"Winter Road",
);
}
+
+ #[test]
+ fn maintains_same_apostrophe_type() {
+ assert_eq!(
+ make_title_case_str(
+ "Alice’s Adventures in Wonderland",
+ &PlainEnglish,
+ &FstDictionary::curated()
+ ),
+ "Alice’s Adventures in Wonderland",
+ );
+ }
}
diff --git a/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml b/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml
index 44e28dcc0..7c2d8ba44 100644
--- a/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml
+++ b/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml
@@ -1,12 +1,3 @@
-Lint: Capitalization (127 priority)
-Message: |
- 1 | # Alice’s Adventures in Wonderland
- | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Try to use title case in headings.
-Suggest:
- - Replace with: “# Alice's Adventures in Wonderland”
-
-
-
Lint: Readability (127 priority)
Message: |
9 | Alice was beginning to get very tired of sitting by her sister on the bank, and
@@ -2094,15 +2085,6 @@ Message: |
-Lint: Capitalization (127 priority)
-Message: |
- 1668 | ## CHAPTER VIII: The Queen’s Croquet-Ground
- | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Try to use title case in headings.
-Suggest:
- - Replace with: “## CHAPTER VIII: The Queen's Croquet-Ground”
-
-
-
Lint: Readability (127 priority)
Message: |
1691 | Seven flung down his brush, and had just begun “Well, of all the unjust things—”
@@ -3818,15 +3800,6 @@ Message: |
-Lint: Capitalization (127 priority)
-Message: |
- 2745 | ## CHAPTER XII: Alice’s Evidence
- | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Try to use title case in headings.
-Suggest:
- - Replace with: “## CHAPTER XII: Alice's Evidence”
-
-
-
Lint: Readability (127 priority)
Message: |
2747 | “Here!” cried Alice, quite forgetting in the flurry of the moment how large she