aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-07-19 09:03:15 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2016-07-19 09:03:15 -0700
commite2d59461bbaa5ff41d41b2f0e430e03c12d8d0fd (patch)
treeb6eb0836f2590aaac6e5e3e86077d81ac42bc504 /src/Text/Pandoc
parent3490932d21d72a7708963794aeffc925ecda74f4 (diff)
downloadpandoc-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/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/Textile.hs19
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])