From 4f14802831477eea7b67ef40e60ed7eec82f69a5 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Tue, 26 Aug 2008 20:36:06 +0000 Subject: LaTeX reader: Parse "code" environments as verbatim (lhs). Refactored parsers for verbatim environments. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1414 788f1e2b-df1e-0410-8736-df70ead52e1b --- Text/Pandoc/Readers/LaTeX.hs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'Text/Pandoc/Readers') diff --git a/Text/Pandoc/Readers/LaTeX.hs b/Text/Pandoc/Readers/LaTeX.hs index 883c1bbd1..647899acf 100644 --- a/Text/Pandoc/Readers/LaTeX.hs +++ b/Text/Pandoc/Readers/LaTeX.hs @@ -189,25 +189,19 @@ hrule = oneOfStrings [ "\\begin{center}\\rule{3in}{0.4pt}\\end{center}\n\n", -- codeBlock :: GenParser Char st Block -codeBlock = codeBlock1 <|> codeBlock2 +codeBlock = choice $ map codeBlockWith ["verbatim", "Verbatim", "code"] +-- Note: Verbatim is from fancyvrb. code is used by literate Haskell. -codeBlock1 :: GenParser Char st Block -codeBlock1 = try $ do - string "\\begin{verbatim}" -- don't use begin function because it - -- gobbles whitespace +codeBlockWith :: String -> GenParser Char st Block +codeBlockWith env = try $ do + string ("\\begin{" ++ env ++ "}") -- don't use begin function because it + -- gobbles whitespace optional blanklines -- we want to gobble blank lines, but not -- leading space - contents <- manyTill anyChar (try (string "\\end{verbatim}")) + contents <- manyTill anyChar (try (string $ "\\end{" ++ env ++ "}")) spaces - return $ CodeBlock ("",[],[]) (stripTrailingNewlines contents) - -codeBlock2 :: GenParser Char st Block -codeBlock2 = try $ do - string "\\begin{Verbatim}" -- used by fancyvrb package - optional blanklines - contents <- manyTill anyChar (try (string "\\end{Verbatim}")) - spaces - return $ CodeBlock ("",[],[]) (stripTrailingNewlines contents) + let classes = if env == "code" then ["haskell"] else [] + return $ CodeBlock ("",classes,[]) (stripTrailingNewlines contents) -- -- block quotes -- cgit v1.2.3