@@ -57,7 +57,6 @@ module Text.Pandoc.Parsing ( (>>~),
57 orderedListMarker,
57 orderedListMarker,
59 tableWith,
59 tableWith,
61 gridTableWith,
60 gridTableWith,
63 testStringWith,
62 testStringWith,
@@ -108,9 +107,11 @@ module Text.Pandoc.Parsing ( (>>~),
113 sepEndBy,
112 sepEndBy,
116 optional,
117 optional,
@@ -536,7 +537,7 @@ tableWith :: Parsec [Char] ParserState ([[Block]], [Alignment], [Int])
536tableWith headerParser rowParser lineParser footerParser captionParser = try $ do
537tableWith headerParser rowParser lineParser footerParser captionParser = try $ do
537 caption' <- option [] captionParser
538 caption' <- option [] captionParser
538 (heads, aligns, indices) <- headerParser
539 (heads, aligns, indices) <- headerParser
539− lines' <- rowParser indices `sepEndBy` lineParser
540+ lines' <- rowParser indices `sepEndBy1` lineParser
540 footerParser
541 footerParser
541 caption <- if null caption'
542 caption <- if null caption'
542 then option [] captionParser
543 then option [] captionParser
@@ -573,97 +574,6 @@ widthsFromIndices numColumns' indices =
573 fracs = map (\l -> (fromIntegral l) / quotient) lengths in
574 fracs = map (\l -> (fromIntegral l) / quotient) lengths in
574 tail fracs
575 tail fracs
577−-- Parse an extra table (php-markdown): each line starts and ends with '|',
578−-- with a mandatory line of '--' to separate the (optionnal) headers from content.
579−extraTableWith :: GenParser Char ParserState Block -- ^ Block parser
580− -> GenParser Char ParserState [Inline] -- ^ Caption parser
581− -> Bool -- ^ Headerless table
582− -> GenParser Char ParserState Block
583−extraTableWith block tableCaption headless =
584− tableWith (extraTableHeader headless block) (extraTableRow block) (extraTableSep '-') extraTableFooter tableCaption
586−-- | Parse header for an extra table.
587−extraTableHeader :: Bool -- ^ Headerless table
588− -> GenParser Char ParserState Block
589− -> GenParser Char ParserState ([[Block]], [Alignment], [Int])
590−extraTableHeader headless block = try $ do
592− rawContent <- if headless
593− then return $ repeat ""
595− (notFollowedBy (extraTableHeaderSep) >> char '|' >>
596− many1Till anyChar newline)
597− aligns <- extraTableHeaderDashedLine
599− let rawHeads = if headless
600− then replicate (length aligns) ""
601− else map (intercalate " ") $ transpose
602− $ map (extraTableSplitLine )
603− $ map (trimOnceBy '|') rawContent
604− heads <- mapM (parseFromString $ many block) $
605− map removeLeadingTrailingSpace rawHeads
606− return (heads, aligns, indices)
608−extraTableHeaderPart :: GenParser Char st Alignment
609−extraTableHeaderPart = do
610− left <- optionMaybe (char ':')
612− right <- optionMaybe (char ':')
615− case (left,right) of
616− (Nothing,Nothing) -> AlignDefault
617− (Just _,Nothing) -> AlignLeft
618− (Nothing,Just _) -> AlignRight
619− (Just _,Just _) -> AlignCenter
621−extraTableHeaderDashedLine :: GenParser Char st [Alignment]
622−extraTableHeaderDashedLine = try $ char '|' >> many1 (extraTableHeaderPart) >>~ blankline
624−extraTableHeaderSep :: GenParser Char ParserState Char
625−extraTableHeaderSep = try $ extraTableHeaderDashedLine >> return '\n'
627−-- | Split a header or data line in an extra table.
628−-- | The line must contain only *inside* separators.
629−extraTableSplitLine :: String -> [String]
630−extraTableSplitLine line = map removeLeadingSpace $
631− splitBy (== '|') $ removeTrailingSpace line
633−-- Remove, if present, a character from both ends of a string
634−trimOnceBy :: Char -> String -> String
636− if (head s == ch) && (last s == ch)
639−trimEndOnceBy :: Char -> String -> String
645−-- | Parse row of an extra table.
646−extraTableRow :: GenParser Char ParserState Block
648− -> GenParser Char ParserState [[Block]]
649−extraTableRow block indices = do
650− cols <- extraTableRawLine
651− mapM (liftM compactifyCell . parseFromString (many block)) cols
653−extraTableRawLine :: GenParser Char ParserState [String]
654−extraTableRawLine = do
656− line <- many1Till anyChar newline
657− return (extraTableSplitLine $ trimEndOnceBy '|' line)
659−-- | Separator between rows of an extra table.
660−extraTableSep :: Char -> GenParser Char ParserState Char
661−extraTableSep ch = do return '\n'
663−-- | Parse footer for an extra table.
664−extraTableFooter :: GenParser Char ParserState [Char]
665−extraTableFooter = blanklines
669-- Parse a grid table: starts with row of '-' on top, then header
579-- Parse a grid table: starts with row of '-' on top, then header