git.iko.soy/typeable/pandoc
on master help sign in
PowerPoint writer: Correct application of reference doc for content

Previously we had applied content shapes based on their index (which was "1", "2" in MS Word 2013). It turns out that this was a convention, and could not be relied on. Instead we use a default type (ie, a ph tag with no "type"). This is more correct, and should make the application of reference documents in PowerPoint much more robust.

commit5e944bf5b06ff9785e3e9c67cf9b8f383e498fde authorJesse Rosenthal <jrosenthal@jhu.edu> dateMon 1 Apr 2019, 14:34 (8 years ago) parentda802c1
1 file changed+16−30
src/Text/Pandoc/Writers/Powerpoint/Output.hs+16−30
src/Text/Pandoc/Writers/Powerpoint/Output.hs+16−30
@@ -336,22 +336,18 @@ shapeHasId ns ident element
336336 nm == ident
337337 | otherwise = False
338338
339−-- The content shape in slideLayout2 (Title/Content) has id=3 In
340−-- slideLayout4 (two column) the left column is id=3, and the right
341−-- column is id=4.
342339getContentShape :: PandocMonad m => NameSpaces -> Element -> P m Element
343340getContentShape ns spTreeElem
344341 | isElem ns "p" "spTree" spTreeElem = do
345342 contentType <- asks envContentType
346− let idx = case contentType of
347− NormalContent -> "1"
348− TwoColumnLeftContent -> "1"
349− TwoColumnRightContent -> "2"
350− case getShapeByPlaceHolderIndex ns spTreeElem idx of
351− Just e -> return e
352− Nothing -> throwError $
353− PandocSomeError $
354− "Could not find shape for Powerpoint content"
343+ let contentShapes = getShapesByPlaceHolderType ns spTreeElem ObjType
344+ case contentType of
345+ NormalContent | (sp : _) <- contentShapes -> return sp
346+ TwoColumnLeftContent | (sp : _) <- contentShapes -> return sp
347+ TwoColumnRightContent | (_ : sp : _) <- contentShapes -> return sp
348+ _ -> throwError $
349+ PandocSomeError $
350+ "Could not find shape for Powerpoint content"
355351getContentShape _ _ = throwError $
356352 PandocSomeError $
357353 "Attempted to find content on non shapeTree"
@@ -1006,11 +1002,15 @@ findPHType ns spElem phType
10061002 Nothing -> False
10071003findPHType _ _ _ = False
10081004
1009−getShapeByPlaceHolderType :: NameSpaces -> Element -> PHType -> Maybe Element
1010−getShapeByPlaceHolderType ns spTreeElem phType
1005+getShapesByPlaceHolderType :: NameSpaces -> Element -> PHType -> [Element]
1006+getShapesByPlaceHolderType ns spTreeElem phType
10111007 | isElem ns "p" "spTree" spTreeElem =
1012− filterChild (\e -> findPHType ns e phType) spTreeElem
1013− | otherwise = Nothing
1008+ filterChildren (\e -> findPHType ns e phType) spTreeElem
1009+ | otherwise = []
1010+
1011+getShapeByPlaceHolderType :: NameSpaces -> Element -> PHType -> Maybe Element
1012+getShapeByPlaceHolderType ns spTreeElem phType =
1013+ listToMaybe $ getShapesByPlaceHolderType ns spTreeElem phType
10141014
10151015-- Like the above, but it tries a number of different placeholder types
10161016getShapeByPlaceHolderTypes :: NameSpaces -> Element -> [PHType] -> Maybe Element
@@ -1020,20 +1020,6 @@ getShapeByPlaceHolderTypes ns spTreeElem (s:ss) =
10201020 Just element -> Just element
10211021 Nothing -> getShapeByPlaceHolderTypes ns spTreeElem ss
10221022
1023−getShapeByPlaceHolderIndex :: NameSpaces -> Element -> String -> Maybe Element
1024−getShapeByPlaceHolderIndex ns spTreeElem phIdx
1025− | isElem ns "p" "spTree" spTreeElem =
1026− let findPhType element = isElem ns "p" "sp" element &&
1027− Just phIdx == (Just element >>=
1028− findChild (elemName ns "p" "nvSpPr") >>=
1029− findChild (elemName ns "p" "nvPr") >>=
1030− findChild (elemName ns "p" "ph") >>=
1031− findAttr (QName "idx" Nothing Nothing))
1032− in
1033− filterChild findPhType spTreeElem
1034− | otherwise = Nothing
1035−
1036−
10371023nonBodyTextToElement :: PandocMonad m => Element -> [PHType] -> [ParaElem] -> P m Element
10381024nonBodyTextToElement layout phTypes paraElements
10391025 | ns <- elemToNameSpaces layout