RST reader: better handling for headers with an anchor.
Instead of creating a div containing the header, we put the id directly on the header. This way header promotion will work properly. Closes #4240.
This commit is contained in:
parent
13f7c2cf83
commit
49007ded7b
2 changed files with 45 additions and 2 deletions
|
@ -1157,9 +1157,19 @@ anchor = try $ do
|
|||
refs <- referenceNames
|
||||
blanklines
|
||||
b <- block
|
||||
-- put identifier on next block:
|
||||
let addDiv ref = B.divWith (ref, [], [])
|
||||
return $ foldr addDiv b refs
|
||||
let emptySpanWithId id' = Span (id',[],[]) []
|
||||
-- put identifier on next block:
|
||||
case B.toList b of
|
||||
[Header lev (_,classes,kvs) txt] ->
|
||||
case reverse refs of
|
||||
[] -> return b
|
||||
(r:rs) -> return $ B.singleton $
|
||||
Header lev (r,classes,kvs)
|
||||
(txt ++ map emptySpanWithId rs)
|
||||
-- we avoid generating divs for headers,
|
||||
-- because it hides them from promoteHeader, see #4240
|
||||
_ -> return $ foldr addDiv b refs
|
||||
|
||||
headerBlock :: PandocMonad m => RSTParser m [Char]
|
||||
headerBlock = do
|
||||
|
|
33
test/command/4240.md
Normal file
33
test/command/4240.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
```
|
||||
% pandoc -f rst -s -t native
|
||||
=====
|
||||
Title
|
||||
=====
|
||||
|
||||
--------
|
||||
Subtitle
|
||||
--------
|
||||
|
||||
header1
|
||||
=======
|
||||
|
||||
header2
|
||||
-------
|
||||
|
||||
.. _id:
|
||||
|
||||
header3
|
||||
~~~~~~~
|
||||
|
||||
.. _id2:
|
||||
.. _id3:
|
||||
|
||||
header4
|
||||
~~~~~~~
|
||||
^D
|
||||
Pandoc (Meta {unMeta = fromList [("subtitle",MetaInlines [Str "Subtitle"]),("title",MetaInlines [Str "Title"])]})
|
||||
[Header 1 ("header1",[],[]) [Str "header1"]
|
||||
,Header 2 ("header2",[],[]) [Str "header2"]
|
||||
,Header 3 ("id",[],[]) [Str "header3"]
|
||||
,Header 3 ("id3",[],[]) [Str "header4",Span ("id2",[],[]) []]]
|
||||
```
|
Loading…
Reference in a new issue