From c78b30bd286f49cb0a0951a1f022e2626a9295dd Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Wed, 4 Mar 2020 08:42:57 -0800
Subject: [PATCH] EPUB writer: fix regression on detection of
 front/back/bodymatter.

This bug caused sections with epub:type "dedication" to be
misplaced in bodymatter instead of frontmatter as specified
in the manual.  The same problem would affect other epub:types.

The pattern matching needed to be changed with the use of
`makeSection`.  Closes #6170.
---
 src/Text/Pandoc/Writers/EPUB.hs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
index 7605d3a4b..b000869e4 100644
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -595,7 +595,8 @@ pandocToEPUB version opts doc = do
                             <> cssvars True <> vars } pdoc
          where (pdoc, bodyType) =
                  case bs of
-                     (Header _ (_,_,kvs) xs : _) ->
+                     (Div (_,"section":_,kvs)
+                       (Header _ _ xs : _) : _) ->
                        -- remove notes or we get doubled footnotes
                        (Pandoc (setMeta "title"
                            (walk removeNote $ fromList xs) nullMeta) bs,