From 132496cdcaedfed21a6033380f88ab77c2eaf72f Mon Sep 17 00:00:00 2001 From: Pagwin Date: Sat, 13 Dec 2025 16:11:16 -0500 Subject: [PATCH] removed debug log and handled list newlines correctly, this was concerningly easy --- src/Markdown.hs | 7 ++++--- tests/Markdown/Parse.hs | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Markdown.hs b/src/Markdown.hs index 710025a..663d923 100644 --- a/src/Markdown.hs +++ b/src/Markdown.hs @@ -63,7 +63,6 @@ element = try htmlBlock "HTML Block", paragraphBlock "Paragarph" ] - <* logDebug "element end" <* blockEnding lineEnding :: (Logger m, Characters s, HasCallStack) => Parser s m () @@ -162,12 +161,14 @@ listBlock list_type prefix child_parser_factory nest_level = do pure $ List $ L {list_type, items} where listItem = do - -- TODO - error "Need to handle newlines and not consuming blockEndings here due to nesting" count nest_level ((try $ void $ char '\t') <|> (void $ (count 4 $ char ' '))) prefix content <- many ((notFollowedBy lineEnding) *> inlineText' lineEnding) + + optional ((notFollowedBy blockEnding) *> lineEnding) + child <- optional $ child_parser_factory $ nest_level + 1 + pure $ LI {content, child} unorderedListBlock :: (Logger m, Characters s) => Int -> Parser s m Element diff --git a/tests/Markdown/Parse.hs b/tests/Markdown/Parse.hs index 45548f3..0c82131 100644 --- a/tests/Markdown/Parse.hs +++ b/tests/Markdown/Parse.hs @@ -40,6 +40,7 @@ main = do ("ordered_list", ordered_list), ("multiple_ordered_lists", multiple_ordered_lists), ("header_then_ordered_list", header_then_ordered_list), + ("simple_nested_ordered_list", simple_nested_ordered_list), ("nested_unordered_list", nested_unordered_list) -- ("",), ] @@ -222,6 +223,27 @@ multiple_ordered_lists = property $ do (Just (Right tree)) -> fail $ "Incorrect syntax tree: " <> show tree (Just (Left e)) -> fail $ errorBundlePretty e +simple_nested_ordered_list :: Property +simple_nested_ordered_list = property $ do + let text_gen = forAll $ Gen.text (Range.linear 1 10) Gen.alpha + item_1 <- text_gen + item_2 <- text_gen + let input = "1) " <> item_1 <> "\n 1) " <> item_2 + + parsed <- generic_parse input + case parsed of + Nothing -> fail $ "Hit Timeout" + ( Just + ( Right + ( Doc + [ List (L {list_type = Ordered, items = [LI {content = [Text item_1], child = Just (L {list_type = Ordered, items = [LI {content = [Text item_2], child = Nothing}]})}]}) + ] + ) + ) + ) -> success + (Just (Right tree)) -> fail $ "Incorrect syntax tree: " <> show tree + (Just (Left e)) -> fail $ errorBundlePretty e + -- - a -- - a -- - b