git.iko.soy/typeable/pandoc
on master help sign in
Man reader: allow block-level content in table cells.

Closes #5028.

commite96bb43ceb561628d28a87965d539b0aae2c097b authorJohn MacFarlane <jgm@berkeley.edu> dateSat 27 Oct 2018, 23:37 (8 years ago) parentf8ca365
3 files changed+51−9
src/Text/Pandoc/Readers/Man.hs+25−8 test/man-reader.man+17 test/man-reader.native+9−1
src/Text/Pandoc/Readers/Man.hs+25−8
@@ -55,13 +55,15 @@ import qualified Text.Parsec as Parsec
5555import Text.Parsec.Pos (updatePosString, initialPos)
5656import qualified Data.Foldable as Foldable
5757
58−data ManState = ManState { readerOptions :: ReaderOptions
59− , metadata :: Meta
58+data ManState = ManState { readerOptions :: ReaderOptions
59+ , metadata :: Meta
60+ , tableCellsPlain :: Bool
6061 } deriving Show
6162
6263instance Default ManState where
63− def = ManState { readerOptions = def
64− , metadata = nullMeta }
64+ def = ManState { readerOptions = def
65+ , metadata = nullMeta
66+ , tableCellsPlain = True }
6567
6668type ManParser m = ParserT [RoffToken] ManState m
6769
@@ -111,6 +113,7 @@ parseBlock = choice [ parseList
111113
112114parseTable :: PandocMonad m => ManParser m Blocks
113115parseTable = do
116+ modifyState $ \st -> st { tableCellsPlain = True }
114117 let isMTable (MTable{}) = True
115118 isMTable _ = False
116119 MTable _opts rows pos <- msatisfy isMTable
@@ -126,7 +129,12 @@ parseTable = do
126129 _ -> (([],[]), rows)
127130 headerRow <- mapM parseTableCell $ snd headerRow'
128131 bodyRows <- mapM (mapM parseTableCell . snd) bodyRows'
129− return $ B.table mempty (zip alignments (repeat 0.0))
132+ isPlainTable <- tableCellsPlain <$> getState
133+ let widths = if isPlainTable
134+ then repeat 0.0
135+ else repeat ((1.0 / fromIntegral (length alignments))
136+ :: Double)
137+ return $ B.table mempty (zip alignments widths)
130138 headerRow bodyRows) <|> fallback pos
131139 [] -> fallback pos
132140
@@ -135,14 +143,23 @@ parseTable = do
135143 parseTableCell ts = do
136144 st <- getState
137145 let ts' = Foldable.toList $ unRoffTokens ts
138− let tcell = try $ do
146+ let plaintcell = try $ do
139147 skipMany memptyLine
140148 plain . trimInlines <$> (parseInlines <* eof)
149+ let blockstcell = try $ do
150+ skipMany memptyLine
151+ mconcat <$> many parseBlock <* eof
141152 res <- if null ts'
142153 then return $ Right mempty
143− else lift $ readWithMTokens tcell st ts'
154+ else lift $ readWithMTokens plaintcell st ts'
144155 case res of
145− Left _ -> fail "Could not parse table cell"
156+ Left _ -> do
157+ res' <- lift $ readWithMTokens blockstcell st ts'
158+ case res' of
159+ Left _ -> fail "Could not parse table cell"
160+ Right x -> do
161+ modifyState $ \s -> s{ tableCellsPlain = False }
162+ return x
146163 Right x -> return x
147164
148165 isHrule :: TableRow -> Bool
test/man-reader.man+17
@@ -372,3 +372,20 @@ T}@T{
3723721
373373T}
374374.TE
375+.TS
376+tab(@);
377+rl.
378+a@b
379+T{
380+.PP
381+one
382+.PP
383+two
384+T}@T{
385+.nf
386+some
387+ code
388+.fi
389+T}
390+.TE
391+
test/man-reader.native+9−1
@@ -169,4 +169,12 @@ Pandoc (Meta {unMeta = fromList [("date",MetaInlines [Str "Oct",Space,Str "17,",
169169 ,[[Plain [Str "1"]]
170170 ,[Plain [Str "1"]]
171171 ,[Plain [Str "1"]]
172− ,[Plain [Str "1"]]]]]
172+ ,[Plain [Str "1"]]]]
173+,Table [] [AlignRight,AlignLeft] [0.5,0.5]
174+ [[]
175+ ,[]]
176+ [[[Plain [Str "a"]]
177+ ,[Plain [Str "b"]]]
178+ ,[[Para [Str "one"]
179+ ,Para [Str "two"]]
180+ ,[CodeBlock ("",[],[]) "some\n code"]]]]