Skip to content

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

fix(#1926): isolate typst content blocks with parbreaks (#1927)

Grant Lemons99a67ca9bddb
diff --git a/harper-typst/src/typst_translator.rs b/harper-typst/src/typst_translator.rs
index baddba8d3..81cf123db 100644
--- a/harper-typst/src/typst_translator.rs
+++ b/harper-typst/src/typst_translator.rs
@@ -152,6 +152,17 @@ impl<'a> TypstTranslator<'a> {
};
}
+ fn parbreak() -> Option<Vec<Token>> {
+ Some(vec![Token {
+ span: harper_core::Span::EMPTY,
+ kind: TokenKind::ParagraphBreak,
+ }])
+ }
+
+ fn isolate(inner: Option<Vec<Token>>) -> Option<Vec<Token>> {
+ merge![parbreak(), inner, parbreak()]
+ }
+
// Recurse on each element of an iterator
let iter_recurse = |exprs: &mut dyn Iterator<Item = Expr>| {
let mut buf = Vec::new();
@@ -294,7 +305,9 @@ impl<'a> TypstTranslator<'a> {
.collect_vec(),
)
}
- Expr::Content(content_block) => iter_recurse(&mut content_block.body().exprs()),
+ Expr::Content(content_block) => {
+ isolate(iter_recurse(&mut content_block.body().exprs()))
+ }
Expr::Parenthesized(parenthesized) => recurse!(parenthesized.expr()),
Expr::Array(array) => Some(
array
diff --git a/harper-typst/tests/run_tests.rs b/harper-typst/tests/run_tests.rs
index d4bd79ad0..ff766a141 100644
--- a/harper-typst/tests/run_tests.rs
+++ b/harper-typst/tests/run_tests.rs
@@ -40,3 +40,4 @@ create_test!(simplified_document.typ, 0);
create_test!(complex_document_with_spelling_mistakes.typ, 4);
// create_test!(issue_399.typ, 3);
create_test!(function_with_ignorable_args.typ, 9);
+create_test!(issue_1926.typ, 1);
diff --git a/harper-typst/tests/test_sources/issue_1926.typ b/harper-typst/tests/test_sources/issue_1926.typ
new file mode 100644
index 000000000..fce9a2fa9
--- /dev/null
+++ b/harper-typst/tests/test_sources/issue_1926.typ
@@ -0,0 +1,5 @@
+No No
+#table(
+ columns: 2,
+ [No], [No]
+)