diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-11-02 22:42:12 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-11-02 22:42:58 -0700 |
commit | 65129f33fdb469ede372560d0b39f07343c9c1b3 (patch) | |
tree | 046434bae5483a646e111d1a9db0f749b83f20c0 /src/Text/Pandoc | |
parent | 43a0734f623e8ed782500e58269510a04fcf7c3f (diff) | |
download | pandoc-65129f33fdb469ede372560d0b39f07343c9c1b3.tar.gz |
Roff reader: reinstate column check for macros.
If .TS occurs in a table cell, this shouldn't
start a table.
We make an exception for the line after .if or .ie.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers/Roff.hs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/Roff.hs b/src/Text/Pandoc/Readers/Roff.hs index f2eb81bdb..179394e55 100644 --- a/src/Text/Pandoc/Readers/Roff.hs +++ b/src/Text/Pandoc/Readers/Roff.hs @@ -48,7 +48,7 @@ where import Prelude import Safe (lastDef) -import Control.Monad (void, mzero, mplus) +import Control.Monad (void, mzero, mplus, guard) import Control.Monad.Except (throwError) import Text.Pandoc.Class (getResourcePath, readFileFromDirs, PandocMonad(..), report) @@ -117,12 +117,13 @@ data RoffMode = NormalMode | CopyMode deriving Show -data RoffState = RoffState { customMacros :: M.Map String RoffTokens - , prevFont :: FontSpec - , currentFont :: FontSpec - , tableTabChar :: Char - , roffMode :: RoffMode - , lastExpression :: Maybe Bool +data RoffState = RoffState { customMacros :: M.Map String RoffTokens + , prevFont :: FontSpec + , currentFont :: FontSpec + , tableTabChar :: Char + , roffMode :: RoffMode + , lastExpression :: Maybe Bool + , afterConditional :: Bool } deriving Show instance Default RoffState where @@ -139,6 +140,7 @@ instance Default RoffState where , tableTabChar = '\t' , roffMode = NormalMode , lastExpression = Nothing + , afterConditional = False } type RoffLexer m = ParserT [Char] RoffState m @@ -364,8 +366,8 @@ lexComment = do lexMacro :: PandocMonad m => RoffLexer m RoffTokens lexMacro = do pos <- getPosition - -- we don't want this because of '.ie .B foo': - -- guard $ sourceColumn pos == 1 + st <- getState + guard $ sourceColumn pos == 1 || afterConditional st char '.' <|> char '\'' skipMany spacetab macroName <- many (satisfy (not . isSpace)) @@ -510,7 +512,11 @@ lexConditional mname = do else expression skipMany spacetab st <- getState -- save state, so we can reset it - ifPart <- lexGroup <|> (optional (try (char '\\' >> newline)) >> manToken) + ifPart <- lexGroup <|> ((try (char '\\' >> newline)) >> manToken) + <|> do modifyState $ \st -> st{ afterConditional = True } + t <- manToken + modifyState $ \st -> st{ afterConditional = False } + return t case mbtest of Nothing -> do putState st -- reset state, so we don't record macros in skipped section |