diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2022-09-14 22:23:45 +0200 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2022-09-14 22:23:45 +0200 |
| commit | d79f8386d4cf6925c46e66795baee945fea695c5 (patch) | |
| tree | aff30297e415a6939aa1ea6923b9a8eb62d4faf4 | |
| parent | eb03cad6ae58d8acf9dd37dc2862de5934da3bbf (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.
| -rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 5 | ||||
| -rw-r--r-- | test/markdown-reader-more.native | 6 |
2 files changed, 6 insertions, 5 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) } -- diff --git a/test/markdown-reader-more.native b/test/markdown-reader-more.native index f200d0705..41a2e3345 100644 --- a/test/markdown-reader-more.native +++ b/test/markdown-reader-more.native @@ -357,7 +357,7 @@ Pandoc , Link ( "" , [] , [] ) [ Str "My" , Space , Str "header" ] - ( "#my-header-1" , "" ) + ( "#my-header" , "" ) , Str "." ] , Para @@ -367,7 +367,7 @@ Pandoc , Space , Str "to" , Space - , Link ( "" , [] , [] ) [ Str "it" ] ( "#my-header-1" , "" ) + , Link ( "" , [] , [] ) [ Str "it" ] ( "#my-header" , "" ) , Str "." ] , Para @@ -378,7 +378,7 @@ Pandoc , Link ( "" , [] , [] ) [ Str "case" , Space , Str "insensitive" ] - ( "#my-header-1" , "" ) + ( "#my-header" , "" ) , Str "." ] , Para |
