git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Support alltt environment.

Closes #892.

commit82e46bf3852b776defab85f3347115260d332250 authorJohn MacFarlane <fiddlosopher@gmail.com> dateThu 27 Jun 2013, 18:54 (13 years ago) parent79a4ea0
1 file changed+12−2
src/Text/Pandoc/Readers/LaTeX.hs+12−2
src/Text/Pandoc/Readers/LaTeX.hs+12−2
@@ -35,6 +35,7 @@ module Text.Pandoc.Readers.LaTeX ( readLaTeX,
3535 ) where
3636
3737import Text.Pandoc.Definition
38+import Text.Pandoc.Generic
3839import Text.Pandoc.Shared
3940import Text.Pandoc.Options
4041import Text.Pandoc.Biblio (processBiblio)
@@ -48,7 +49,7 @@ import Control.Applicative
4849import Data.Monoid
4950import System.Environment (getEnv)
5051import System.FilePath (replaceExtension, (</>))
51−import Data.List (intercalate)
52+import Data.List (intercalate, intersperse)
5253import qualified Data.Map as M
5354import qualified Control.Exception as E
5455import System.FilePath (takeExtension, addExtension)
@@ -776,13 +777,21 @@ keyval = try $ do
776777keyvals :: LP [(String, String)]
777778keyvals = try $ char '[' *> manyTill keyval (char ']')
778779
780+alltt :: String -> LP Blocks
781+alltt t = bottomUp strToCode <$> parseFromString blocks
782+ (substitute " " "\\ " $ substitute "%" "\\%" $
783+ concat $ intersperse "\\\\\n" $ lines t)
784+ where strToCode (Str s) = Code nullAttr s
785+ strToCode x = x
786+
779787verbatimEnv :: LP (String, String)
780788verbatimEnv = do
781789 (_,r) <- withRaw $ do
782790 controlSeq "begin"
783791 name <- braced
784792 guard $ name == "verbatim" || name == "Verbatim" ||
785− name == "lstlisting" || name == "minted"
793+ name == "lstlisting" || name == "minted" ||
794+ name == "alltt"
786795 verbEnv name
787796 rest <- getInput
788797 return (r,rest)
@@ -808,6 +817,7 @@ environments = M.fromList
808817 , ("itemize", bulletList <$> listenv "itemize" (many item))
809818 , ("description", definitionList <$> listenv "description" (many descItem))
810819 , ("enumerate", ordered_list)
820+ , ("alltt", alltt =<< verbEnv "alltt")
811821 , ("code", guardEnabled Ext_literate_haskell *>
812822 (codeBlockWith ("",["sourceCode","literate","haskell"],[]) <$>
813823 verbEnv "code"))