diff options
author | Alexander Krotov <ilabdsf@gmail.com> | 2018-04-02 15:55:04 +0300 |
---|---|---|
committer | Alexander Krotov <ilabdsf@gmail.com> | 2018-04-02 15:58:37 +0300 |
commit | ca78d93b408c660ee1ab753e165d07acd864b5a7 (patch) | |
tree | 851bc3175a45f629f1d774e6be250eb96b3e1699 | |
parent | aca4137c4094ec921276bf50278dfc58db5634a3 (diff) | |
download | pandoc-ca78d93b408c660ee1ab753e165d07acd864b5a7.tar.gz |
Muse writer: place header IDs before header
See https://github.com/melmothx/text-amuse/issues/39
-rw-r--r-- | src/Text/Pandoc/Readers/Muse.hs | 4 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/Muse.hs | 3 | ||||
-rw-r--r-- | test/Tests/Readers/Muse.hs | 3 | ||||
-rw-r--r-- | test/Tests/Writers/Muse.hs | 4 |
4 files changed, 7 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index b43a53d60..9e2ec310d 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -363,12 +363,12 @@ separator = try $ do header :: PandocMonad m => MuseParser m (F Blocks) header = try $ do + anchorId <- option "" $ try (parseAnchor <* manyTill spaceChar eol) getPosition >>= \pos -> guard (sourceColumn pos == 1) level <- fmap length $ many1 $ char '*' guard $ level <= 5 spaceChar content <- trimInlinesF . mconcat <$> manyTill inline eol - anchorId <- option "" parseAnchor attr <- registerHeader (anchorId, [], []) (runF content def) return $ B.headerWith attr level <$> content @@ -781,12 +781,12 @@ parseAnchor = try $ do char '#' first <- letter rest <- many (letter <|> digit) - skipMany spaceChar <|> void newline return $ first:rest anchor :: PandocMonad m => MuseParser m (F Inlines) anchor = try $ do anchorId <- parseAnchor + skipMany spaceChar <|> void newline return $ return $ B.spanWith (anchorId, [], []) mempty footnote :: PandocMonad m => MuseParser m (F Inlines) diff --git a/src/Text/Pandoc/Writers/Muse.hs b/src/Text/Pandoc/Writers/Muse.hs index eaae43604..a5cb71d8c 100644 --- a/src/Text/Pandoc/Writers/Muse.hs +++ b/src/Text/Pandoc/Writers/Muse.hs @@ -241,8 +241,7 @@ blockToMuse (Header level (ident,_,_) inlines) = do then empty else "#" <> text ident <> cr let header' = text $ replicate level '*' - return $ blankline <> nowrap (header' <> space <> contents) - $$ attr' <> blankline + return $ blankline <> attr' $$ nowrap (header' <> space <> contents) <> blankline -- https://www.gnu.org/software/emacs-muse/manual/muse.html#Horizontal-Rules-and-Anchors blockToMuse HorizontalRule = return $ blankline $$ "----" $$ blankline blockToMuse (Table caption _ _ headers rows) = do diff --git a/test/Tests/Readers/Muse.hs b/test/Tests/Readers/Muse.hs index ca63a6579..56ad9f249 100644 --- a/test/Tests/Readers/Muse.hs +++ b/test/Tests/Readers/Muse.hs @@ -533,8 +533,9 @@ tests = ] =?> blockQuote (para "* Hi") , "Headers consume anchors" =: - T.unlines [ "** Foo" + T.unlines [ "; A comment to make sure anchor is not parsed as a directive" , "#bar" + , "** Foo" ] =?> headerWith ("bar",[],[]) 2 "Foo" , "Headers don't consume anchors separated with a blankline" =: diff --git a/test/Tests/Writers/Muse.hs b/test/Tests/Writers/Muse.hs index eca7ed736..33ba2b1fb 100644 --- a/test/Tests/Writers/Muse.hs +++ b/test/Tests/Writers/Muse.hs @@ -254,8 +254,8 @@ tests = [ testGroup "block elements" ] , "heading with ID" =: headerWith ("bar", [], []) 2 (text "Foo") =?> - unlines [ "** Foo" - , "#bar" + unlines [ "#bar" + , "** Foo" ] ] , "horizontal rule" =: horizontalRule =?> "----" |