diff options
Diffstat (limited to 'Text/Pandoc')
-rw-r--r-- | Text/Pandoc/Readers/LaTeX.hs | 25 | ||||
-rw-r--r-- | Text/Pandoc/Readers/Markdown.hs | 25 |
2 files changed, 37 insertions, 13 deletions
diff --git a/Text/Pandoc/Readers/LaTeX.hs b/Text/Pandoc/Readers/LaTeX.hs index c45b18d5b..2ce0204ee 100644 --- a/Text/Pandoc/Readers/LaTeX.hs +++ b/Text/Pandoc/Readers/LaTeX.hs @@ -30,7 +30,7 @@ Conversion of LaTeX to 'Pandoc' document. module Text.Pandoc.Readers.LaTeX ( readLaTeX, rawLaTeXInline, - rawLaTeXEnvironment + rawLaTeXEnvironment' ) where import Text.ParserCombinators.Parsec @@ -92,13 +92,12 @@ begin name = try $ do end :: [Char] -> GenParser Char st [Char] end name = try $ do string $ "\\end{" ++ name ++ "}" - spaces return name -- | Returns a list of block elements containing the contents of an -- environment. environment :: [Char] -> GenParser Char ParserState [Block] -environment name = try $ begin name >> spaces >> manyTill block (end name) +environment name = try $ begin name >> spaces >> manyTill block (end name) >>~ spaces anyEnvironment :: GenParser Char ParserState Block anyEnvironment = try $ do @@ -109,6 +108,7 @@ anyEnvironment = try $ do optional commandArgs spaces contents <- manyTill block (end (name ++ star)) + spaces return $ BlockQuote contents -- @@ -377,7 +377,15 @@ specialEnvironment = do -- these are always parsed as raw -- | Parse any LaTeX environment and return a Para block containing -- the whole literal environment as raw TeX. rawLaTeXEnvironment :: GenParser Char st Block -rawLaTeXEnvironment = try $ do +rawLaTeXEnvironment = do + contents <- rawLaTeXEnvironment' + spaces + return $ Para [TeX contents] + +-- | Parse any LaTeX environment and return a string containing +-- the whole literal environment as raw TeX. +rawLaTeXEnvironment' :: GenParser Char st String +rawLaTeXEnvironment' = try $ do string "\\begin{" name <- many1 letter star <- option "" (string "*") -- for starred variants @@ -386,14 +394,11 @@ rawLaTeXEnvironment = try $ do args <- option [] commandArgs let argStr = concat args contents <- manyTill (choice [ (many1 (noneOf "\\")), - (do - (Para [TeX s]) <- rawLaTeXEnvironment - return s), + rawLaTeXEnvironment', string "\\" ]) (end name') - spaces - return $ Para [TeX $ "\\begin{" ++ name' ++ "}" ++ argStr ++ - concat contents ++ "\\end{" ++ name' ++ "}"] + return $ "\\begin{" ++ name' ++ "}" ++ argStr ++ + concat contents ++ "\\end{" ++ name' ++ "}" unknownEnvironment :: GenParser Char ParserState Block unknownEnvironment = try $ do diff --git a/Text/Pandoc/Readers/Markdown.hs b/Text/Pandoc/Readers/Markdown.hs index cf1053628..ac7096d37 100644 --- a/Text/Pandoc/Readers/Markdown.hs +++ b/Text/Pandoc/Readers/Markdown.hs @@ -38,7 +38,7 @@ import Data.Char ( isAlphaNum, isAlpha, isLower, isDigit ) import Data.Maybe import Text.Pandoc.Definition import Text.Pandoc.Shared -import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXEnvironment ) +import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXEnvironment' ) import Text.Pandoc.Readers.HTML ( rawHtmlBlock, anyHtmlBlockTag, anyHtmlInlineTag, anyHtmlTag, anyHtmlEndTag, htmlEndTag, extractTagType, @@ -272,7 +272,6 @@ block = do , bulletList , orderedList , definitionList - , rawLaTeXEnvironment , para , rawHtmlBlocks , plain @@ -1144,7 +1143,27 @@ inlineNote = try $ do return $ Note [Para contents] rawLaTeXInline' :: GenParser Char ParserState Inline -rawLaTeXInline' = failIfStrict >> rawLaTeXInline +rawLaTeXInline' = do + failIfStrict + (rawConTeXtEnvironment' >>= return . TeX) + <|> (rawLaTeXEnvironment' >>= return . TeX) + <|> rawLaTeXInline + +rawConTeXtEnvironment' :: GenParser Char st String +rawConTeXtEnvironment' = try $ do + string "\\start" + completion <- inBrackets (letter <|> digit <|> spaceChar) + <|> (many1 letter) + contents <- manyTill (rawConTeXtEnvironment' <|> (count 1 anyChar)) + (try $ string "\\stop" >> string completion) + return $ "\\start" ++ completion ++ concat contents ++ "\\stop" ++ completion + +inBrackets :: (GenParser Char st Char) -> GenParser Char st String +inBrackets parser = do + char '[' + contents <- many parser + char ']' + return $ "[" ++ contents ++ "]" rawHtmlInline' :: GenParser Char ParserState Inline rawHtmlInline' = do |