git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Fix pandoc title blocks with lines ending in 2 spaces.

Closes #2799. Also added -s to markdown-reader-more test.

commit4b49f923cbfd74287742f7d9634406580d48515b authorJohn MacFarlane <jgm@berkeley.edu> dateSun 10 Apr 2016, 09:13 (11 years ago) parent773bbb8
3 files changed+26−22
src/Text/Pandoc/Readers/Markdown.hs+23−19 tests/Tests/Old.hs+1−1 tests/markdown-reader-more.native+2−2
src/Text/Pandoc/Readers/Markdown.hs+23−19
@@ -122,9 +122,6 @@ inList = do
122122 ctx <- stateParserContext <$> getState
123123 guard (ctx == ListItemState)
124124
125−isNull :: F Inlines -> Bool
126−isNull ils = B.isNull $ runF ils def
127−
128125spnl :: Parser [Char] st ()
129126spnl = try $ do
130127 skipSpaces
@@ -188,31 +185,38 @@ charsInBalancedBrackets openBrackets =
188185-- document structure
189186--
190187
191−titleLine :: MarkdownParser (F Inlines)
192−titleLine = try $ do
188+rawTitleBlockLine :: MarkdownParser String
189+rawTitleBlockLine = do
193190 char '%'
194191 skipSpaces
195− res <- many $ (notFollowedBy newline >> inline)
196− <|> try (endline >> whitespace)
197− newline
192+ first <- anyLine
193+ rest <- many $ try $ do spaceChar
194+ notFollowedBy blankline
195+ skipSpaces
196+ anyLine
197+ return $ trim $ unlines (first:rest)
198+
199+titleLine :: MarkdownParser (F Inlines)
200+titleLine = try $ do
201+ raw <- rawTitleBlockLine
202+ res <- parseFromString (many inline) raw
198203 return $ trimInlinesF $ mconcat res
199204
200205authorsLine :: MarkdownParser (F [Inlines])
201206authorsLine = try $ do
202− char '%'
203− skipSpaces
204− authors <- sepEndBy (many (notFollowedBy (satisfy $ \c ->
205− c == ';' || c == '\n') >> inline))
206− (char ';' <|>
207− try (newline >> notFollowedBy blankline >> spaceChar))
208− newline
209− return $ sequence $ filter (not . isNull) $ map (trimInlinesF . mconcat) authors
207+ raw <- rawTitleBlockLine
208+ let sep = (char ';' <* spaces) <|> newline
209+ let pAuthors = sepEndBy
210+ (trimInlinesF . mconcat <$> many
211+ (try $ notFollowedBy sep >> inline))
212+ sep
213+ sequence <$> parseFromString pAuthors raw
210214
211215dateLine :: MarkdownParser (F Inlines)
212216dateLine = try $ do
213− char '%'
214− skipSpaces
215− trimInlinesF . mconcat <$> manyTill inline newline
217+ raw <- rawTitleBlockLine
218+ res <- parseFromString (many inline) raw
219+ return $ trimInlinesF $ mconcat res
216220
217221titleBlock :: MarkdownParser ()
218222titleBlock = pandocTitleBlock <|> mmdTitleBlock
tests/Tests/Old.hs+1−1
@@ -57,7 +57,7 @@ tests = [ testGroup "markdown"
5757 "tables.txt" "tables.native"
5858 , test "pipe tables" ["-r", "markdown", "-w", "native", "--columns=80"]
5959 "pipe-tables.txt" "pipe-tables.native"
60− , test "more" ["-r", "markdown", "-w", "native", "-S"]
60+ , test "more" ["-r", "markdown", "-w", "native", "-s", "-S"]
6161 "markdown-reader-more.txt" "markdown-reader-more.native"
6262 , lhsReaderTest "markdown+lhs"
6363 ]
tests/markdown-reader-more.native+2−2
@@ -1,5 +1,5 @@
1−[Para [Str "spanning",Space,Str "multiple",Space,Str "lines",SoftBreak,Str "%",Space,Str "Author",Space,Str "One",SoftBreak,Str "Author",Space,Str "Two;",Space,Str "Author",Space,Str "Three;",SoftBreak,Str "Author",Space,Str "Four"]
2−,Header 1 ("additional-markdown-reader-tests",[],[]) [Str "Additional",Space,Str "markdown",Space,Str "reader",Space,Str "tests"]
1+Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "Author",Space,Str "One"],MetaInlines [Str "Author",Space,Str "Two"],MetaInlines [Str "Author",Space,Str "Three"],MetaInlines [Str "Author",Space,Str "Four"]]),("title",MetaInlines [Str "Title",SoftBreak,Str "spanning",Space,Str "multiple",Space,Str "lines"])]})
2+[Header 1 ("additional-markdown-reader-tests",[],[]) [Str "Additional",Space,Str "markdown",Space,Str "reader",Space,Str "tests"]
33,Header 2 ("blank-line-before-url-in-link-reference",[],[]) [Str "Blank",Space,Str "line",Space,Str "before",Space,Str "URL",Space,Str "in",Space,Str "link",Space,Str "reference"]
44,Para [Link ("",[],[]) [Str "foo"] ("/url",""),Space,Str "and",Space,Link ("",[],[]) [Str "bar"] ("/url","title")]
55,Header 2 ("raw-context-environments",[],[]) [Str "Raw",Space,Str "ConTeXt",Space,Str "environments"]