aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Shared.hs16
-rw-r--r--test/command/3057.md10
2 files changed, 15 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 4dc2484e7..a5acc6c15 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -523,19 +523,23 @@ hierarchicalizeWithIds (Header level attr@(_,classes,_) title':xs) = do
sectionContents' <- hierarchicalizeWithIds sectionContents
rest' <- hierarchicalizeWithIds rest
return $ Sec level newnum attr title' sectionContents' : rest'
-hierarchicalizeWithIds (Div attr@(_,classes',_)
- (Header level (_,classes,_) title' : xs):ys)
- | not ("columns" `elem` classes')
- , not ("column" `elem` classes') = do
+hierarchicalizeWithIds (Div (dident,dclasses,dkvs)
+ (Header level (hident,hclasses,hkvs) title' : xs):ys)
+ | not ("columns" `elem` dclasses)
+ , not ("column" `elem` dclasses) = do
lastnum <- S.get
let lastnum' = take level lastnum
let newnum = case length lastnum' of
- x | "unnumbered" `elem` classes -> []
+ x | "unnumbered" `elem` hclasses -> []
| x >= level -> init lastnum' ++ [last lastnum' + 1]
| otherwise -> lastnum ++
replicate (level - length lastnum - 1) 0 ++ [1]
unless (null newnum) $ S.put newnum
- sectionContents' <- hierarchicalizeWithIds xs
+ let attr = (hident, dclasses ++ hclasses, dkvs ++ hkvs)
+ sectionContents' <- hierarchicalizeWithIds $
+ if null dident -- ensure we don't lose an id
+ then xs
+ else [Div (dident,[],[]) xs]
rest' <- hierarchicalizeWithIds ys
return $ Sec level newnum attr title' sectionContents' : rest'
hierarchicalizeWithIds (x:rest) = do
diff --git a/test/command/3057.md b/test/command/3057.md
index 0db5e7969..7d1f146c2 100644
--- a/test/command/3057.md
+++ b/test/command/3057.md
@@ -7,9 +7,9 @@
</div>
</div>
^D
-<section>
+<section xml:id="one">
<title>one</title>
- <section>
+ <section xml:id="two">
<title>two</title>
<para>
</para>
@@ -26,9 +26,9 @@
</div>
</div>
^D
-<section>
+<section xml:id="one">
<title>one</title>
- <section>
+ <section xml:id="two">
<title>two</title>
<para>
</para>
@@ -48,7 +48,7 @@
<para>
</para>
</section>
-<section>
+<section xml:id="two">
<title>two</title>
<para>
</para>