@@ -582,25 +582,20 @@ makeSections numbering mbBaseLevel bs =
582 let attr = ("",classes,kvs')
582 let attr = ("",classes,kvs')
584 Div divattr (Header level' attr title' : sectionContents') : rest'
584 Div divattr (Header level' attr title' : sectionContents') : rest'
585− go (Div (dident,dclasses,dkvs)
585+ go (Div divattr@(dident,dclasses,_) (Header level hattr title':ys) : xs)
586− (Header level (ident,classes,kvs) title':ys) : xs)
587 | all (\case
586 | all (\case
588 Header level' _ _ -> level' > level
587 Header level' _ _ -> level' > level
589 _ -> True) ys
588 _ -> True) ys
590 , "column" `notElem` dclasses
589 , "column" `notElem` dclasses
591 , "columns" `notElem` dclasses = do
590 , "columns" `notElem` dclasses = do
592− inner <- go (Header level (ident,classes,kvs) title':ys)
591+ inner <- go (Header level hattr title':ys)
595− (Div (dident',dclasses',dkvs') zs@(Header{}:zs') : ws)
597− Div (dident',dclasses' ++ dclasses,dkvs' ++ dkvs) zs : ws
598− | otherwise -> -- keep id on header so we don't lose anchor
599− Div (dident,dclasses ++ dclasses',dkvs ++ dkvs')
600− (Header level (dident',classes,kvs) title':zs') : ws
601− _ -> inner -- shouldn't happen
602 rest <- go xs
592 rest <- go xs
603− return $ inner' ++ rest
593+ return $
595+ [Div divattr'@(dident',_,_) zs]
596+ | T.null dident || T.null dident' || dident == dident'
597+ -> Div (combineAttr divattr' divattr) zs : rest
598+ _ -> Div divattr inner : rest
604 go (Div attr xs : rest) = do
599 go (Div attr xs : rest) = do
605 xs' <- go xs
600 xs' <- go xs
606 rest' <- go rest
601 rest' <- go rest
@@ -608,6 +603,14 @@ makeSections numbering mbBaseLevel bs =
608 go (x:xs) = (x :) <$> go xs
603 go (x:xs) = (x :) <$> go xs
609 go [] = return []
604 go [] = return []
606+ combineAttr :: Attr -> Attr -> Attr
607+ combineAttr (id1, classes1, kvs1) (id2, classes2, kvs2) =
608+ (if T.null id1 then id2 else id1,
609+ ordNub (classes1 ++ classes2),
610+ foldr (\(k,v) kvs -> case lookup k kvs of
611+ Nothing -> (k,v):kvs
612+ Just _ -> kvs) mempty (kvs1 ++ kvs2))
611headerLtEq :: Int -> Block -> Bool
614headerLtEq :: Int -> Block -> Bool
612headerLtEq level (Header l _ _) = l <= level
615headerLtEq level (Header l _ _) = l <= level
613headerLtEq level (Div _ (b:_)) = headerLtEq level b
616headerLtEq level (Div _ (b:_)) = headerLtEq level b
@@ -642,6 +645,7 @@ headerShift n (Pandoc meta (Header m _ ils : bs))
642 , m + n == 0 = headerShift n $
645 , m + n == 0 = headerShift n $
643 B.setTitle (B.fromList ils) $ Pandoc meta bs
646 B.setTitle (B.fromList ils) $ Pandoc meta bs
644headerShift n (Pandoc meta bs) = Pandoc meta (walk shift bs)
647headerShift n (Pandoc meta bs) = Pandoc meta (walk shift bs)
646 shift :: Block -> Block
650 shift :: Block -> Block
647 shift (Header level attr inner)
651 shift (Header level attr inner)