aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-10-25 12:35:58 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-10-25 12:35:58 -0700
commitd009a0fa525b6fa17bc34cf1a16f0b15c49366bd (patch)
treef1c4930a8cc774b009a92e1f59d166b2a304f713 /src/Text/Pandoc
parent31759731e754de9b37131229f65a5f8787b53a5d (diff)
downloadpandoc-d009a0fa525b6fa17bc34cf1a16f0b15c49366bd.tar.gz
Groff tokenizer: Add structured repr of table options.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/Groff.hs22
-rw-r--r--src/Text/Pandoc/Readers/Man.hs2
2 files changed, 12 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Readers/Groff.hs b/src/Text/Pandoc/Readers/Groff.hs
index e48f53432..9609a490f 100644
--- a/src/Text/Pandoc/Readers/Groff.hs
+++ b/src/Text/Pandoc/Readers/Groff.hs
@@ -37,6 +37,7 @@ module Text.Pandoc.Readers.Groff
, defaultFontSpec
, LinePart(..)
, Arg
+ , TableOption
, GroffToken(..)
, GroffTokens(..)
, linePartsToString
@@ -87,12 +88,13 @@ data LinePart = RoffStr String
deriving Show
type Arg = [LinePart]
+type TableOption = (String, String)
-- TODO parse tables (see man tbl)
data GroffToken = MLine [LinePart]
| MEmptyLine
| MMacro MacroKind [Arg] SourcePos
- | MTable [[String]] [[GroffTokens]] SourcePos
+ | MTable [TableOption] [[String]] [[GroffTokens]] SourcePos
deriving Show
newtype GroffTokens = GroffTokens { unGroffTokens :: Seq.Seq GroffToken }
@@ -325,12 +327,15 @@ lexMacro = do
lexTable :: PandocMonad m => SourcePos -> GroffLexer m GroffTokens
lexTable pos = do
spaces
- optional tableOptions
+ opts <- option [] tableOptions
+ case lookup "tab" opts of
+ Just (c:_) -> modifyState $ \st -> st{ tableTabChar = c }
+ _ -> modifyState $ \st -> st{ tableTabChar = '\t' }
spaces
aligns <- tableFormatSpec
spaces
rows <- manyTill tableRow (try (string ".TE" >> skipMany spacetab >> eofline))
- return $ singleTok $ MTable aligns rows pos
+ return $ singleTok $ MTable opts aligns rows pos
tableCell :: PandocMonad m => GroffLexer m GroffTokens
tableCell = (enclosedCell <|> simpleCell) >>= lexGroff . T.pack
@@ -351,15 +356,10 @@ tableRow = do
eofline
return (c:cs)
-tableOptions :: PandocMonad m => GroffLexer m ()
-tableOptions = try $ do
- opts <- many1 tableOption <* spaces <* char ';'
- case lookup "tab" opts of
- Just (c:_) -> modifyState $ \st -> st{ tableTabChar = c }
- _ -> modifyState $ \st -> st{ tableTabChar = '\t' }
- return ()
+tableOptions :: PandocMonad m => GroffLexer m [TableOption]
+tableOptions = try $ many1 tableOption <* spaces <* char ';'
-tableOption :: PandocMonad m => GroffLexer m (String, String)
+tableOption :: PandocMonad m => GroffLexer m TableOption
tableOption = do
k <- many1 letter
v <- option "" $ do
diff --git a/src/Text/Pandoc/Readers/Man.hs b/src/Text/Pandoc/Readers/Man.hs
index dc4ba3f52..9d40b40fb 100644
--- a/src/Text/Pandoc/Readers/Man.hs
+++ b/src/Text/Pandoc/Readers/Man.hs
@@ -113,7 +113,7 @@ parseTable :: PandocMonad m => ManParser m Blocks
parseTable = do
let isMTable (MTable{}) = True
isMTable _ = False
- MTable _aligns _rows pos <- msatisfy isMTable
+ MTable _opts _aligns _rows pos <- msatisfy isMTable
report $ SkippedContent "TABLE" pos
return $ B.para (B.text "TABLE")