aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Readers/Man.hs4
-rw-r--r--src/Text/Pandoc/Readers/Roff.hs12
2 files changed, 10 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/Man.hs b/src/Text/Pandoc/Readers/Man.hs
index 665679c4d..3644050c7 100644
--- a/src/Text/Pandoc/Readers/Man.hs
+++ b/src/Text/Pandoc/Readers/Man.hs
@@ -52,7 +52,7 @@ import Text.Pandoc.Shared (crFilter)
import Text.Pandoc.Readers.Roff -- TODO explicit imports
import Text.Parsec hiding (tokenPrim)
import qualified Text.Parsec as Parsec
-import Text.Parsec.Pos (updatePosString)
+import Text.Parsec.Pos (updatePosString, initialPos)
import qualified Data.Foldable as Foldable
data ManState = ManState { readerOptions :: ReaderOptions
@@ -69,7 +69,7 @@ type ManParser m = ParserT [RoffToken] ManState m
-- | Read man (troff) from an input string and return a Pandoc document.
readMan :: PandocMonad m => ReaderOptions -> T.Text -> m Pandoc
readMan opts txt = do
- tokenz <- lexRoff (crFilter txt)
+ tokenz <- lexRoff (initialPos "input") (crFilter txt)
let state = def {readerOptions = opts} :: ManState
eitherdoc <- readWithMTokens parseMan state
(Foldable.toList . unRoffTokens $ tokenz)
diff --git a/src/Text/Pandoc/Readers/Roff.hs b/src/Text/Pandoc/Readers/Roff.hs
index a98678a30..e83821ed4 100644
--- a/src/Text/Pandoc/Readers/Roff.hs
+++ b/src/Text/Pandoc/Readers/Roff.hs
@@ -311,6 +311,7 @@ lexComment = do
lexMacro :: PandocMonad m => RoffLexer m RoffTokens
lexMacro = do
pos <- getPosition
+ guard $ sourceColumn pos == 1
char '.' <|> char '\''
skipMany spacetab
macroName <- many (satisfy (not . isSpace))
@@ -369,7 +370,9 @@ lexTableRows = do
return $ zip aligns rows
tableCell :: PandocMonad m => RoffLexer m RoffTokens
-tableCell = (enclosedCell <|> simpleCell) >>= lexRoff . T.pack
+tableCell = do
+ pos <- getPosition
+ (enclosedCell <|> simpleCell) >>= lexRoff pos . T.pack
where
enclosedCell = do
try (string "T{")
@@ -642,9 +645,10 @@ linePartsToString = mconcat . map go
go _ = mempty
-- | Tokenize a string as a sequence of groff tokens.
-lexRoff :: PandocMonad m => T.Text -> m RoffTokens
-lexRoff txt = do
- eithertokens <- readWithM (mconcat <$> many manToken) def (T.unpack txt)
+lexRoff :: PandocMonad m => SourcePos -> T.Text -> m RoffTokens
+lexRoff pos txt = do
+ eithertokens <- readWithM (do setPosition pos
+ mconcat <$> many manToken) def (T.unpack txt)
case eithertokens of
Left e -> throwError e
Right tokenz -> return tokenz