git.iko.soy/typeable/pandoc
on master help sign in
Groff tokenizer: Add structured repr of table options.
commitd009a0fa525b6fa17bc34cf1a16f0b15c49366bd authorJohn MacFarlane <jgm@berkeley.edu> dateThu 25 Oct 2018, 12:35 (8 years ago) parent3175973
2 files changed+12−12
src/Text/Pandoc/Readers/Groff.hs+11−11 src/Text/Pandoc/Readers/Man.hs+1−1
src/Text/Pandoc/Readers/Groff.hs+11−11
@@ -37,6 +37,7 @@ module Text.Pandoc.Readers.Groff
3737 , defaultFontSpec
3838 , LinePart(..)
3939 , Arg
40+ , TableOption
4041 , GroffToken(..)
4142 , GroffTokens(..)
4243 , linePartsToString
@@ -87,12 +88,13 @@ data LinePart = RoffStr String
8788 deriving Show
8889
8990type Arg = [LinePart]
91+type TableOption = (String, String)
9092
9193-- TODO parse tables (see man tbl)
9294data GroffToken = MLine [LinePart]
9395 | MEmptyLine
9496 | MMacro MacroKind [Arg] SourcePos
95− | MTable [[String]] [[GroffTokens]] SourcePos
97+ | MTable [TableOption] [[String]] [[GroffTokens]] SourcePos
9698 deriving Show
9799
98100newtype GroffTokens = GroffTokens { unGroffTokens :: Seq.Seq GroffToken }
@@ -325,12 +327,15 @@ lexMacro = do
325327lexTable :: PandocMonad m => SourcePos -> GroffLexer m GroffTokens
326328lexTable pos = do
327329 spaces
328− optional tableOptions
330+ opts <- option [] tableOptions
331+ case lookup "tab" opts of
332+ Just (c:_) -> modifyState $ \st -> st{ tableTabChar = c }
333+ _ -> modifyState $ \st -> st{ tableTabChar = '\t' }
329334 spaces
330335 aligns <- tableFormatSpec
331336 spaces
332337 rows <- manyTill tableRow (try (string ".TE" >> skipMany spacetab >> eofline))
333− return $ singleTok $ MTable aligns rows pos
338+ return $ singleTok $ MTable opts aligns rows pos
334339
335340tableCell :: PandocMonad m => GroffLexer m GroffTokens
336341tableCell = (enclosedCell <|> simpleCell) >>= lexGroff . T.pack
@@ -351,15 +356,10 @@ tableRow = do
351356 eofline
352357 return (c:cs)
353358
354−tableOptions :: PandocMonad m => GroffLexer m ()
355−tableOptions = try $ do
356− opts <- many1 tableOption <* spaces <* char ';'
357− case lookup "tab" opts of
358− Just (c:_) -> modifyState $ \st -> st{ tableTabChar = c }
359− _ -> modifyState $ \st -> st{ tableTabChar = '\t' }
360− return ()
359+tableOptions :: PandocMonad m => GroffLexer m [TableOption]
360+tableOptions = try $ many1 tableOption <* spaces <* char ';'
361361
362−tableOption :: PandocMonad m => GroffLexer m (String, String)
362+tableOption :: PandocMonad m => GroffLexer m TableOption
363363tableOption = do
364364 k <- many1 letter
365365 v <- option "" $ do
src/Text/Pandoc/Readers/Man.hs+1−1
@@ -113,7 +113,7 @@ parseTable :: PandocMonad m => ManParser m Blocks
113113parseTable = do
114114 let isMTable (MTable{}) = True
115115 isMTable _ = False
116− MTable _aligns _rows pos <- msatisfy isMTable
116+ MTable _opts _aligns _rows pos <- msatisfy isMTable
117117 report $ SkippedContent "TABLE" pos
118118 return $ B.para (B.text "TABLE")
119119