git.iko.soy/typeable/pandoc
on master help sign in
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.

commit49007ded7b7a64cf9c875f23e9c59a966e1284c8 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 10 Jan 2018, 12:07 (9 years ago) parent13f7c2c
2 files changed+45−2
src/Text/Pandoc/Readers/RST.hs+12−2 test/command/4240.md+33
src/Text/Pandoc/Readers/RST.hs+12−2
@@ -1157,9 +1157,19 @@ anchor = try $ do
11571157 refs <- referenceNames
11581158 blanklines
11591159 b <- block
1160− -- put identifier on next block:
11611160 let addDiv ref = B.divWith (ref, [], [])
1162− return $ foldr addDiv b refs
1161+ let emptySpanWithId id' = Span (id',[],[]) []
1162+ -- put identifier on next block:
1163+ case B.toList b of
1164+ [Header lev (_,classes,kvs) txt] ->
1165+ case reverse refs of
1166+ [] -> return b
1167+ (r:rs) -> return $ B.singleton $
1168+ Header lev (r,classes,kvs)
1169+ (txt ++ map emptySpanWithId rs)
1170+ -- we avoid generating divs for headers,
1171+ -- because it hides them from promoteHeader, see #4240
1172+ _ -> return $ foldr addDiv b refs
11631173
11641174headerBlock :: PandocMonad m => RSTParser m [Char]
11651175headerBlock = do
test/command/4240.mdnew file+33
@@ -0,0 +1,33 @@
1+```
2+% pandoc -f rst -s -t native
3+=====
4+Title
5+=====
6+
7+--------
8+Subtitle
9+--------
10+
11+header1
12+=======
13+
14+header2
15+-------
16+
17+.. _id:
18+
19+header3
20+~~~~~~~
21+
22+.. _id2:
23+.. _id3:
24+
25+header4
26+~~~~~~~
27+^D
28+Pandoc (Meta {unMeta = fromList [("subtitle",MetaInlines [Str "Subtitle"]),("title",MetaInlines [Str "Title"])]})
29+[Header 1 ("header1",[],[]) [Str "header1"]
30+,Header 2 ("header2",[],[]) [Str "header2"]
31+,Header 3 ("id",[],[]) [Str "header3"]
32+,Header 3 ("id3",[],[]) [Str "header4",Span ("id2",[],[]) []]]
33+```