From 212406a61d027d85712705e626954e0486a2bc34 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 6 Sep 2019 09:05:34 -0700 Subject: hierarchicalize: ensure that sections get ids... even if they're in divs. Improves #3057. --- src/Text/Pandoc/Shared.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src') 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 -- cgit v1.2.3