diff options
| author | John MacFarlane <[email protected]> | 2023-11-05 21:26:37 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2023-11-05 21:26:37 -0800 |
| commit | 6fdebc4afd37227f6450f3c28ef7019c1f2e2be8 (patch) | |
| tree | 66cb4c7c270a8be22a7e0b99204bb4805df6ebfe /src | |
| parent | 9400f75506173efcb0591d7b8415da64ea30dadb (diff) | |
T.P.Shared: export `combineAttr`.
[API change]
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Shared.hs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 1e68bdd10..95828da9a 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -50,6 +50,7 @@ module Text.Pandoc.Shared ( linesToPara, figureDiv, makeSections, + combineAttr, uniqueIdent, inlineListToIdentifier, textToIdentifier, @@ -562,13 +563,15 @@ makeSections numbering mbBaseLevel bs = go (x:xs) = (x :) <$> go xs go [] = return [] - combineAttr :: Attr -> Attr -> Attr - combineAttr (id1, classes1, kvs1) (id2, classes2, kvs2) = - (if T.null id1 then id2 else id1, - nubOrd (classes1 ++ classes2), - foldr (\(k,v) kvs -> case lookup k kvs of - Nothing -> (k,v):kvs - Just _ -> kvs) mempty (kvs1 ++ kvs2)) +-- | Combine two 'Attr'. Classes are concatenated. For the id and key-value +-- attributes, the first one takes precedence in case of duplicates. +combineAttr :: Attr -> Attr -> Attr +combineAttr (id1, classes1, kvs1) (id2, classes2, kvs2) = + (if T.null id1 then id2 else id1, + nubOrd (classes1 ++ classes2), + foldr (\(k,v) kvs -> case lookup k kvs of + Nothing -> (k,v):kvs + Just _ -> kvs) kvs1 kvs2) headerLtEq :: Int -> Block -> Bool headerLtEq level (Header l _ _) = l <= level |
