git.iko.soy/typeable/pandoc
on master help sign in
Powerpoint writer: Ignore internal links without targets.
53c48ddJesse Rosenthal
src/Text/Pandoc/Writers/Powerpoint.hs+31−12
@@ -57,7 +57,7 @@ import Text.Pandoc.Walk
57import Text.Pandoc.Writers.Shared (fixDisplayMath)
57import Text.Pandoc.Writers.Shared (fixDisplayMath)
58import Text.Pandoc.Writers.OOXML
58import Text.Pandoc.Writers.OOXML
59import qualified Data.Map as M
59import qualified Data.Map as M
60−import Data.Maybe (mapMaybe, listToMaybe, maybeToList)
60+import Data.Maybe (mapMaybe, listToMaybe, maybeToList, catMaybes)
61import Text.Pandoc.ImageSize
61import Text.Pandoc.ImageSize
62import Control.Applicative ((<|>))
62import Control.Applicative ((<|>))
63
63
@@ -1158,13 +1158,27 @@ paraElemToElement (Run rpr s) = do
1158 linkProps <- case rLink rpr of
1158 linkProps <- case rLink rpr of
1159 Just link -> do
1159 Just link -> do
1160 idNum <- registerLink link
1160 idNum <- registerLink link
1161− let (url, _) = link
1162− linkAttrs = [("r:id", "rId" ++ show idNum)]
1163− -- we have to add an extra action if it's an anchor.
1161+ -- first we have to make sure that if it's an
1164− linkAttrs' = linkAttrs ++ case url of
1162+ -- anchor, it's in the anchor map. If not, there's
1163+ -- no link.
1164+ anchorMap <- gets stAnchorMap
1165+ return $ case link of
1166+ -- anchor with nothing in the map
1167+ ('#':target, _) | Nothing <- M.lookup target anchorMap ->
1168+ []
1169+ -- anchor that is in the map
1170+ ('#':_, _) ->
1171+ let linkAttrs =
1172+ [ ("r:id", "rId" ++ show idNum)
1165− '#' : _ -> [("action", "ppaction://hlinksldjump")]
1173+ , ("action", "ppaction://hlinksldjump")
1174+ ]
1175+ in [mknode "a:hlinkClick" linkAttrs ()]
1176+ -- external
1166− _ -> []
1177+ _ ->
1178+ let linkAttrs =
1179+ [ ("r:id", "rId" ++ show idNum)
1180+ ]
1167− return [mknode "a:hlinkClick" linkAttrs' ()]
1181+ in [mknode "a:hlinkClick" linkAttrs ()]
1168 Nothing -> return []
1182 Nothing -> return []
1169 let propContents = if rPropCode rpr
1183 let propContents = if rPropCode rpr
1170 then [mknode "a:latin" [("typeface", "Courier")] ()]
1184 then [mknode "a:latin" [("typeface", "Courier")] ()]
@@ -1595,18 +1609,23 @@ slideToSlideRelEntry slide idNum = do
1595 element <- slideToSlideRelElement slide idNum
1609 element <- slideToSlideRelElement slide idNum
1596 elemToEntry ("ppt/slides/_rels/" ++ slideToFilePath slide idNum ++ ".rels") element
1610 elemToEntry ("ppt/slides/_rels/" ++ slideToFilePath slide idNum ++ ".rels") element
1597
1611
1598−linkRelElement :: PandocMonad m => Int -> (URL, String) -> P m Element
1612+linkRelElement :: PandocMonad m => Int -> (URL, String) -> P m (Maybe Element)
1599linkRelElement idNum (url, _) = do
1613linkRelElement idNum (url, _) = do
1600 anchorMap <- gets stAnchorMap
1614 anchorMap <- gets stAnchorMap
1601 case url of
1615 case url of
1616+ -- if it's an anchor in the map, we use the slide number for an
1617+ -- internal link.
1602 '#' : anchor | Just num <- M.lookup anchor anchorMap ->
1618 '#' : anchor | Just num <- M.lookup anchor anchorMap ->
1603− return $
1619+ return $ Just $
1604 mknode "Relationship" [ ("Id", "rId" ++ show idNum)
1620 mknode "Relationship" [ ("Id", "rId" ++ show idNum)
1605 , ("Type", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide")
1621 , ("Type", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide")
1606 , ("Target", "slide" ++ show num ++ ".xml")
1622 , ("Target", "slide" ++ show num ++ ".xml")
1607 ] ()
1623 ] ()
1624+ -- if it's an anchor not in the map, we return nothing.
1625+ '#' : _ -> return Nothing
1626+ -- Anything else we treat as an external link
1608 _ ->
1627 _ ->
1609− return $
1628+ return $ Just $
1610 mknode "Relationship" [ ("Id", "rId" ++ show idNum)
1629 mknode "Relationship" [ ("Id", "rId" ++ show idNum)
1611 , ("Type", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink")
1630 , ("Type", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink")
1612 , ("Target", url)
1631 , ("Target", url)
@@ -1614,7 +1633,7 @@ linkRelElement idNum (url, _) = do
1614 ] ()
1633 ] ()
1615
1634
1616linkRelElements :: PandocMonad m => M.Map Int (URL, String) -> P m [Element]
1635linkRelElements :: PandocMonad m => M.Map Int (URL, String) -> P m [Element]
1617−linkRelElements mp = mapM (\(n, lnk) -> linkRelElement n lnk) (M.toList mp)
1636+linkRelElements mp = catMaybes <$> mapM (\(n, lnk) -> linkRelElement n lnk) (M.toList mp)
1618
1637
1619mediaRelElement :: MediaInfo -> Element
1638mediaRelElement :: MediaInfo -> Element
1620mediaRelElement mInfo =
1639mediaRelElement mInfo =