summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2018-01-03 16:55:33 -0500
committerJesse Rosenthal <jrosenthal@jhu.edu>2018-01-03 16:55:33 -0500
commit02d85469abcb06f10b22ef461e2152c84f12394b (patch)
tree7b0bd54763e9133b0dc66ffe33e7b38ce41b5653 /src
parent6aae43998082280a356e2dda3df77c021abed58f (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Powerpoint.hs20
1 files 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
----------------------------------------------------------------