diff --git a/core/src/doc.rs b/core/src/doc.rs index 5bd3fbb..94b883d 100644 --- a/core/src/doc.rs +++ b/core/src/doc.rs @@ -37,10 +37,16 @@ pub fn classify_line(index: usize, raw: &str) -> ClassifiedLine { fn is_cordial(line: &str) -> bool { if line.starts_with("let ") { - return true; + let rest = &line[4..]; + if let Some(eq_pos) = rest.find('=') { + let name = rest[..eq_pos].trim(); + if is_ident(name) { + return true; + } + } + return false; } - // variable assignment: identifier = expr (but not ==) if let Some(eq_pos) = line.find('=') { if eq_pos > 0 { let before = &line[..eq_pos]; @@ -158,6 +164,18 @@ mod tests { assert_eq!(c.kind, LineKind::Markdown); } + #[test] + fn let_prose_not_cordial() { + let c = classify_line(0, "let us consider something"); + assert_eq!(c.kind, LineKind::Markdown); + } + + #[test] + fn let_without_equals_not_cordial() { + let c = classify_line(0, "let me explain"); + assert_eq!(c.kind, LineKind::Markdown); + } + #[test] fn single_line_block_comment() { let lines = classify_document("/* hello */");