fixed a test and then passed it

This commit is contained in:
Pagwin 2025-12-05 20:07:19 -05:00
parent c4ff078785
commit cd0cf5f016
No known key found for this signature in database
GPG key ID: 81137023740CA260
2 changed files with 10 additions and 9 deletions

View file

@ -9,6 +9,7 @@ module Markdown (document, metadata) where
import Control.Applicative (many, optional, some, (<|>)) import Control.Applicative (many, optional, some, (<|>))
import Control.Monad (guard, void) import Control.Monad (guard, void)
import Data.Functor.Identity (Identity) import Data.Functor.Identity (Identity)
import Data.Maybe (maybeToList)
import Data.String (IsString) import Data.String (IsString)
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as T import qualified Data.Text as T
@ -166,19 +167,19 @@ unorderedListItem = do
content <- many $ notFollowedBy lineEnding' *> inlineElement content <- many $ notFollowedBy lineEnding' *> inlineElement
lineEnding' lineEnding'
-- continuations <- many listContinuation -- continuations <- many listContinuation
children <- many (try indentedList) children <- maybeToList <$> (optional $ indentedList 1)
pure $ LI content children pure $ LI content children
-- TODO: handle list indentation at all levels -- TODO: handle list indentation at all levels
indentedList :: (Logger m, Token s ~ Char, Stream s, IsString (Tokens s)) => ParserTG s m List indentedList :: (Logger m, Token s ~ Char, Stream s, IsString (Tokens s)) => Int -> ParserTG s m List
indentedList = do indentedList n = do
let n = 1
void $ (count (4 * n) (char ' ')) <|> count n (char '\t') void $ (count (4 * n) (char ' ')) <|> count n (char '\t')
choice [try indentedUnorderedList, indentedOrderedList] ret <- (try indentedUnorderedList) <|> indentedOrderedList
pure ret <* lineEnding'
indentedUnorderedList :: (Logger m, Token s ~ Char, Stream s, IsString (Tokens s)) => ParserTG s m List indentedUnorderedList :: (Logger m, Token s ~ Char, Stream s, IsString (Tokens s)) => ParserTG s m List
indentedUnorderedList = do indentedUnorderedList = do
items <- some (try $ indentedListItem (oneOf "*-+" >> void (char ' ' <|> char '\t'))) items <- some (indentedListItem (oneOf "*-+" >> void (char ' ' <|> char '\t')))
pure $ L Unordered items pure $ L Unordered items
indentedOrderedList :: (Logger m, Token s ~ Char, Stream s, IsString (Tokens s)) => ParserTG s m List indentedOrderedList :: (Logger m, Token s ~ Char, Stream s, IsString (Tokens s)) => ParserTG s m List
@ -207,7 +208,7 @@ orderedListItem = do
content <- many $ notFollowedBy lineEnding' *> inlineElement content <- many $ notFollowedBy lineEnding' *> inlineElement
lineEnding' lineEnding'
-- continuations <- many listContinuation -- continuations <- many listContinuation
children <- many (try indentedList) children <- maybeToList <$> (optional $ indentedList 1)
pure $ LI content children pure $ LI content children
-- HTML Block -- HTML Block

View file

@ -234,7 +234,7 @@ nested_unordered_list = property $ do
item_1 <- text_gen item_1 <- text_gen
item_2 <- text_gen item_2 <- text_gen
item_3 <- text_gen item_3 <- text_gen
let input = "- " <> item_1 <> "\n -" <> item_2 <> "\n- " <> item_3 let input = "- " <> item_1 <> "\n - " <> item_2 <> "\n- " <> item_3
parsed <- generic_parse input parsed <- generic_parse input
case parsed of case parsed of
@ -242,7 +242,7 @@ nested_unordered_list = property $ do
( Just ( Just
( Right ( Right
( Doc ( Doc
[ List (L {list_type = Unordered, items = [LI {content = [Text item_1], children = [L {list_type = Unordered, items = [LI {content = [Text item_2]}]}]}, LI {content = [Text item_3], children = []}]}) [ List (L {list_type = Unordered, items = [LI {content = [Text item_1], children = [L {list_type = Unordered, items = [LI {content = [Text item_2], children = []}]}]}, LI {content = [Text item_3], children = []}]})
] ]
) )
) )