@@ -853,12 +853,14 @@ list :: OrgParser (F Blocks)
853853list = choice [ definitionList, bulletList, orderedList ] <?> " list"
854854
855855definitionList :: OrgParser (F Blocks )
856- definitionList = fmap B. definitionList . fmap compactify'DL . sequence
857- <$> many1 (definitionListItem bulletListStart)
856+ definitionList = try $ do n <- lookAhead (bulletListStart' Nothing )
857+ fmap B. definitionList . fmap compactify'DL . sequence
858+ <$> many1 (definitionListItem $ bulletListStart' (Just n))
858859
859860bulletList :: OrgParser (F Blocks )
860- bulletList = fmap B. bulletList . fmap compactify' . sequence
861- <$> many1 (listItem bulletListStart)
861+ bulletList = try $ do n <- lookAhead (bulletListStart' Nothing )
862+ fmap B. bulletList . fmap compactify' . sequence
863+ <$> many1 (listItem (bulletListStart' $ Just n))
862864
863865orderedList :: OrgParser (F Blocks )
864866orderedList = fmap B. orderedList . fmap compactify' . sequence
@@ -870,10 +872,27 @@ genericListStart listMarker = try $
870872 (+) <$> (length <$> many spaceChar)
871873 <*> (length <$> listMarker <* many1 spaceChar)
872874
873- -- parses bullet list start and returns its length (excl. following whitespace)
875+ -- parses bullet list marker. maybe we know the indent level
874876bulletListStart :: OrgParser Int
875- bulletListStart = genericListStart bulletListMarker
876- where bulletListMarker = pure <$> oneOf " *-+"
877+ bulletListStart = bulletListStart' Nothing
878+
879+ bulletListStart' :: Maybe Int -> OrgParser Int
880+ -- returns length of bulletList prefix, inclusive of marker
881+ bulletListStart' Nothing = do ind <- many spaceChar
882+ oneOf bullets
883+ many1 spaceChar
884+ return $ length ind + 1
885+ -- Unindented lists are legal, but they can't use '*' bullets
886+ -- We return n to maintain compatibility with the generic listItem
887+ bulletListStart' (Just n) = do count (n- 1 ) spaceChar
888+ oneOf validBullets
889+ many1 spaceChar
890+ return n
891+ where validBullets = if n == 1 then noAsterisks else bullets
892+ noAsterisks = filter (/= ' *' ) bullets
893+
894+ bullets :: String
895+ bullets = " *+-"
877896
878897orderedListStart :: OrgParser Int
879898orderedListStart = genericListStart orderedListMarker
0 commit comments