{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Readers.Docx.Util (
NameSpaces
, elemName
, isElem
, elemToNameSpaces
, findChildByName
, findChildrenByName
, findElementByName
, findAttrByName
, extractChildren
) where
import Data.List (partition)
import Text.Pandoc.XML.Light
import Text.Pandoc.Readers.OOXML.Shared
(NameSpaces, elemName, isElem, elemToNameSpaces,
findChildByName, findChildrenByName, findElementByName, findAttrByName)
extractChildren :: Element -> (Element -> Bool) -> Maybe (Element, [Element])
Element
el Element -> Bool
condition
| [Element] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Element]
removedChildren = Maybe (Element, [Element])
forall a. Maybe a
Nothing
| Bool
otherwise = (Element, [Element]) -> Maybe (Element, [Element])
forall a. a -> Maybe a
Just (Element
modifiedElement, [Element]
removedChildren)
where
([Element]
removedChildren, [Element]
keptChildren) = (Element -> Bool) -> [Element] -> ([Element], [Element])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition Element -> Bool
condition ([Content] -> [Element]
onlyElems ([Content] -> [Element]) -> [Content] -> [Element]
forall a b. (a -> b) -> a -> b
$ Element -> [Content]
elContent Element
el)
modifiedElement :: Element
modifiedElement = Element
el { elContent = map Elem keptChildren }