aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-11-03 12:22:01 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-11-03 12:22:01 -0700
commit7ac9c3999678e545ea408200a6d503775366d467 (patch)
tree4fa31743d87ad315e96593939a0189d0d9ffcd7c /src/Text
parent2f652638516fb82fd809842517c07d620e18c40c (diff)
downloadpandoc-7ac9c3999678e545ea408200a6d503775366d467.tar.gz
AsciiDoc writer: prevent illegal nestings.
In asciidoc you can only have level n+1 headers directly under level n headers.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/AsciiDoc.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/AsciiDoc.hs b/src/Text/Pandoc/Writers/AsciiDoc.hs
index e17dad47f..3287779c7 100644
--- a/src/Text/Pandoc/Writers/AsciiDoc.hs
+++ b/src/Text/Pandoc/Writers/AsciiDoc.hs
@@ -90,7 +90,7 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do
(fmap render' . blockListToAsciiDoc opts)
(fmap render' . inlineListToAsciiDoc opts)
meta
- body <- blockListToAsciiDoc opts blocks
+ body <- vcat <$> mapM (elementToAsciiDoc 1 opts) (hierarchicalize blocks)
let main = render colwidth body
let context = defField "body" main
$ defField "toc"
@@ -101,6 +101,14 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do
Nothing -> return main
Just tpl -> renderTemplate' tpl context
+elementToAsciiDoc :: PandocMonad m
+ => Int -> WriterOptions -> Element -> ADW m Doc
+elementToAsciiDoc _ opts (Blk b) = blockToAsciiDoc opts b
+elementToAsciiDoc nestlevel opts (Sec _lvl _num attr label children) = do
+ hdr <- blockToAsciiDoc opts (Header nestlevel attr label)
+ rest <- vcat <$> mapM (elementToAsciiDoc (nestlevel + 1) opts) children
+ return $ hdr $$ rest
+
-- | Escape special characters for AsciiDoc.
escapeString :: String -> String
escapeString = escapeStringUsing escs