git.iko.soy/typeable/pandoc
on master help sign in
Improved makeSections so we don't get doubled attributes.
20cf4e4John MacFarlane
src/Text/Pandoc/Shared.hs+17−13
@@ -582,25 +582,20 @@ makeSections numbering mbBaseLevel bs =
582 let attr = ("",classes,kvs')
582 let attr = ("",classes,kvs')
583 return $
583 return $
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)
593− let inner' =
594− case inner of
595− (Div (dident',dclasses',dkvs') zs@(Header{}:zs') : ws)
596− | T.null dident ->
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 $
594+ case inner of
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 []
610
605
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))
613+
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)
648+
645 where
649 where
646 shift :: Block -> Block
650 shift :: Block -> Block
647 shift (Header level attr inner)
651 shift (Header level attr inner)
src/Text/Pandoc/Writers/HTML.hs+2−1
@@ -663,7 +663,8 @@ blockToHtml opts (Div (ident, "section":dclasses, dkvs)
663 (z:zs) -> ([],z ++ concatMap inDiv zs)
663 (z:zs) -> ([],z ++ concatMap inDiv zs)
664 titleContents <- blockListToHtml opts titleBlocks
664 titleContents <- blockListToHtml opts titleBlocks
665 innerContents <- blockListToHtml opts innerSecs
665 innerContents <- blockListToHtml opts innerSecs
666+ let classes' = ordNub $
666− let classes' = ["title-slide" | titleSlide] ++ ["slide" | slide] ++
667+ ["title-slide" | titleSlide] ++ ["slide" | slide] ++
667 ["section" | (slide || writerSectionDivs opts) &&
668 ["section" | (slide || writerSectionDivs opts) &&
668 not html5 ] ++
669 not html5 ] ++
669 ["level" <> tshow level | slide || writerSectionDivs opts ]
670 ["level" <> tshow level | slide || writerSectionDivs opts ]
test/command/5986.md+1−1
@@ -10,7 +10,7 @@
10</ol>
10</ol>
11</nav>
11</nav>
12<p><span id="ch001.xhtml"></span></p>
12<p><span id="ch001.xhtml"></span></p>
13−<section id="ch001.xhtml#hi" class="level1 section" data-number="1">
13+<section id="ch001.xhtml#hi" class="level1" data-number="1">
14<h1 data-number="1"><span class="header-section-number">1</span> Hi</h1>
14<h1 data-number="1"><span class="header-section-number">1</span> Hi</h1>
15</section>
15</section>
16```
16```
test/command/section-divs.md+3−3
@@ -13,13 +13,13 @@ Ok
13==
13==
14:::
14:::
15^D
15^D
16−<section id="hi" class="level1 section">
16+<section id="hi" class="level1">
17<h1>Hi</h1>
17<h1>Hi</h1>
18−<section id="there" class="level2 section">
18+<section id="there" class="level2">
19<h2>there</h2>
19<h2>there</h2>
20</section>
20</section>
21</section>
21</section>
22−<section id="ok" class="level1 section">
22+<section id="ok" class="level1">
23<h1>Ok</h1>
23<h1>Ok</h1>
24</section>
24</section>
25```
25```