aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2018-10-20 08:22:35 -0400
committerJesse Rosenthal <jrosenthal@jhu.edu>2018-10-20 08:43:50 -0400
commit5547cd6000a061a74aee22ec41b238b9a6c0f920 (patch)
treeac15fca379829d638cd137cc96b0dfa8e46a41b3 /src/Text/Pandoc
parent0c419a01f7c554e7ad5f26a035db0cc63b72fedb (diff)
downloadpandoc-5547cd6000a061a74aee22ec41b238b9a6c0f920.tar.gz
Powerpoint: Support raw openxml in pptx writer.
This allows raw openxml blocks and inlines to be used in the pptx writer. A few caveats: 1. It's up to the user to write well-formed openxml. The chances for corruption, especially with such a brittle format as pptx, is pretty high. 2. Because of the tricky way that blocks map onto shapes, if you are using a raw block, it should be the only block on a slide (otherwise other text might end up overlapping it). 3. The pptx ooxml namespace abbreviations are different from the docx ooxml namespaces. Again, it's up to the user to get it right. Unzipped document and ooxml specification should be consulted. Closes: #4976
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Writers/Powerpoint/Output.hs23
-rw-r--r--src/Text/Pandoc/Writers/Powerpoint/Presentation.hs14
2 files changed, 25 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Writers/Powerpoint/Output.hs b/src/Text/Pandoc/Writers/Powerpoint/Output.hs
index 865ef1efc..3e6652686 100644
--- a/src/Text/Pandoc/Writers/Powerpoint/Output.hs
+++ b/src/Text/Pandoc/Writers/Powerpoint/Output.hs
@@ -728,9 +728,9 @@ makePicElements layout picProps mInfo alt = do
else return [picShape]
-paraElemToElement :: PandocMonad m => ParaElem -> P m Element
-paraElemToElement Break = return $ mknode "a:br" [] ()
-paraElemToElement (Run rpr s) = do
+paraElemToElements :: PandocMonad m => ParaElem -> P m [Element]
+paraElemToElements Break = return [mknode "a:br" [] ()]
+paraElemToElements (Run rpr s) = do
let sizeAttrs = case rPropForceSize rpr of
Just n -> [("sz", (show $ n * 100))]
Nothing -> if rPropCode rpr
@@ -787,15 +787,17 @@ paraElemToElement (Run rpr s) = do
then [mknode "a:latin" [("typeface", "Courier")] ()]
else []
let propContents = linkProps ++ colorContents ++ codeContents
- return $ mknode "a:r" [] [ mknode "a:rPr" attrs $ propContents
- , mknode "a:t" [] s
- ]
-paraElemToElement (MathElem mathType texStr) = do
+ return [mknode "a:r" [] [ mknode "a:rPr" attrs $ propContents
+ , mknode "a:t" [] s
+ ]]
+paraElemToElements (MathElem mathType texStr) = do
res <- convertMath writeOMML mathType (unTeXString texStr)
case res of
- Right r -> return $ mknode "a14:m" [] $ addMathInfo r
- Left (Str s) -> paraElemToElement (Run def s)
+ Right r -> return [mknode "a14:m" [] $ addMathInfo r]
+ Left (Str s) -> paraElemToElements (Run def s)
Left _ -> throwError $ PandocShouldNeverHappenError "non-string math fallback"
+paraElemToElements (RawOOXMLParaElem str) = return [ x | Elem x <- parseXML str ]
+
-- This is a bit of a kludge -- really requires adding an option to
-- TeXMath, but since that's a different package, we'll do this one
@@ -852,7 +854,7 @@ paragraphToElement par = do
[mknode "a:buAutoNum" [("type", autoNumberingToType attrs')] ()]
Nothing -> [mknode "a:buNone" [] ()]
)
- paras <- mapM paraElemToElement (paraElems par)
+ paras <- concat <$> mapM paraElemToElements (paraElems par)
return $ mknode "a:p" [] $ [mknode "a:pPr" attrs props] ++ paras
shapeToElement :: PandocMonad m => Element -> Shape -> P m Element
@@ -882,6 +884,7 @@ shapeToElements layout (Pic picProps fp alt) = do
Nothing -> shapeToElements layout $ TextBox [Paragraph def alt]
shapeToElements layout (GraphicFrame tbls cptn) =
graphicFrameToElements layout tbls cptn
+shapeToElements _ (RawOOXMLShape str) = return [ x | Elem x <- parseXML str ]
shapeToElements layout shp = do
element <- shapeToElement layout shp
return [element]
diff --git a/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs b/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs
index c97d8d770..22f2a46e7 100644
--- a/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs
+++ b/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs
@@ -216,6 +216,7 @@ data Layout = MetadataSlide { metadataSlideTitle :: [ParaElem]
data Shape = Pic PicProps FilePath [ParaElem]
| GraphicFrame [Graphic] [ParaElem]
| TextBox [Paragraph]
+ | RawOOXMLShape String
deriving (Show, Eq)
type Cell = [Paragraph]
@@ -266,6 +267,7 @@ data ParaElem = Break
-- `convertmath` from T.P.Writers.Math. Will perhaps
-- revisit in the future.
| MathElem MathType TeXString
+ | RawOOXMLParaElem String
deriving (Show, Eq)
data Strikethrough = NoStrike | SingleStrike | DoubleStrike
@@ -382,7 +384,11 @@ inlineToParElems (Quoted quoteType ils) =
where (open, close) = case quoteType of
SingleQuote -> ("\x2018", "\x2019")
DoubleQuote -> ("\x201C", "\x201D")
-inlineToParElems (RawInline _ _) = return []
+inlineToParElems il@(RawInline fmt s) =
+ case fmt of
+ Format "openxml" -> return [RawOOXMLParaElem s]
+ _ -> do addLogMessage $ InlineNotRendered il
+ return []
inlineToParElems (Cite _ ils) = inlinesToParElems ils
-- Note: we shouldn't reach this, because images should be handled at
-- the shape level, but should that change in the future, we render
@@ -446,7 +452,8 @@ blockToParagraphs (BlockQuote blks) =
, envRunProps = (envRunProps r){rPropForceSize = Just blockQuoteSize}})$
concatMapM blockToParagraphs blks
-- TODO: work out the format
-blockToParagraphs (RawBlock _ _) = return []
+blockToParagraphs blk@(RawBlock _ _) = do addLogMessage $ BlockNotRendered blk
+ return []
blockToParagraphs (Header _ (ident, _, _) ils) = do
-- Note that this function only deals with content blocks, so it
-- will only touch headers that are above the current slide level --
@@ -547,6 +554,8 @@ blockToShape (Table caption algn _ hdrCells rows) = do
}
return $ GraphicFrame [Tbl tblPr hdrCells' rows'] caption'
+-- If the format isn't openxml, we fall through to blockToPargraphs
+blockToShape (RawBlock (Format "openxml") str) = return $ RawOOXMLShape str
blockToShape blk = do paras <- blockToParagraphs blk
let paras' = map (\par -> par{paraElems = combineParaElems $ paraElems par}) paras
return $ TextBox paras'
@@ -809,6 +818,7 @@ applyToShape :: Monad m => (ParaElem -> m ParaElem) -> Shape -> m Shape
applyToShape f (Pic pPr fp pes) = Pic pPr fp <$> mapM f pes
applyToShape f (GraphicFrame gfx pes) = GraphicFrame gfx <$> mapM f pes
applyToShape f (TextBox paras) = TextBox <$> mapM (applyToParagraph f) paras
+applyToShape _ (RawOOXMLShape str) = return $ RawOOXMLShape str
applyToLayout :: Monad m => (ParaElem -> m ParaElem) -> Layout -> m Layout
applyToLayout f (MetadataSlide title subtitle authors date) = do