@@ -2,6 +2,7 @@
22{-# LANGUAGE GeneralizedNewtypeDeriving #-}
33{-
44 Copyright (C) 2018 Yan Pashkovsky <yanp.bugz@gmail.com>
5+ and John MacFarlane
56
67This program is free software; you can redistribute it and/or modify
78it under the terms of the GNU General Public License as published by
@@ -37,6 +38,7 @@ module Text.Pandoc.Readers.Man (readMan) where
3738import Prelude
3839import Control.Monad (liftM, void, mzero, guard)
3940import Control.Monad.Except (throwError)
41+import Text.Pandoc.Class (getResourcePath, readFileFromDirs)
4042import Data.Char (isHexDigit, chr, ord)
4143import Data.Default (Default)
4244import Data.Maybe (catMaybes)
@@ -278,10 +280,25 @@ lexMacro = do
278280 "\\#" -> return mempty
279281 "de" -> lexMacroDef args
280282 "sp" -> return $ singleTok MEmptyLine
283+ "so" -> lexIncludeFile args
281284 _ -> resolveMacro macroName args
282285
283286 where
284287
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+
285302 resolveMacro :: PandocMonad m
286303 => String -> [Arg] -> ManLexer m ManTokens
287304 resolveMacro macroName args = do