mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-24 15:44:59 +08:00
Muse writer: place header IDs before header
See https://github.com/melmothx/text-amuse/issues/39
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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" =:
|
||||
|
||||
@@ -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 =?> "----"
|
||||
|
||||
Reference in New Issue
Block a user