@@ -37,6 +37,7 @@ import Text.Pandoc.Shared
37import Text.Pandoc.Templates (renderTemplate)
37import Text.Pandoc.Templates (renderTemplate)
38import Text.Pandoc.Writers.Shared
38import Text.Pandoc.Writers.Shared
40data WriterState = WriterState { defListMarker :: Text
41data WriterState = WriterState { defListMarker :: Text
41 , orderedListLevel :: Int
42 , orderedListLevel :: Int
42 , bulletListLevel :: Int
43 , bulletListLevel :: Int
@@ -45,6 +46,10 @@ data WriterState = WriterState { defListMarker :: Text
45 , asciidoctorVariant :: Bool
46 , asciidoctorVariant :: Bool
46 , inList :: Bool
47 , inList :: Bool
47 , hasMath :: Bool
48 , hasMath :: Bool
50+ -- 1 is top level table
51+ -- 2 is a table in a table
52+ , tableNestingLevel :: Int
50defaultWriterState :: WriterState
55defaultWriterState :: WriterState
@@ -56,6 +61,7 @@ defaultWriterState = WriterState { defListMarker = "::"
56 , asciidoctorVariant = False
61 , asciidoctorVariant = False
57 , inList = False
62 , inList = False
58 , hasMath = False
63 , hasMath = False
64+ , tableNestingLevel = 0
61-- | Convert Pandoc to AsciiDoc.
67-- | Convert Pandoc to AsciiDoc.
@@ -194,7 +200,7 @@ blockToAsciiDoc opts (BlockQuote blocks) = do
194 else contents
200 else contents
195 let bar = text "____"
201 let bar = text "____"
196 return $ bar $$ chomp contents' $$ bar <> blankline
202 return $ bar $$ chomp contents' $$ bar <> blankline
197−blockToAsciiDoc opts (Table _ blkCapt specs thead tbody tfoot) = do
203+blockToAsciiDoc opts block@(Table _ blkCapt specs thead tbody tfoot) = do
198 let (caption, aligns, widths, headers, rows) =
204 let (caption, aligns, widths, headers, rows) =
199 toLegacyTable blkCapt specs thead tbody tfoot
205 toLegacyTable blkCapt specs thead tbody tfoot
200 caption' <- inlineListToAsciiDoc opts caption
206 caption' <- inlineListToAsciiDoc opts caption
@@ -236,23 +242,42 @@ blockToAsciiDoc opts (Table _ blkCapt specs thead tbody tfoot) = do
236 $ zipWith colspec aligns widths')
242 $ zipWith colspec aligns widths')
237 <> text ","
243 <> text ","
238 <> headerspec <> text "]"
244 <> headerspec <> text "]"
246+ -- construct cells and recurse in case of nested tables
247+ parentTableLevel <- gets tableNestingLevel
248+ let currentNestingLevel = parentTableLevel + 1
250+ modify $ \st -> st{ tableNestingLevel = currentNestingLevel }
252+ let separator = text (if parentTableLevel == 0
253+ then "|" -- top level separator
254+ else "!") -- nested separator
239 let makeCell [Plain x] = do d <- blockListToAsciiDoc opts [Plain x]
256 let makeCell [Plain x] = do d <- blockListToAsciiDoc opts [Plain x]
240− return $ text "|" <> chomp d
257+ return $ separator <> chomp d
241 makeCell [Para x] = makeCell [Plain x]
258 makeCell [Para x] = makeCell [Plain x]
242− makeCell [] = return $ text "|"
259+ makeCell [] = return separator
260+ makeCell bs = if currentNestingLevel == 2
262+ --asciidoc only supports nesting once
263+ report $ BlockNotRendered block
243− makeCell bs = do d <- blockListToAsciiDoc opts bs
266+ d <- blockListToAsciiDoc opts bs
244− return $ text "a|" $$ d
267+ return $ (text "a" <> separator) $$ d
245 let makeRow cells = hsep `fmap` mapM makeCell cells
269 let makeRow cells = hsep `fmap` mapM makeCell cells
246 rows' <- mapM makeRow rows
270 rows' <- mapM makeRow rows
247 head' <- makeRow headers
271 head' <- makeRow headers
272+ modify $ \st -> st{ tableNestingLevel = parentTableLevel }
248 let head'' = if all null headers then empty else head'
273 let head'' = if all null headers then empty else head'
249 let colwidth = if writerWrapText opts == WrapAuto
274 let colwidth = if writerWrapText opts == WrapAuto
250 then writerColumns opts
275 then writerColumns opts
251 else 100000
276 else 100000
252 let maxwidth = maximum $ map offset (head':rows')
277 let maxwidth = maximum $ map offset (head':rows')
253 let body = if maxwidth > colwidth then vsep rows' else vcat rows'
278 let body = if maxwidth > colwidth then vsep rows' else vcat rows'
254− let border = text "|==="
279+ let border = separator <> text "==="
255− return $
280+ return $
256 caption'' $$ tablespec $$ border $$ head'' $$ body $$ border $$ blankline
281 caption'' $$ tablespec $$ border $$ head'' $$ body $$ border $$ blankline
257blockToAsciiDoc opts (BulletList items) = do
282blockToAsciiDoc opts (BulletList items) = do
258 inlist <- gets inList
283 inlist <- gets inList