From 1ca320e249ab72a33e46ca1e73d36b1a818ce008 Mon Sep 17 00:00:00 2001
From: Alexander Krotov <ilabdsf@gmail.com>
Date: Fri, 26 Oct 2018 16:30:15 +0300
Subject: [PATCH] Muse reader: parse page breaks

---
 src/Text/Pandoc/Readers/Muse.hs | 10 +++++++++-
 test/Tests/Readers/Muse.hs      |  8 ++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs
index 818f66e20..29a6882dd 100644
--- a/src/Text/Pandoc/Readers/Muse.hs
+++ b/src/Text/Pandoc/Readers/Muse.hs
@@ -32,7 +32,6 @@ Conversion of Muse text to 'Pandoc' document.
 -}
 {-
 TODO:
-- Page breaks (five "*")
 - Org tables
 - table.el tables
 - <cite> tag
@@ -312,6 +311,7 @@ blockElements :: PandocMonad m => MuseParser m (F Blocks)
 blockElements = (mempty <$ blankline)
             <|> comment
             <|> separator
+            <|> pagebreak
             <|> example
             <|> exampleTag
             <|> literalTag
@@ -342,6 +342,14 @@ separator = try $ pure B.horizontalRule
   <* many spaceChar
   <* eol
 
+-- | Parse a page break
+pagebreak :: PandocMonad m => MuseParser m (F Blocks)
+pagebreak = try $ pure (B.divWith ("", [], [("style", "page-break-before: always;")]) mempty)
+  <$ count 6 spaceChar
+  <* many spaceChar
+  <* string "* * * * *"
+  <* manyTill spaceChar eol
+
 headingStart :: PandocMonad m => MuseParser m (String, Int)
 headingStart = try $ (,)
   <$> option "" (try (parseAnchor <* manyTill spaceChar eol))
diff --git a/test/Tests/Readers/Muse.hs b/test/Tests/Readers/Muse.hs
index 36724b33c..492b5baaa 100644
--- a/test/Tests/Readers/Muse.hs
+++ b/test/Tests/Readers/Muse.hs
@@ -279,6 +279,14 @@ tests =
         , "5 dashes is a horizontal rule" =: "-----" =?> horizontalRule
         , "4 dashes with spaces is a horizontal rule" =: "----  " =?> horizontalRule
         ]
+      , testGroup "Page breaks"
+        [ "Page break" =:
+          "      * * * * *" =?>
+          divWith ("", [], [("style", "page-break-before: always;")]) mempty
+        , "Page break with trailing space" =:
+          "      * * * * * " =?>
+          divWith ("", [], [("style", "page-break-before: always;")]) mempty
+        ]
       , testGroup "Paragraphs"
         [ "Simple paragraph" =:
           T.unlines [ "First line"