diff --git a/harper-typst/src/lib.rs b/harper-typst/src/lib.rs index a67eb9ea..bbd51aa9 100644 --- a/harper-typst/src/lib.rs +++ b/harper-typst/src/lib.rs @@ -23,48 +23,6 @@ impl Parser for Typst { let typst_tree = Markup::from_untyped(typst_document.root()) .expect("Unable to create typst document from parsed tree!"); - // Owned collection of nodes forcibly casted to paragraph breaks - let untyped_nodes = typst_tree - .exprs() - .map(|e| { - let mut node = SyntaxNode::placeholder(typst_syntax::SyntaxKind::Parbreak); - node.synthesize(e.span()); - node - }) - .collect_vec(); - - // Converts newlines after certain elements to paragraph breaks - // This is accomplished here instead of in the translating module because at this point there is - // still semantic information associated with the elements. - // - // Newlines are separate expressions in the parse tree (as the Space variant) - let should_parbreak = |e1, e2, e3| { - matches!(e2, Expr::Space(_)) - && (matches!(e1, Expr::Heading(_) | Expr::List(_)) - || matches!(e3, Expr::Heading(_) | Expr::List(_))) - }; - - let mut exprs: Vec = Vec::new(); - let mut last_element: Option = None; - for ((i, expr), (_, next_expr)) in typst_tree.exprs().enumerate().tuple_windows() { - let mut current_expr = expr; - if let Some(last_element) = last_element { - if should_parbreak(last_element, expr, next_expr) { - let pbreak = typst_syntax::ast::Parbreak::from_untyped(&untyped_nodes[i]) - .expect("Unable to convert expression to Parbreak"); - current_expr = Expr::Parbreak(pbreak); - } - } - exprs.push(current_expr); - last_element = Some(expr) - } - // Push last element because it will be excluded by tuple_windows() above - if let Some(last) = typst_tree.exprs().last() { - exprs.push(last); - } - - dbg!(&exprs); - // Recurse through AST to create tokens let parse_helper = TypstTranslator::new(&typst_document); let mut buf = Vec::new();