aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2022-09-14 22:23:45 +0200
committerJohn MacFarlane <[email protected]>2022-09-14 22:23:45 +0200
commitd79f8386d4cf6925c46e66795baee945fea695c5 (patch)
treeaff30297e415a6939aa1ea6923b9a8eb62d4faf4 /src
parenteb03cad6ae58d8acf9dd37dc2862de5934da3bbf (diff)
Fix implicit_header_references with duplicate headings.
Documentation says that when more than one heading has the same text, an implicit reference `[Heading text][]` refers to the first one. Previously pandoc linked to the last one instead. This patch makes pandoc conform to the documented behavior. See #8300.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index b1e7dfdcc..3a63beb04 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -582,8 +582,9 @@ registerImplicitHeader raw attr@(ident, _, _)
| T.null raw = return ()
| otherwise = do
let key = toKey $ "[" <> raw <> "]"
- updateState $ \s ->
- s { stateHeaderKeys = M.insert key (("#" <> ident,""), attr)
+ updateState $ \s -> -- don't override existing headers
+ s { stateHeaderKeys = M.insertWith (\_new old -> old)
+ key (("#" <> ident,""), attr)
(stateHeaderKeys s) }
--