From f5e26e4512c1a797fa3a20cbc451f5d56b248870 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 27 Oct 2018 11:03:03 -0700 Subject: Roff tokenizer: check for first-column before parsing macro. Also add SourcePos as argument to lexRoff, so we can pass in current source pos when parsing a table cell. Closes #5025. --- src/Text/Pandoc/Readers/Roff.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/Text/Pandoc/Readers/Roff.hs') 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 -- cgit v1.2.3