Muse writer: place header IDs before header

See https://github.com/melmothx/text-amuse/issues/39
This commit is contained in:
Alexander Krotov
2018-04-02 15:58:37 +03:00
parent aca4137c40
commit ca78d93b40
4 changed files with 7 additions and 7 deletions
+2 -2
View File
@@ -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)
+1 -2
View File
@@ -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
+2 -1
View File
@@ -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" =:
+2 -2
View File
@@ -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 =?> "----"