From 9b0378b939f46183fc152b1a49a69f3007de295a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 16 Nov 2013 22:49:15 -0800 Subject: OpenDocument: Skip raw HTML. Previously it was erroneously included as verbatim text. Closes #1035. --- src/Text/Pandoc/Writers/OpenDocument.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Text/Pandoc/Writers/OpenDocument.hs') diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index b38d250aa..565f5f869 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -376,8 +376,8 @@ inlineToOpenDocument o ils | Code _ s <- ils = withTextStyle Pre $ inTextStyle $ preformatted s | Math t s <- ils = inlinesToOpenDocument o (readTeXMath' t s) | Cite _ l <- ils = inlinesToOpenDocument o l - | RawInline f s <- ils = if f == "opendocument" || f == "html" - then withTextStyle Pre $ inTextStyle $ preformatted s + | RawInline f s <- ils = if f == "opendocument" + then return $ preformatted s else return empty | Link l (s,t) <- ils = mkLink s t <$> inlinesToOpenDocument o l | Image _ (s,t) <- ils = return $ mkImg s t -- cgit v1.2.3 From 7aa4d519686af1416eaf3b380f8584ab89569c41 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 30 Nov 2013 17:00:58 -0800 Subject: ODT writer: Add `draw:name` attribute to `draw:frame` elements. This is reported to be necessary to avoid an error from recent versions of Libre Office when files contain more than one image. Closes #1069. Thanks to wmanley for reporting and diagnosing the problem. --- src/Text/Pandoc/Writers/OpenDocument.hs | 10 ++++++++-- tests/writer.opendocument | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src/Text/Pandoc/Writers/OpenDocument.hs') diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index 565f5f869..4ddfd7166 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -64,6 +64,7 @@ data WriterState = , stInDefinition :: Bool , stTight :: Bool , stFirstPara :: Bool + , stImageId :: Int } defaultWriterState :: WriterState @@ -78,6 +79,7 @@ defaultWriterState = , stInDefinition = False , stTight = False , stFirstPara = False + , stImageId = 1 } when :: Bool -> Doc -> Doc @@ -380,7 +382,7 @@ inlineToOpenDocument o ils then return $ preformatted s else return empty | Link l (s,t) <- ils = mkLink s t <$> inlinesToOpenDocument o l - | Image _ (s,t) <- ils = return $ mkImg s t + | Image _ (s,t) <- ils = mkImg s t | Note l <- ils = mkNote l | otherwise = return empty where @@ -389,7 +391,11 @@ inlineToOpenDocument o ils , ("xlink:href" , s ) , ("office:name", t ) ] . inSpanTags "Definition" - mkImg s t = inTags False "draw:frame" (attrsFromTitle t) $ + mkImg s t = do + id' <- gets stImageId + modify (\st -> st{ stImageId = id' + 1 }) + return $ inTags False "draw:frame" + (("draw:name", "img" ++ show id'):attrsFromTitle t) $ selfClosingTag "draw:image" [ ("xlink:href" , s ) , ("xlink:type" , "simple") , ("xlink:show" , "embed" ) diff --git a/tests/writer.opendocument b/tests/writer.opendocument index b3888e34d..81c793a62 100644 --- a/tests/writer.opendocument +++ b/tests/writer.opendocument @@ -1576,9 +1576,9 @@ link in pointy braces. Images From “Voyage dans la Lune” by Georges Melies (1902): - + Here is a movie - + icon. Footnotes -- cgit v1.2.3 From ac100f27249e4c572e687d027330ca2cc53cb1ed Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 2 Jan 2014 15:23:16 -0800 Subject: OpenDocument writer: Fixed RawInline, RawBlock so they don't escape. --- src/Text/Pandoc/Writers/OpenDocument.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/Text/Pandoc/Writers/OpenDocument.hs') diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index 4ddfd7166..0029c3296 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -285,8 +285,12 @@ blocksToOpenDocument o b = vcat <$> mapM (blockToOpenDocument o) b -- | Convert a Pandoc block element to OpenDocument. blockToOpenDocument :: WriterOptions -> Block -> State WriterState Doc blockToOpenDocument o bs - | Plain b <- bs = inParagraphTags =<< inlinesToOpenDocument o b - | Para b <- bs = inParagraphTags =<< inlinesToOpenDocument o b + | Plain b <- bs = if null b + then return empty + else inParagraphTags =<< inlinesToOpenDocument o b + | Para b <- bs = if null b + then return empty + else inParagraphTags =<< inlinesToOpenDocument o b | Div _ xs <- bs = blocksToOpenDocument o xs | Header i _ b <- bs = setFirstPara >> (inHeaderTags i =<< inlinesToOpenDocument o b) @@ -298,8 +302,8 @@ blockToOpenDocument o bs | Table c a w h r <- bs = setFirstPara >> table c a w h r | HorizontalRule <- bs = setFirstPara >> return (selfClosingTag "text:p" [ ("text:style-name", "Horizontal_20_Line") ]) - | RawBlock f s <- bs = if f == "opendocument" - then preformatted s + | RawBlock f s <- bs = if f == Format "opendocument" + then return $ text s else return empty | Null <- bs = return empty | otherwise = return empty @@ -378,8 +382,8 @@ inlineToOpenDocument o ils | Code _ s <- ils = withTextStyle Pre $ inTextStyle $ preformatted s | Math t s <- ils = inlinesToOpenDocument o (readTeXMath' t s) | Cite _ l <- ils = inlinesToOpenDocument o l - | RawInline f s <- ils = if f == "opendocument" - then return $ preformatted s + | RawInline f s <- ils = if f == Format "opendocument" + then return $ text s else return empty | Link l (s,t) <- ils = mkLink s t <$> inlinesToOpenDocument o l | Image _ (s,t) <- ils = mkImg s t -- cgit v1.2.3