diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-10-18 13:20:27 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-10-18 13:20:27 -0700 |
commit | 84f6b1e41a9d0c44ec4a87dfbb5de9f19407b919 (patch) | |
tree | 486e389241ba522e5d336d23812ab6dd84b6b324 /src/Text | |
parent | 31713d572a606a487d36c4a4d673b9797cf4a0db (diff) | |
parent | f1f56e85334fd29b4ed670d0b280e85f68e21bf2 (diff) | |
download | pandoc-84f6b1e41a9d0c44ec4a87dfbb5de9f19407b919.tar.gz |
Merge pull request #1680 from shelf/master
Respect indent when parsing Org bullet lists
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Readers/Org.hs | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/Org.hs b/src/Text/Pandoc/Readers/Org.hs index 67470eff9..a6ebf65dc 100644 --- a/src/Text/Pandoc/Readers/Org.hs +++ b/src/Text/Pandoc/Readers/Org.hs @@ -853,12 +853,14 @@ list :: OrgParser (F Blocks) list = choice [ definitionList, bulletList, orderedList ] <?> "list" definitionList :: OrgParser (F Blocks) -definitionList = fmap B.definitionList . fmap compactify'DL . sequence - <$> many1 (definitionListItem bulletListStart) +definitionList = try $ do n <- lookAhead (bulletListStart' Nothing) + fmap B.definitionList . fmap compactify'DL . sequence + <$> many1 (definitionListItem $ bulletListStart' (Just n)) bulletList :: OrgParser (F Blocks) -bulletList = fmap B.bulletList . fmap compactify' . sequence - <$> many1 (listItem bulletListStart) +bulletList = try $ do n <- lookAhead (bulletListStart' Nothing) + fmap B.bulletList . fmap compactify' . sequence + <$> many1 (listItem (bulletListStart' $ Just n)) orderedList :: OrgParser (F Blocks) orderedList = fmap B.orderedList . fmap compactify' . sequence @@ -870,10 +872,27 @@ genericListStart listMarker = try $ (+) <$> (length <$> many spaceChar) <*> (length <$> listMarker <* many1 spaceChar) --- parses bullet list start and returns its length (excl. following whitespace) +-- parses bullet list marker. maybe we know the indent level bulletListStart :: OrgParser Int -bulletListStart = genericListStart bulletListMarker - where bulletListMarker = pure <$> oneOf "*-+" +bulletListStart = bulletListStart' Nothing + +bulletListStart' :: Maybe Int -> OrgParser Int +-- returns length of bulletList prefix, inclusive of marker +bulletListStart' Nothing = do ind <- many spaceChar + oneOf bullets + many1 spaceChar + return $ length ind + 1 + -- Unindented lists are legal, but they can't use '*' bullets + -- We return n to maintain compatibility with the generic listItem +bulletListStart' (Just n) = do count (n-1) spaceChar + oneOf validBullets + many1 spaceChar + return n + where validBullets = if n == 1 then noAsterisks else bullets + noAsterisks = filter (/= '*') bullets + +bullets :: String +bullets = "*+-" orderedListStart :: OrgParser Int orderedListStart = genericListStart orderedListMarker |