diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-03-12 21:30:04 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-03-12 21:30:04 +0100 |
commit | c8b906256dccc7b0572c1707dee9b211c86e996d (patch) | |
tree | 395523c54c7a8ea761c812fcc10c0e1b8541942f | |
parent | 3765f08304a642cd85691864c1fd988b6bdb1c27 (diff) | |
download | pandoc-c8b906256dccc7b0572c1707dee9b211c86e996d.tar.gz |
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.
-rw-r--r-- | src/Text/Pandoc/Parsing.hs | 3 | ||||
-rw-r--r-- | test/command/1745.md | 13 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index b207e79e0..a616058bb 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -1130,7 +1130,8 @@ registerHeader (ident,classes,kvs) header' = do updateState $ updateHeaderMap $ insert' header' id' return (id'',classes,kvs) else do - unless (null ident) $ + unless (null ident) $ do + updateState $ updateIdentifierList $ Set.insert ident updateState $ updateHeaderMap $ insert' header' ident return (ident,classes,kvs) diff --git a/test/command/1745.md b/test/command/1745.md new file mode 100644 index 000000000..cf987c20f --- /dev/null +++ b/test/command/1745.md @@ -0,0 +1,13 @@ +``` +% pandoc -f latex+auto_identifiers -t html +\section{Six favourite beers} +\subsection{Jovaru Alus}\label{jovaru-alus} +\section{Farmhouse brewers} +\subsection{Jovaru Alus} +^D +<h1 id="six-favourite-beers">Six favourite beers</h1> +<h2 id="jovaru-alus">Jovaru Alus</h2> +<h1 id="farmhouse-brewers">Farmhouse brewers</h1> +<h2 id="jovaru-alus-1">Jovaru Alus</h2> +``` + |