@@ -1372,10 +1372,23 @@ getRels = do
13721372 return $ mapMaybe elementToRel relElems
13731373
13741374presentationToRels :: PandocMonad m => Presentation -> P m [Relationship]
1375−presentationToRels (Presentation _ slides) = do
1375+presentationToRels pres@(Presentation _ slides) = do
13761376 mySlideRels <- mapM slideToPresRel slides
1377+ let notesMasterRels =
1378+ if presHasSpeakerNotes pres
1379+ then [Relationship { relId = length mySlideRels + 2
1380+ , relType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster"
1381+ , relTarget = "notesMasters/notesMaster1.xml"
1382+ }]
1383+ else []
1384+ insertedRels = mySlideRels ++ notesMasterRels
13771385 rels <- getRels
1378− let relsWithoutSlides = filter (\r -> relType r /= "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide") rels
1386+ -- we remove the slide rels and the notesmaster (if it's
1387+ -- there). We'll put these back in ourselves, if necessary.
1388+ let relsWeKeep = filter
1389+ (\r -> relType r /= "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" &&
1390+ relType r /= "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster")
1391+ rels
13791392 -- We want to make room for the slides in the id space. The slides
13801393 -- will start at Id2 (since Id1 is for the slide master). There are
13811394 -- two slides in the data file, but that might change in the future,
@@ -1384,8 +1397,9 @@ presentationToRels (Presentation _ slides) = do
13841397 -- 1. We look to see what the minimum relWithoutSlide id (greater than 1) is.
13851398 -- 2. We add the difference between this and the number of slides to
13861399 -- all relWithoutSlide rels (unless they're 1)
1400+ -- 3. If we have a notesmaster slide, we make space for that as well.
13871401
1388− let minRelNotOne = case filter (1<) $ map relId relsWithoutSlides of
1402+ let minRelNotOne = case filter (1<) $ map relId relsWeKeep of
13891403 [] -> 0 -- doesn't matter in this case, since
13901404 -- there will be nothing to map the
13911405 -- function over
@@ -1393,11 +1407,11 @@ presentationToRels (Presentation _ slides) = do
13931407
13941408 modifyRelNum :: Int -> Int
13951409 modifyRelNum 1 = 1
1396− modifyRelNum n = n - minRelNotOne + 2 + length slides
1410+ modifyRelNum n = n - minRelNotOne + 2 + length insertedRels
13971411
1398− relsWithoutSlides' = map (\r -> r{relId = modifyRelNum $ relId r}) relsWithoutSlides
1412+ relsWeKeep' = map (\r -> r{relId = modifyRelNum $ relId r}) relsWeKeep
13991413
1400− return $ mySlideRels ++ relsWithoutSlides'
1414+ return $ insertedRels ++ relsWeKeep'
14011415
14021416-- We make this ourselves, in case there's a thumbnail in the one from
14031417-- the template.
@@ -1601,26 +1615,41 @@ presentationToPresentationElement pres@(Presentation _ slds) = do
16011615
16021616 notesMasterRId = length slds + 2
16031617
1604− modifySpeakerNotes' :: Content -> [Content]
1605− modifySpeakerNotes' (Elem e) = case elName e of
1606− (QName "notesMasterIdLst" _ _) ->
1607− if presHasSpeakerNotes pres
1608− then [Elem $
1609− mknode "p:notesMasterIdLst" []
1610− [ mknode
1611− "p:NotesMasterId"
1612− [("r:id", "rId" ++ show notesMasterRId)]
1613− ()
1614− ]
1615− ]
1616− else []
1617− _ -> [Elem e]
1618− modifySpeakerNotes' ct = [ct]
1619−
1620− modifySpeakerNotes :: [Content] -> [Content]
1621− modifySpeakerNotes = concatMap modifySpeakerNotes'
1618+ notesMasterElem = mknode "p:notesMasterIdLst" []
1619+ [ mknode
1620+ "p:NotesMasterId"
1621+ [("r:id", "rId" ++ show notesMasterRId)]
1622+ ()
1623+ ]
16221624
1623− newContent = modifySpeakerNotes $ map modifySldIdLst $ elContent element
1625+ -- if there's a notesMasterIdLst in the presentation.xml file,
1626+ -- we want to remove it. We then want to put our own, if
1627+ -- necessary, after the slideMasterIdLst element.
1628+
1629+ removeNotesMaster' :: Content -> [Content]
1630+ removeNotesMaster' (Elem e) = case elName e of
1631+ (QName "notesMasterIdLst" _ _) -> []
1632+ _ -> [Elem e]
1633+ removeNotesMaster' ct = [ct]
1634+
1635+ removeNotesMaster :: [Content] -> [Content]
1636+ removeNotesMaster = concatMap removeNotesMaster'
1637+
1638+ insertNotesMaster' :: Content -> [Content]
1639+ insertNotesMaster' (Elem e) = case elName e of
1640+ (QName "sldMasterIdLst" _ _) -> [Elem e, Elem notesMasterElem]
1641+ _ -> [Elem e]
1642+ insertNotesMaster' ct = [ct]
1643+
1644+ insertNotesMaster :: [Content] -> [Content]
1645+ insertNotesMaster = if presHasSpeakerNotes pres
1646+ then concatMap insertNotesMaster'
1647+ else id
1648+
1649+ newContent = insertNotesMaster $
1650+ removeNotesMaster $
1651+ map modifySldIdLst $
1652+ elContent element
16241653
16251654 return $ element{elContent = newContent}
16261655