git.iko.soy/typeable/pandoc
on master help sign in
Man reader: Support .so for include files.
3fa9a83John MacFarlane
src/Text/Pandoc/Readers/Man.hs+17
@@ -2,6 +2,7 @@
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-
3{-
4 Copyright (C) 2018 Yan Pashkovsky <yanp.bugz@gmail.com>
4 Copyright (C) 2018 Yan Pashkovsky <yanp.bugz@gmail.com>
5+ and John MacFarlane
5
6
6This program is free software; you can redistribute it and/or modify
7This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8it under the terms of the GNU General Public License as published by
@@ -37,6 +38,7 @@ module Text.Pandoc.Readers.Man (readMan) where
37import Prelude
38import Prelude
38import Control.Monad (liftM, void, mzero, guard)
39import Control.Monad (liftM, void, mzero, guard)
39import Control.Monad.Except (throwError)
40import Control.Monad.Except (throwError)
41+import Text.Pandoc.Class (getResourcePath, readFileFromDirs)
40import Data.Char (isHexDigit, chr, ord)
42import Data.Char (isHexDigit, chr, ord)
41import Data.Default (Default)
43import Data.Default (Default)
42import Data.Maybe (catMaybes)
44import Data.Maybe (catMaybes)
@@ -278,10 +280,25 @@ lexMacro = do
278 "\\#" -> return mempty
280 "\\#" -> return mempty
279 "de" -> lexMacroDef args
281 "de" -> lexMacroDef args
280 "sp" -> return $ singleTok MEmptyLine
282 "sp" -> return $ singleTok MEmptyLine
283+ "so" -> lexIncludeFile args
281 _ -> resolveMacro macroName args
284 _ -> resolveMacro macroName args
282
285
283 where
286 where
284
287
288+ lexIncludeFile :: PandocMonad m => [Arg] -> ManLexer m ManTokens
289+ lexIncludeFile args = do
290+ pos <- getPosition
291+ case args of
292+ (f:_) -> do
293+ let fp = linePartsToString f
294+ dirs <- getResourcePath
295+ result <- readFileFromDirs dirs fp
296+ case result of
297+ Nothing -> report $ CouldNotLoadIncludeFile fp pos
298+ Just s -> getInput >>= setInput . (s ++)
299+ return mempty
300+ [] -> return mempty
301+
285 resolveMacro :: PandocMonad m
302 resolveMacro :: PandocMonad m
286 => String -> [Arg] -> ManLexer m ManTokens
303 => String -> [Arg] -> ManLexer m ManTokens
287 resolveMacro macroName args = do
304 resolveMacro macroName args = do