@@ -828,13 +828,14 @@ list :: OrgParser (F Blocks)
828828list = choice [ definitionList, bulletList, orderedList ] <?> " list"
829829
830830definitionList :: OrgParser (F Blocks )
831- definitionList = fmap B. definitionList . fmap compactify'DL . sequence
832- <$> many1 (definitionListItem bulletListStart)
831+ definitionList = try $ do n <- lookAhead (bulletListStart' Nothing )
832+ fmap B. definitionList . fmap compactify'DL . sequence
833+ <$> many1 (definitionListItem $ bulletListStart' (Just n))
833834
834835bulletList :: OrgParser (F Blocks )
835- bulletList = try $ do n <- lookAhead bulletListStart
836+ bulletList = try $ do n <- lookAhead ( bulletListStart' Nothing )
836837 fmap B. bulletList . fmap compactify' . sequence
837- <$> many1 (listItem (bulletListCont n))
838+ <$> many1 (listItem (bulletListStart' $ Just n))
838839
839840orderedList :: OrgParser (F Blocks )
840841orderedList = fmap B. orderedList . fmap compactify' . sequence
@@ -846,17 +847,27 @@ genericListStart listMarker = try $
846847 (+) <$> (length <$> many spaceChar)
847848 <*> (length <$> listMarker <* many1 spaceChar)
848849
849- -- parses bullet list start and returns its length (excl. following whitespace)
850+ -- parses bullet list marker. maybe we know the indent level
850851bulletListStart :: OrgParser Int
851- bulletListStart = genericListStart bulletListMarker
852- where bulletListMarker = pure <$> oneOf " *-+"
853-
854- -- parses bullet list marker at a known indent level
855- bulletListCont :: Int -> OrgParser Int
856- bulletListCont n
857- -- Unindented lists are legal, but they can't use '*' bullets
858- | n <= 1 = oneOf " +-" >> return n
859- | otherwise = count (n- 1 ) spaceChar >> oneOf " +-*" >> return n
852+ bulletListStart = bulletListStart' Nothing
853+
854+ bulletListStart' :: Maybe Int -> OrgParser Int
855+ -- returns length of bulletList prefix, inclusive of marker
856+ bulletListStart' Nothing = do ind <- many spaceChar
857+ oneOf bullets
858+ many1 spaceChar
859+ return $ length ind + 1
860+ -- Unindented lists are legal, but they can't use '*' bullets
861+ -- We return n to maintain compatibility with the generic listItem
862+ bulletListStart' (Just n) = do count (n- 1 ) spaceChar
863+ oneOf validBullets
864+ many1 spaceChar
865+ return n
866+ where validBullets = if n == 1 then noAsterisks else bullets
867+ noAsterisks = filter (/= ' *' ) bullets
868+
869+ bullets :: String
870+ bullets = " *+-"
860871
861872orderedListStart :: OrgParser Int
862873orderedListStart = genericListStart orderedListMarker
0 commit comments