Markdown reader: don't coalesce adjacent raw LaTeX blocks...

if they are separated by a blank line.

See lierdakil/pandoc-crossref#160 for motivation.
This commit is contained in:
John MacFarlane 2018-01-17 09:22:35 -08:00
parent fcbec16e57
commit ca8cd38bdc
3 changed files with 20 additions and 4 deletions

View file

@ -122,6 +122,13 @@ spnl = try $ do
skipSpaces skipSpaces
notFollowedBy (char '\n') notFollowedBy (char '\n')
spnl' :: PandocMonad m => ParserT [Char] st m String
spnl' = try $ do
xs <- many spaceChar
ys <- option "" $ try $ (:) <$> newline
<*> (many spaceChar <* notFollowedBy (char '\n'))
return (xs ++ ys)
indentSpaces :: PandocMonad m => MarkdownParser m String indentSpaces :: PandocMonad m => MarkdownParser m String
indentSpaces = try $ do indentSpaces = try $ do
tabStop <- getOption readerTabStop tabStop <- getOption readerTabStop
@ -1125,10 +1132,9 @@ rawTeXBlock = do
lookAhead $ try $ char '\\' >> letter lookAhead $ try $ char '\\' >> letter
result <- (B.rawBlock "context" . trim . concat <$> result <- (B.rawBlock "context" . trim . concat <$>
many1 ((++) <$> (rawConTeXtEnvironment <|> conTeXtCommand) many1 ((++) <$> (rawConTeXtEnvironment <|> conTeXtCommand)
<*> (blanklines <|> many spaceChar))) <*> spnl'))
<|> (B.rawBlock "latex" . trim . concat <$> <|> (B.rawBlock "latex" . trim . concat <$>
many1 ((++) <$> rawLaTeXBlock many1 ((++) <$> rawLaTeXBlock <*> spnl'))
<*> (blanklines <|> many spaceChar)))
return $ case B.toList result of return $ case B.toList result of
[RawBlock _ cs] [RawBlock _ cs]
| all (`elem` [' ','\t','\n']) cs -> return mempty | all (`elem` [' ','\t','\n']) cs -> return mempty

View file

@ -0,0 +1,9 @@
```
% pandoc -f markdown -t native
\listoffigures
\listoftables
^D
[RawBlock (Format "latex") "\\listoffigures"
,RawBlock (Format "latex") "\\listoftables"]
```

View file

@ -3,7 +3,8 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "Author",S
,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"] ,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"]
,Para [Link ("",[],[]) [Str "foo"] ("/url",""),Space,Str "and",Space,Link ("",[],[]) [Str "bar"] ("/url","title")] ,Para [Link ("",[],[]) [Str "foo"] ("/url",""),Space,Str "and",Space,Link ("",[],[]) [Str "bar"] ("/url","title")]
,Header 2 ("raw-context-environments",[],[]) [Str "Raw",Space,Str "ConTeXt",Space,Str "environments"] ,Header 2 ("raw-context-environments",[],[]) [Str "Raw",Space,Str "ConTeXt",Space,Str "environments"]
,RawBlock (Format "context") "\\placeformula \\startformula\n L_{1} = L_{2}\n \\stopformula\n\n\\start[a2]\n\\start[a2]\n\\stop[a2]\n\\stop[a2]" ,RawBlock (Format "context") "\\placeformula \\startformula\n L_{1} = L_{2}\n \\stopformula"
,RawBlock (Format "context") "\\start[a2]\n\\start[a2]\n\\stop[a2]\n\\stop[a2]"
,Header 2 ("raw-latex-environments",[],[]) [Str "Raw",Space,Str "LaTeX",Space,Str "environments"] ,Header 2 ("raw-latex-environments",[],[]) [Str "Raw",Space,Str "LaTeX",Space,Str "environments"]
,RawBlock (Format "latex") "\\begin{center}\n\\begin{tikzpicture}[baseline={([yshift=+-.5ex]current bounding box.center)}, level distance=24pt]\n\\Tree [.{S} [.NP John\\index{i} ] [.VP [.V likes ] [.NP himself\\index{i,*j} ]]]\n\\end{tikzpicture}\n\\end{center}" ,RawBlock (Format "latex") "\\begin{center}\n\\begin{tikzpicture}[baseline={([yshift=+-.5ex]current bounding box.center)}, level distance=24pt]\n\\Tree [.{S} [.NP John\\index{i} ] [.VP [.V likes ] [.NP himself\\index{i,*j} ]]]\n\\end{tikzpicture}\n\\end{center}"
,Header 2 ("urls-with-spaces-and-punctuation",[],[]) [Str "URLs",Space,Str "with",Space,Str "spaces",Space,Str "and",Space,Str "punctuation"] ,Header 2 ("urls-with-spaces-and-punctuation",[],[]) [Str "URLs",Space,Str "with",Space,Str "spaces",Space,Str "and",Space,Str "punctuation"]