Skip to content

Commit 6fdebc4

Browse files
committed
T.P.Shared: export combineAttr.
[API change]
1 parent 9400f75 commit 6fdebc4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/Text/Pandoc/Shared.hs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module Text.Pandoc.Shared (
5050
linesToPara,
5151
figureDiv,
5252
makeSections,
53+
combineAttr,
5354
uniqueIdent,
5455
inlineListToIdentifier,
5556
textToIdentifier,
@@ -562,13 +563,15 @@ makeSections numbering mbBaseLevel bs =
562563
go (x:xs) = (x :) <$> go xs
563564
go [] = return []
564565

565-
combineAttr :: Attr -> Attr -> Attr
566-
combineAttr (id1, classes1, kvs1) (id2, classes2, kvs2) =
567-
(if T.null id1 then id2 else id1,
568-
nubOrd (classes1 ++ classes2),
569-
foldr (\(k,v) kvs -> case lookup k kvs of
570-
Nothing -> (k,v):kvs
571-
Just _ -> kvs) mempty (kvs1 ++ kvs2))
566+
-- | Combine two 'Attr'. Classes are concatenated. For the id and key-value
567+
-- attributes, the first one takes precedence in case of duplicates.
568+
combineAttr :: Attr -> Attr -> Attr
569+
combineAttr (id1, classes1, kvs1) (id2, classes2, kvs2) =
570+
(if T.null id1 then id2 else id1,
571+
nubOrd (classes1 ++ classes2),
572+
foldr (\(k,v) kvs -> case lookup k kvs of
573+
Nothing -> (k,v):kvs
574+
Just _ -> kvs) kvs1 kvs2)
572575

573576
headerLtEq :: Int -> Block -> Bool
574577
headerLtEq level (Header l _ _) = l <= level

0 commit comments

Comments
 (0)