From 8e9973b9f761262b6871206f741ac3f2a25aa6bb Mon Sep 17 00:00:00 2001 From: Yan Pas Date: Wed, 9 May 2018 19:32:50 +0300 Subject: remove debug code --- src/Text/Pandoc/Readers/Man.hs | 47 +++++++++++------------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/Man.hs b/src/Text/Pandoc/Readers/Man.hs index 23ac3aeff..70de68d1f 100644 --- a/src/Text/Pandoc/Readers/Man.hs +++ b/src/Text/Pandoc/Readers/Man.hs @@ -30,7 +30,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Conversion of man to 'Pandoc' document. -} -module Text.Pandoc.Readers.Man where +module Text.Pandoc.Readers.Man (readMan) where import Control.Monad.Except (throwError) import Data.Default (Default) @@ -39,12 +39,11 @@ import Data.Maybe (isJust, fromMaybe) import Data.List (intersperse, intercalate) import qualified Data.Text as T -import Text.Pandoc.Class (PandocMonad(..), runPure) +import Text.Pandoc.Class (PandocMonad(..)) import Text.Pandoc.Definition -import Text.Pandoc.Error (PandocError) import Text.Pandoc.Logging (LogMessage(..)) import Text.Pandoc.Options -import Text.Pandoc.Parsing hiding (enclosed) +import Text.Pandoc.Parsing import Text.Pandoc.Shared (crFilter) import Text.Parsec import Text.Parsec.Char () @@ -71,37 +70,6 @@ modifyRoffState f = do type ManParser m = ParserT [Char] ManState m -testStrr :: [Char] -> SourceName -> Either PandocError (Either ParseError Pandoc) -testStrr s srcnm = runPure (runParserT parseMan (ManState {pState=def, rState=def}) srcnm s) - -printPandoc :: Pandoc -> [Char] -printPandoc (Pandoc m content) = - let ttl = "Pandoc: " ++ (show $ unMeta m) - cnt = intercalate "\n" $ map show content - in ttl ++ "\n" ++ cnt - -strrepr :: (Show a2, Show a1) => Either a2 (Either a1 Pandoc) -> [Char] -strrepr obj = case obj of - Right x -> case x of - Right x' -> printPandoc x' - Left y' -> show y' - Left y -> show y - -testFile :: FilePath -> IO () -testFile fname = do - cont <- readFile fname - putStrLn . strrepr $ testStrr cont fname - - --- | Read man (troff) from an input string and return a Pandoc document. -readMan :: PandocMonad m => ReaderOptions -> T.Text -> m Pandoc -readMan opts txt = do - let state = ManState { pState = def{ stateOptions = opts }, rState = def} - parsed <- readWithM parseMan state (T.unpack $ crFilter txt) - case parsed of - Right result -> return result - Left e -> throwError e - parseMacro :: PandocMonad m => ManParser m Block parseMacro = do char '.' <|> char '\'' @@ -304,3 +272,12 @@ parseMan = do blocks <- createParas <$> many (parseMacro <|> parseLine) parserst <- pState <$> getState return $ Pandoc (stateMeta parserst) blocks + +-- | Read man (troff) from an input string and return a Pandoc document. +readMan :: PandocMonad m => ReaderOptions -> T.Text -> m Pandoc +readMan opts txt = do + let state = ManState { pState = def{ stateOptions = opts }, rState = def} + parsed <- readWithM parseMan state (T.unpack $ crFilter txt) + case parsed of + Right result -> return result + Left e -> throwError e -- cgit v1.2.3