git.iko.soy/typeable/pandoc
on master help sign in
Improved behavior of `auto_identifiers` when there are explicit ids.

Previously only autogenerated ids were added to the list of header identifiers in state, so explicit ids weren't taken into account when generating unique identifiers. Duplicated identifiers could result. This simple fix ensures that explicitly given identifiers are also taken into account. Fixes #1745. Note some limitations, however. An autogenerated identifier may still coincide with an explicit identifier that is given for a header later in the document, or with an identifier on a div, span, link, or image. Fixing this would be much more difficult, because we need to run `registerHeader` before we have the complete parse tree (so we can't get a complete list of identifiers from the document by walking the tree). However, it might be worth issuing warnings for duplicate header identifiers; I think we can do that. It is not common for headers to have the same text, and the issue can always be worked around by adding explicit identifiers, if the user is aware of it.

commitc8b906256dccc7b0572c1707dee9b211c86e996d authorJohn MacFarlane <jgm@berkeley.edu> dateSun 12 Mar 2017, 21:30 (10 years ago) parent3765f08
2 files changed+15−1
src/Text/Pandoc/Parsing.hs+2−1 test/command/1745.md+13
src/Text/Pandoc/Parsing.hs+2−1
@@ -1130,7 +1130,8 @@ registerHeader (ident,classes,kvs) header' = do
11301130 updateState $ updateHeaderMap $ insert' header' id'
11311131 return (id'',classes,kvs)
11321132 else do
1133− unless (null ident) $
1133+ unless (null ident) $ do
1134+ updateState $ updateIdentifierList $ Set.insert ident
11341135 updateState $ updateHeaderMap $ insert' header' ident
11351136 return (ident,classes,kvs)
11361137
test/command/1745.mdnew file+13
@@ -0,0 +1,13 @@
1+```
2+% pandoc -f latex+auto_identifiers -t html
3+\section{Six favourite beers}
4+\subsection{Jovaru Alus}\label{jovaru-alus}
5+\section{Farmhouse brewers}
6+\subsection{Jovaru Alus}
7+^D
8+<h1 id="six-favourite-beers">Six favourite beers</h1>
9+<h2 id="jovaru-alus">Jovaru Alus</h2>
10+<h1 id="farmhouse-brewers">Farmhouse brewers</h1>
11+<h2 id="jovaru-alus-1">Jovaru Alus</h2>
12+```
13+