From e2d59461bbaa5ff41d41b2f0e430e03c12d8d0fd Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 19 Jul 2016 09:03:15 -0700 Subject: Textile reader: improve definition list parsing. - Allow multiple terms (which we concatenate with linebreaks). - Fix exponential parsing bug (closes #3020 for real this time). --- src/Text/Pandoc/Readers/Textile.hs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/Text/Pandoc/Readers') diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs index d9cdfd66f..13fe29ca2 100644 --- a/src/Text/Pandoc/Readers/Textile.hs +++ b/src/Text/Pandoc/Readers/Textile.hs @@ -62,7 +62,7 @@ import Text.Pandoc.Shared (trim) import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock ) import Text.HTML.TagSoup (parseTags, innerText, fromAttrib, Tag(..)) import Text.HTML.TagSoup.Match -import Data.List ( intercalate, transpose ) +import Data.List ( intercalate, transpose, intersperse ) import Data.Char ( digitToInt, isUpper ) import Control.Monad ( guard, liftM, when ) import Text.Pandoc.Compat.Monoid ((<>)) @@ -273,13 +273,20 @@ listStart = genericListStart '*' genericListStart :: Char -> Parser [Char] st () genericListStart c = () <$ try (many1 (char c) >> whitespace) -definitionListStart :: Parser [Char] ParserState Inlines -definitionListStart = try $ do +basicDLStart :: Parser [Char] ParserState () +basicDLStart = do char '-' whitespace notFollowedBy newline + +definitionListStart :: Parser [Char] ParserState Inlines +definitionListStart = try $ do + basicDLStart trimInlines . mconcat <$> - many1Till inline (try (string ":=")) <* optional whitespace + many1Till inline + ( try (newline *> lookAhead basicDLStart) + <|> try (lookAhead (() <$ string ":=")) + ) listInline :: Parser [Char] ParserState Inlines listInline = try (notFollowedBy newline >> inline) @@ -291,8 +298,8 @@ listInline = try (notFollowedBy newline >> inline) -- break. definitionListItem :: Parser [Char] ParserState (Inlines, [Blocks]) definitionListItem = try $ do - term <- definitionListStart - def' <- multilineDef <|> inlineDef + term <- (mconcat . intersperse B.linebreak) <$> many1 definitionListStart + def' <- string ":=" *> optional whitespace *> (multilineDef <|> inlineDef) return (term, def') where inlineDef :: Parser [Char] ParserState [Blocks] inlineDef = liftM (\d -> [B.plain d]) -- cgit v1.2.3