From 49007ded7b7a64cf9c875f23e9c59a966e1284c8 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 10 Jan 2018 12:07:33 -0800 Subject: [PATCH] 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. --- src/Text/Pandoc/Readers/RST.hs | 14 ++++++++++++-- test/command/4240.md | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 test/command/4240.md diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 27ce5fa2d..ba5a24f8f 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -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 diff --git a/test/command/4240.md b/test/command/4240.md new file mode 100644 index 000000000..39a7d2adf --- /dev/null +++ b/test/command/4240.md @@ -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",[],[]) []]] +```