git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: place header IDs before header

See https://github.com/melmothx/text-amuse/issues/39

commitca78d93b408c660ee1ab753e165d07acd864b5a7 authorAlexander Krotov <ilabdsf@gmail.com> dateMon 2 Apr 2018, 15:55 (9 years ago) parentaca4137
4 files changed+7−7
src/Text/Pandoc/Readers/Muse.hs+2−2 src/Text/Pandoc/Writers/Muse.hs+1−2 test/Tests/Readers/Muse.hs+2−1 test/Tests/Writers/Muse.hs+2−2
src/Text/Pandoc/Readers/Muse.hs+2−2
@@ -363,12 +363,12 @@ separator = try $ do
363363
364364header :: PandocMonad m => MuseParser m (F Blocks)
365365header = try $ do
366+ anchorId <- option "" $ try (parseAnchor <* manyTill spaceChar eol)
366367 getPosition >>= \pos -> guard (sourceColumn pos == 1)
367368 level <- fmap length $ many1 $ char '*'
368369 guard $ level <= 5
369370 spaceChar
370371 content <- trimInlinesF . mconcat <$> manyTill inline eol
371− anchorId <- option "" parseAnchor
372372 attr <- registerHeader (anchorId, [], []) (runF content def)
373373 return $ B.headerWith attr level <$> content
374374
@@ -781,12 +781,12 @@ parseAnchor = try $ do
781781 char '#'
782782 first <- letter
783783 rest <- many (letter <|> digit)
784− skipMany spaceChar <|> void newline
785784 return $ first:rest
786785
787786anchor :: PandocMonad m => MuseParser m (F Inlines)
788787anchor = try $ do
789788 anchorId <- parseAnchor
789+ skipMany spaceChar <|> void newline
790790 return $ return $ B.spanWith (anchorId, [], []) mempty
791791
792792footnote :: PandocMonad m => MuseParser m (F Inlines)
src/Text/Pandoc/Writers/Muse.hs+1−2
@@ -241,8 +241,7 @@ blockToMuse (Header level (ident,_,_) inlines) = do
241241 then empty
242242 else "#" <> text ident <> cr
243243 let header' = text $ replicate level '*'
244− return $ blankline <> nowrap (header' <> space <> contents)
245− $$ attr' <> blankline
244+ return $ blankline <> attr' $$ nowrap (header' <> space <> contents) <> blankline
246245-- https://www.gnu.org/software/emacs-muse/manual/muse.html#Horizontal-Rules-and-Anchors
247246blockToMuse HorizontalRule = return $ blankline $$ "----" $$ blankline
248247blockToMuse (Table caption _ _ headers rows) = do
test/Tests/Readers/Muse.hs+2−1
@@ -533,8 +533,9 @@ tests =
533533 ] =?>
534534 blockQuote (para "* Hi")
535535 , "Headers consume anchors" =:
536− T.unlines [ "** Foo"
536+ T.unlines [ "; A comment to make sure anchor is not parsed as a directive"
537537 , "#bar"
538+ , "** Foo"
538539 ] =?>
539540 headerWith ("bar",[],[]) 2 "Foo"
540541 , "Headers don't consume anchors separated with a blankline" =:
test/Tests/Writers/Muse.hs+2−2
@@ -254,8 +254,8 @@ tests = [ testGroup "block elements"
254254 ]
255255 , "heading with ID" =:
256256 headerWith ("bar", [], []) 2 (text "Foo") =?>
257− unlines [ "** Foo"
258− , "#bar"
257+ unlines [ "#bar"
258+ , "** Foo"
259259 ]
260260 ]
261261 , "horizontal rule" =: horizontalRule =?> "----"