git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: Insert HTML comment btw list and indented code block.

This prevents the code block from being interpreted as part of the list.

commitda2301387f9891b3b1231a3d7178bd31f973a968 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 6 Jun 2011, 05:56 (15 years ago) parent8d54e30
2 files changed+15−1
src/Text/Pandoc/Writers/Markdown.hs+13−1 src/test-pandoc.hs+2
src/Text/Pandoc/Writers/Markdown.hs+13−1
@@ -366,7 +366,19 @@ blockListToMarkdown :: WriterOptions -- ^ Options
366366 -> [Block] -- ^ List of block elements
367367 -> State WriterState Doc
368368blockListToMarkdown opts blocks =
369− mapM (blockToMarkdown opts) blocks >>= return . cat
369+ mapM (blockToMarkdown opts) (fixBlocks blocks) >>= return . cat
370+ -- insert comment between list and indented code block, or the
371+ -- code block will be treated as a list continuation paragraph
372+ where fixBlocks (b : CodeBlock attr x : rest)
373+ | (writerStrictMarkdown opts || attr == nullAttr) && isListBlock b =
374+ b : RawBlock "html" "<!-- -->\n" : CodeBlock attr x :
375+ fixBlocks rest
376+ fixBlocks (x : xs) = x : fixBlocks xs
377+ fixBlocks [] = []
378+ isListBlock (BulletList _) = True
379+ isListBlock (OrderedList _ _) = True
380+ isListBlock (DefinitionList _) = True
381+ isListBlock _ = False
370382
371383-- | Get reference for target; if none exists, create unique one and return.
372384-- Prefer label if possible; otherwise, generate a unique key.
src/test-pandoc.hs+2
@@ -11,6 +11,7 @@ import qualified Tests.Readers.RST
1111import qualified Tests.Writers.ConTeXt
1212import qualified Tests.Writers.HTML
1313import qualified Tests.Writers.Native
14+import qualified Tests.Writers.Markdown
1415import qualified Tests.Shared
1516
1617tests :: [Test]
@@ -20,6 +21,7 @@ tests = [ testGroup "Old" Tests.Old.tests
2021 [ testGroup "Native" Tests.Writers.Native.tests
2122 , testGroup "ConTeXt" Tests.Writers.ConTeXt.tests
2223 , testGroup "HTML" Tests.Writers.HTML.tests
24+ , testGroup "Markdown" Tests.Writers.Markdown.tests
2325 ]
2426 , testGroup "Readers"
2527 [ testGroup "LaTeX" Tests.Readers.LaTeX.tests