Skip to content

Commit

Permalink
Muse reader: parse ordered lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Krotov committed Jun 18, 2017
1 parent dac2ce9 commit 2409c3e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/Text/Pandoc/Readers/Muse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ TODO:
- Page breaks (five "*")
- Headings with anchors (make it round trip with Muse writer)
- <verse> and ">"
- Ordered lists
- Definition lists
- Org tables
- table.el tables
Expand Down Expand Up @@ -185,6 +184,7 @@ blockElements = choice [ comment
, rightTag
, quoteTag
, bulletList
, orderedList
, table
, commentTag
, noteBlock
Expand Down Expand Up @@ -326,6 +326,26 @@ listItem start = try $ do
rest <- many $ listContinuation markerLength
parseFromString (withListContext parseBlocks) $ concat (first:rest) ++ "\n"

orderedListStart :: PandocMonad m
=> ListNumberStyle
-> ListNumberDelim
-> MuseParser m Int
orderedListStart style delim = try $ do
preWhitespace <- length <$> many spaceChar
st <- stateParserContext <$> getState
getPosition >>= \pos -> guard (st == ListItemState || sourceColumn pos /= 1)
(_, markerLength) <- withHorizDisplacement (orderedListMarker style delim)
postWhitespace <- length <$> many1 spaceChar
return $ preWhitespace + markerLength + postWhitespace

orderedList :: PandocMonad m => MuseParser m (F Blocks)
orderedList = try $ do
p@(_, style, delim) <- lookAhead (many spaceChar *> anyOrderedListMarker <* spaceChar)
guard $ style `elem` [Decimal, LowerAlpha, UpperAlpha, LowerRoman, UpperRoman]
guard $ delim == Period
items <- sequence <$> many1 (listItem $ orderedListStart style delim)
return $ B.orderedListWith p <$> items

--
-- tables
--
Expand Down
19 changes: 18 additions & 1 deletion test/Tests/Readers/Muse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,36 @@ tests =
bulletList [ para "Item1"
, para "Item2"
]
, "Ordered list" =:
T.unlines
[ " 1. Item1"
, ""
, " 2. Item2"
] =?>
orderedListWith (1, Decimal, Period) [ para "Item1"
, para "Item2"
]
, "Nested list" =:
T.unlines
[ " - Item1"
, " - Item2"
, " - Item3"
, " - Item4"
, " 1. Nested"
, " 2. Ordered"
, " 3. List"
] =?>
bulletList [ mconcat [ para "Item1"
, bulletList [ para "Item2"
, para "Item3"
]
]
, para "Item4"
, mconcat [ para "Item4"
, orderedListWith (1, Decimal, Period) [ para "Nested"
, para "Ordered"
, para "List"
]
]
]
]
]

0 comments on commit 2409c3e

Please sign in to comment.