diff options
author | Jesse Rosenthal <jrosenthal@jhu.edu> | 2018-01-03 14:29:09 -0500 |
---|---|---|
committer | Jesse Rosenthal <jrosenthal@jhu.edu> | 2018-01-03 14:29:09 -0500 |
commit | 13990c05017baa473f77f1c827d902b40f42b6a4 (patch) | |
tree | 1fdfe15d25d2da7f438191536129a6309d54fd19 /src | |
parent | 1ce736c2dfdb6c3ecbadc5b7d28a091e86d172ec (diff) | |
download | pandoc-13990c05017baa473f77f1c827d902b40f42b6a4.tar.gz |
Powerpoint writer: simplify replaceNamedChildren function
A lot of work in the powerpoint writer is replacing XML from within
slidelayouts from templates. This function does a good deal of that
work, and this makes it preserve element order, as well as making it a
bit easier to understand.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/Powerpoint.hs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Writers/Powerpoint.hs b/src/Text/Pandoc/Writers/Powerpoint.hs index bf80b8afb..50b48fd87 100644 --- a/src/Text/Pandoc/Writers/Powerpoint.hs +++ b/src/Text/Pandoc/Writers/Powerpoint.hs @@ -820,16 +820,24 @@ getContentShape ns spTreeElem filterChild (\e -> (isElem ns "p" "sp" e) && (shapeHasName ns "Content Placeholder 2" e)) spTreeElem | otherwise = Nothing -contentIsElem :: NameSpaces -> String -> String -> Content -> Bool -contentIsElem ns prefix name (Elem element) = isElem ns prefix name element -contentIsElem _ _ _ _ = False - -replaceNamedChildren :: NameSpaces -> String -> String -> [Element] -> Element -> Element +replaceChildren :: (Element -> [Element]) -> Element -> Element +replaceChildren fun element = + element{elContent = concatMap fun' $ elContent element} + where fun' :: Content -> [Content] + fun' (Elem e) = map Elem $ fun e + fun' content = [content] + +replaceNamedChildren :: NameSpaces + -> String + -> String + -> [Element] + -> Element + -> Element replaceNamedChildren ns prefix name newKids element = - let content = elContent element - content' = filter (\c -> not (contentIsElem ns prefix name c)) content - in - element{elContent = content' ++ map Elem newKids} + let fun :: Element -> [Element] + fun e | isElem ns prefix name e = newKids + | otherwise = [e] + in replaceChildren fun element ---------------------------------------------------------------- |