@@ -37,6 +37,7 @@ import Text.Pandoc.Shared
3737import Text.Pandoc.Templates (renderTemplate)
3838import Text.Pandoc.Writers.Shared
3939
40+
4041data WriterState = WriterState { defListMarker :: Text
4142 , orderedListLevel :: Int
4243 , bulletListLevel :: Int
@@ -45,6 +46,10 @@ data WriterState = WriterState { defListMarker :: Text
4546 , asciidoctorVariant :: Bool
4647 , inList :: Bool
4748 , hasMath :: Bool
49+ -- |0 is no table
50+ -- 1 is top level table
51+ -- 2 is a table in a table
52+ , tableNestingLevel :: Int
4853 }
4954
5055defaultWriterState :: WriterState
@@ -56,6 +61,7 @@ defaultWriterState = WriterState { defListMarker = "::"
5661 , asciidoctorVariant = False
5762 , inList = False
5863 , hasMath = False
64+ , tableNestingLevel = 0
5965 }
6066
6167-- | Convert Pandoc to AsciiDoc.
@@ -194,7 +200,7 @@ blockToAsciiDoc opts (BlockQuote blocks) = do
194200 else contents
195201 let bar = text "____"
196202 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
198204 let (caption, aligns, widths, headers, rows) =
199205 toLegacyTable blkCapt specs thead tbody tfoot
200206 caption' <- inlineListToAsciiDoc opts caption
@@ -236,23 +242,42 @@ blockToAsciiDoc opts (Table _ blkCapt specs thead tbody tfoot) = do
236242 $ zipWith colspec aligns widths')
237243 <> text ","
238244 <> headerspec <> text "]"
245+
246+ -- construct cells and recurse in case of nested tables
247+ parentTableLevel <- gets tableNestingLevel
248+ let currentNestingLevel = parentTableLevel + 1
249+
250+ modify $ \st -> st{ tableNestingLevel = currentNestingLevel }
251+
252+ let separator = text (if parentTableLevel == 0
253+ then "|" -- top level separator
254+ else "!") -- nested separator
255+
239256 let makeCell [Plain x] = do d <- blockListToAsciiDoc opts [Plain x]
240− return $ text "|" <> chomp d
257+ return $ separator <> chomp d
241258 makeCell [Para x] = makeCell [Plain x]
242− makeCell [] = return $ text "|"
243− makeCell bs = do d <- blockListToAsciiDoc opts bs
244− return $ text "a|" $$ d
259+ makeCell [] = return separator
260+ makeCell bs = if currentNestingLevel == 2
261+ then do
262+ --asciidoc only supports nesting once
263+ report $ BlockNotRendered block
264+ return separator
265+ else do
266+ d <- blockListToAsciiDoc opts bs
267+ return $ (text "a" <> separator) $$ d
268+
245269 let makeRow cells = hsep `fmap` mapM makeCell cells
246270 rows' <- mapM makeRow rows
247271 head' <- makeRow headers
272+ modify $ \st -> st{ tableNestingLevel = parentTableLevel }
248273 let head'' = if all null headers then empty else head'
249274 let colwidth = if writerWrapText opts == WrapAuto
250275 then writerColumns opts
251276 else 100000
252277 let maxwidth = maximum $ map offset (head':rows')
253278 let body = if maxwidth > colwidth then vsep rows' else vcat rows'
254− let border = text "|==="
255− return $
279+ let border = separator <> text "==="
280+ return $
256281 caption'' $$ tablespec $$ border $$ head'' $$ body $$ border $$ blankline
257282blockToAsciiDoc opts (BulletList items) = do
258283 inlist <- gets inList