@@ -141,14 +141,16 @@ nonindentSpaces = do
141 then return sps
141 then return sps
142 else unexpected "indented line"
142 else unexpected "indented line"
144+-- returns number of spaces parsed
144−skipNonindentSpaces :: MarkdownParser ()
145+skipNonindentSpaces :: MarkdownParser Int
145skipNonindentSpaces = do
146skipNonindentSpaces = do
146 tabStop <- getOption readerTabStop
147 tabStop <- getOption readerTabStop
147− atMostSpaces (tabStop - 1)
148+ atMostSpaces (tabStop - 1) <* notFollowedBy (char ' ')
149−atMostSpaces :: Int -> MarkdownParser ()
150+atMostSpaces :: Int -> MarkdownParser Int
150−atMostSpaces 0 = notFollowedBy (char ' ')
151+atMostSpaces n
151−atMostSpaces n = (char ' ' >> atMostSpaces (n-1)) <|> return ()
152+ | n > 0 = (char ' ' >> (+1) <$> atMostSpaces (n-1)) <|> return 0
153+ | otherwise = return 0
153litChar :: MarkdownParser Char
155litChar :: MarkdownParser Char
154litChar = escapedChar'
156litChar = escapedChar'
@@ -717,35 +719,42 @@ blockQuote = do
717bulletListStart :: MarkdownParser ()
719bulletListStart :: MarkdownParser ()
718bulletListStart = try $ do
720bulletListStart = try $ do
719 optional newline -- if preceded by a Plain block in a list context
721 optional newline -- if preceded by a Plain block in a list context
722+ startpos <- sourceColumn <$> getPosition
720 skipNonindentSpaces
723 skipNonindentSpaces
721 notFollowedBy' (() <$ hrule) -- because hrules start out just like lists
724 notFollowedBy' (() <$ hrule) -- because hrules start out just like lists
722 satisfy isBulletListMarker
725 satisfy isBulletListMarker
726+ endpos <- sourceColumn <$> getPosition
727+ tabStop <- getOption readerTabStop
723− spaceChar <|> lookAhead newline
728+ lookAhead (newline <|> spaceChar)
724− skipSpaces
729+ () <$ atMostSpaces (tabStop - (endpos - startpos))
726anyOrderedListStart :: MarkdownParser (Int, ListNumberStyle, ListNumberDelim)
731anyOrderedListStart :: MarkdownParser (Int, ListNumberStyle, ListNumberDelim)
727anyOrderedListStart = try $ do
732anyOrderedListStart = try $ do
728 optional newline -- if preceded by a Plain block in a list context
733 optional newline -- if preceded by a Plain block in a list context
734+ startpos <- sourceColumn <$> getPosition
729 skipNonindentSpaces
735 skipNonindentSpaces
730 notFollowedBy $ string "p." >> spaceChar >> digit -- page number
736 notFollowedBy $ string "p." >> spaceChar >> digit -- page number
731− (guardDisabled Ext_fancy_lists >>
737+ res <- do guardDisabled Ext_fancy_lists
732− do many1 digit
738+ many1 digit
733− char '.'
739+ char '.'
735− return (1, DefaultStyle, DefaultDelim))
740+ return (1, DefaultStyle, DefaultDelim)
736− <|> do (num, style, delim) <- anyOrderedListMarker
741+ <|> do (num, style, delim) <- anyOrderedListMarker
737− -- if it could be an abbreviated first name, insist on more than one space
742+ -- if it could be an abbreviated first name,
743+ -- insist on more than one space
738− if delim == Period && (style == UpperAlpha || (style == UpperRoman &&
744+ when (delim == Period && (style == UpperAlpha ||
745+ (style == UpperRoman &&
739− num `elem` [1, 5, 10, 50, 100, 500, 1000]))
746+ num `elem` [1, 5, 10, 50, 100, 500, 1000]))) $
740− then char '\t' <|> (try $ char ' ' >> spaceChar)
747+ () <$ spaceChar
741− else spaceChar
748+ return (num, style, delim)
742− skipSpaces
749+ endpos <- sourceColumn <$> getPosition
743− return (num, style, delim)
750+ tabStop <- getOption readerTabStop
751+ lookAhead (newline <|> spaceChar)
752+ atMostSpaces (tabStop - (endpos - startpos))
745listStart :: MarkdownParser ()
755listStart :: MarkdownParser ()
746listStart = bulletListStart <|> (anyOrderedListStart >> return ())
756listStart = bulletListStart <|> (anyOrderedListStart >> return ())
748−-- parse a line of a list item (start = parser for beginning of list item)
749listLine :: MarkdownParser String
758listLine :: MarkdownParser String
750listLine = try $ do
759listLine = try $ do
751 notFollowedBy' (do indentSpaces
760 notFollowedBy' (do indentSpaces
@@ -753,19 +762,21 @@ listLine = try $ do
753 listStart)
762 listStart)
754 notFollowedByHtmlCloser
763 notFollowedByHtmlCloser
755 optional (() <$ indentSpaces)
764 optional (() <$ indentSpaces)
756− chunks <- manyTill
765+ listLineCommon
767+listLineCommon :: MarkdownParser String
768+listLineCommon = concat <$> manyTill
757 ( many1 (satisfy $ \c -> c /= '\n' && c /= '<')
769 ( many1 (satisfy $ \c -> c /= '\n' && c /= '<')
758 <|> liftM snd (htmlTag isCommentTag)
770 <|> liftM snd (htmlTag isCommentTag)
759 <|> count 1 anyChar
771 <|> count 1 anyChar
760 ) newline
772 ) newline
761− return $ concat chunks
763-- parse raw text for one list item, excluding start marker and continuations
774-- parse raw text for one list item, excluding start marker and continuations
764rawListItem :: MarkdownParser a
775rawListItem :: MarkdownParser a
765 -> MarkdownParser String
776 -> MarkdownParser String
766rawListItem start = try $ do
777rawListItem start = try $ do
768− first <- listLine
779+ first <- listLineCommon
769 rest <- many (notFollowedBy listStart >> notFollowedBy blankline >> listLine)
780 rest <- many (notFollowedBy listStart >> notFollowedBy blankline >> listLine)
770 blanks <- many blankline
781 blanks <- many blankline
771 return $ unlines (first:rest) ++ blanks
782 return $ unlines (first:rest) ++ blanks
@@ -823,8 +834,14 @@ orderedList = try $ do
823 items <- fmap sequence $ many1 $ listItem
834 items <- fmap sequence $ many1 $ listItem
824 ( try $ do
835 ( try $ do
825 optional newline -- if preceded by Plain block in a list
836 optional newline -- if preceded by Plain block in a list
837+ startpos <- sourceColumn <$> getPosition
826 skipNonindentSpaces
838 skipNonindentSpaces
827− orderedListMarker style delim )
839+ res <- orderedListMarker style delim
840+ endpos <- sourceColumn <$> getPosition
841+ tabStop <- getOption readerTabStop
842+ lookAhead (newline <|> spaceChar)
843+ atMostSpaces (tabStop - (endpos - startpos))
828 start' <- option 1 $ guardEnabled Ext_startnum >> return start
845 start' <- option 1 $ guardEnabled Ext_startnum >> return start
829 return $ B.orderedListWith (start', style, delim) <$> fmap compactify' items
846 return $ B.orderedListWith (start', style, delim) <$> fmap compactify' items