From 02d85469abcb06f10b22ef461e2152c84f12394b Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Wed, 3 Jan 2018 16:55:33 -0500 Subject: Powerpoint writer: Fix new replaceNamedChildren Previous version replaced *each* element from the template with the new elements -- leading to multiple overlapping frames. This only replaces the first instance, and throws out the rest. --- src/Text/Pandoc/Writers/Powerpoint.hs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Text/Pandoc/Writers/Powerpoint.hs b/src/Text/Pandoc/Writers/Powerpoint.hs index 32b7e2ec6..13542e78f 100644 --- a/src/Text/Pandoc/Writers/Powerpoint.hs +++ b/src/Text/Pandoc/Writers/Powerpoint.hs @@ -820,13 +820,6 @@ getContentShape ns spTreeElem filterChild (\e -> (isElem ns "p" "sp" e) && (shapeHasName ns "Content Placeholder 2" e)) spTreeElem | otherwise = Nothing -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 @@ -834,10 +827,15 @@ replaceNamedChildren :: NameSpaces -> Element -> Element replaceNamedChildren ns prefix name newKids element = - let fun :: Element -> [Element] - fun e | isElem ns prefix name e = newKids - | otherwise = [e] - in replaceChildren fun element + element { elContent = concat $ fun True $ elContent element } + where + fun :: Bool -> [Content] -> [[Content]] + fun _ [] = [] + fun switch ((Elem e) : conts) | isElem ns prefix name e = + if switch + then (map Elem $ newKids) : fun False conts + else fun False conts + fun switch (cont : conts) = [cont] : fun switch conts ---------------------------------------------------------------- -- cgit v1.2.3