@@ -1372,10 +1372,23 @@ getRels = do
1372 return $ mapMaybe elementToRel relElems
1372 return $ mapMaybe elementToRel relElems
1374presentationToRels :: PandocMonad m => Presentation -> P m [Relationship]
1374presentationToRels :: PandocMonad m => Presentation -> P m [Relationship]
1375−presentationToRels (Presentation _ slides) = do
1375+presentationToRels pres@(Presentation _ slides) = do
1376 mySlideRels <- mapM slideToPresRel slides
1376 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"
1384+ insertedRels = mySlideRels ++ notesMasterRels
1377 rels <- getRels
1385 rels <- getRels
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
1378− let relsWithoutSlides = filter (\r -> relType r /= "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide") rels
1389+ (\r -> relType r /= "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" &&
1390+ relType r /= "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster")
1379 -- We want to make room for the slides in the id space. The slides
1392 -- We want to make room for the slides in the id space. The slides
1380 -- will start at Id2 (since Id1 is for the slide master). There are
1393 -- will start at Id2 (since Id1 is for the slide master). There are
1381 -- two slides in the data file, but that might change in the future,
1394 -- two slides in the data file, but that might change in the future,
@@ -1384,8 +1397,9 @@ presentationToRels (Presentation _ slides) = do
1384 -- 1. We look to see what the minimum relWithoutSlide id (greater than 1) is.
1397 -- 1. We look to see what the minimum relWithoutSlide id (greater than 1) is.
1385 -- 2. We add the difference between this and the number of slides to
1398 -- 2. We add the difference between this and the number of slides to
1386 -- all relWithoutSlide rels (unless they're 1)
1399 -- all relWithoutSlide rels (unless they're 1)
1400+ -- 3. If we have a notesmaster slide, we make space for that as well.
1388− let minRelNotOne = case filter (1<) $ map relId relsWithoutSlides of
1402+ let minRelNotOne = case filter (1<) $ map relId relsWeKeep of
1389 [] -> 0 -- doesn't matter in this case, since
1403 [] -> 0 -- doesn't matter in this case, since
1390 -- there will be nothing to map the
1404 -- there will be nothing to map the
1391 -- function over
1405 -- function over
@@ -1393,11 +1407,11 @@ presentationToRels (Presentation _ slides) = do
1394 modifyRelNum :: Int -> Int
1408 modifyRelNum :: Int -> Int
1395 modifyRelNum 1 = 1
1409 modifyRelNum 1 = 1
1396− modifyRelNum n = n - minRelNotOne + 2 + length slides
1410+ modifyRelNum n = n - minRelNotOne + 2 + length insertedRels
1398− relsWithoutSlides' = map (\r -> r{relId = modifyRelNum $ relId r}) relsWithoutSlides
1412+ relsWeKeep' = map (\r -> r{relId = modifyRelNum $ relId r}) relsWeKeep
1400− return $ mySlideRels ++ relsWithoutSlides'
1414+ return $ insertedRels ++ relsWeKeep'
1402-- We make this ourselves, in case there's a thumbnail in the one from
1416-- We make this ourselves, in case there's a thumbnail in the one from
1403-- the template.
1417-- the template.
@@ -1601,26 +1615,41 @@ presentationToPresentationElement pres@(Presentation _ slds) = do
1602 notesMasterRId = length slds + 2
1616 notesMasterRId = length slds + 2
1604− modifySpeakerNotes' :: Content -> [Content]
1605− modifySpeakerNotes' (Elem e) = case elName e of
1606− (QName "notesMasterIdLst" _ _) ->
1607− if presHasSpeakerNotes pres
1609− mknode "p:notesMasterIdLst" []
1618+ notesMasterElem = mknode "p:notesMasterIdLst" []
1610− [ mknode
1619+ [ mknode
1611− "p:NotesMasterId"
1620+ "p:NotesMasterId"
1612− [("r:id", "rId" ++ show notesMasterRId)]
1621+ [("r:id", "rId" ++ show notesMasterRId)]
1618− modifySpeakerNotes' ct = [ct]
1620− modifySpeakerNotes :: [Content] -> [Content]
1621− modifySpeakerNotes = concatMap modifySpeakerNotes'
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.
1629+ removeNotesMaster' :: Content -> [Content]
1630+ removeNotesMaster' (Elem e) = case elName e of
1631+ (QName "notesMasterIdLst" _ _) -> []
1633+ removeNotesMaster' ct = [ct]
1635+ removeNotesMaster :: [Content] -> [Content]
1636+ removeNotesMaster = concatMap removeNotesMaster'
1638+ insertNotesMaster' :: Content -> [Content]
1639+ insertNotesMaster' (Elem e) = case elName e of
1640+ (QName "sldMasterIdLst" _ _) -> [Elem e, Elem notesMasterElem]
1642+ insertNotesMaster' ct = [ct]
1644+ insertNotesMaster :: [Content] -> [Content]
1645+ insertNotesMaster = if presHasSpeakerNotes pres
1646+ then concatMap insertNotesMaster'
1649+ newContent = insertNotesMaster $
1650+ removeNotesMaster $
1623− newContent = modifySpeakerNotes $ map modifySldIdLst $ elContent element
1651+ map modifySldIdLst $
1625 return $ element{elContent = newContent}
1654 return $ element{elContent = newContent}