From dd098d4e15090d12cc71301f91a159c5bfb29b50 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Mon, 28 Jun 2021 11:27:37 -0700
Subject: [PATCH] Markdown writer: put space between Plain and following fenced
 Div.

Closes #4465.
---
 src/Text/Pandoc/Writers/Markdown.hs |  3 +++
 test/command/4465.md                | 15 +++++++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 test/command/4465.md

diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index b13ab57ee..fda2bbcef 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -791,6 +791,9 @@ blockListToMarkdown opts blocks = do
            b1 : commentSep : fixBlocks (b2:bs)
       fixBlocks (Plain ils : bs@(RawBlock{}:_)) =
            Plain ils : fixBlocks bs
+      fixBlocks (Plain ils : bs@(Div{}:_))
+          | isEnabled Ext_fenced_divs opts =
+           Para ils : fixBlocks bs
       fixBlocks (Plain ils : bs) | inlist =
            Plain ils : fixBlocks bs
       fixBlocks (Plain ils : bs) =
diff --git a/test/command/4465.md b/test/command/4465.md
new file mode 100644
index 000000000..eaffcf7f3
--- /dev/null
+++ b/test/command/4465.md
@@ -0,0 +1,15 @@
+```
+% pandoc -f html -t markdown
+<ol>
+  <li>An ordered list can contain block-level elements ind html, it means that divs are also allowed.</li>
+  <li>Let's see the problem! <div class="example">This is an example.</div></li>
+</ol>
+^D
+1.  An ordered list can contain block-level elements ind html, it means
+    that divs are also allowed.
+2.  Let\'s see the problem!
+
+    ::: example
+    This is an example.
+    :::
+```