Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix: inline math not getting marked as unlintable
Elijah Potter9504dcc0f6e8
diff --git a/harper-core/src/language_detection.rs b/harper-core/src/language_detection.rsindex af64776d3..a1a873016 100644--- a/harper-core/src/language_detection.rs+++ b/harper-core/src/language_detection.rs@@ -6,7 +6,6 @@ pub fn is_likely_english(doc: &Document, dict: &impl Dictionary) -> bool {let mut total_words = 0;let mut valid_words = 0;let mut punctuation = 0;- let mut spaces = 0;for token in doc.tokens() {match token.kind {@@ -19,7 +18,6 @@ pub fn is_likely_english(doc: &Document, dict: &impl Dictionary) -> bool {}}TokenKind::Punctuation(_) => punctuation += 1,- TokenKind::Space(n) => spaces += n,_ => ()}}@@ -27,13 +25,8 @@ pub fn is_likely_english(doc: &Document, dict: &impl Dictionary) -> bool {dbg!(total_words);dbg!(valid_words);dbg!(punctuation);- dbg!(spaces);- if spaces > total_words * 3 {- return false;- }-- if punctuation > valid_words {+ if (punctuation as f32 * 1.25) > valid_words as f32 {return false;}diff --git a/harper-core/src/parsers/markdown.rs b/harper-core/src/parsers/markdown.rsindex 90e834969..34e5225e0 100644--- a/harper-core/src/parsers/markdown.rs+++ b/harper-core/src/parsers/markdown.rs@@ -66,7 +66,9 @@ impl Parser for Markdown {pulldown_cmark::Event::End(_) => {stack.pop();}- pulldown_cmark::Event::Code(code) => {+ pulldown_cmark::Event::InlineMath(code)+ | pulldown_cmark::Event::DisplayMath(code)+ | pulldown_cmark::Event::Code(code) => {let chunk_len = code.chars().count();tokens.push(Token {@@ -133,6 +135,7 @@ impl Parser for Markdown {mod tests {use super::super::StrParser;use super::Markdown;+ use crate::{Punctuation, TokenKind};#[test]fn survives_emojis() {@@ -153,4 +156,22 @@ mod tests {assert_ne!(tokens.len(), 0);assert!(!tokens.last().unwrap().kind.is_newline());}++ #[test]+ fn math_becomes_unlintable() {+ let source = r#"$\Katex$ $\text{is}$ $\text{great}$."#;++ let tokens = Markdown.parse_str(source);+ assert_eq!(+ tokens.iter().map(|t| t.kind).collect::<Vec<_>>(),+ vec![+ TokenKind::Unlintable,+ TokenKind::Space(1),+ TokenKind::Unlintable,+ TokenKind::Space(1),+ TokenKind::Unlintable,+ TokenKind::Punctuation(Punctuation::Period)+ ]+ )+ }}