diff options
author | John MacFarlane <jgm@berkeley.edu> | 2016-07-19 09:03:15 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2016-07-19 09:03:15 -0700 |
commit | e2d59461bbaa5ff41d41b2f0e430e03c12d8d0fd (patch) | |
tree | b6eb0836f2590aaac6e5e3e86077d81ac42bc504 /src | |
parent | 3490932d21d72a7708963794aeffc925ecda74f4 (diff) | |
download | pandoc-e2d59461bbaa5ff41d41b2f0e430e03c12d8d0fd.tar.gz |
Textile reader: improve definition list parsing.
- Allow multiple terms (which we concatenate with linebreaks).
- Fix exponential parsing bug (closes #3020 for real this time).
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Textile.hs | 19 |
1 files changed, 13 insertions, 6 deletions
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]) |