Skip to content

Commit

Permalink
ODT writer: Add draw:name attribute to draw:frame elements.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jgm committed Dec 1, 2013
1 parent dde484f commit 7aa4d51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/Text/Pandoc/Writers/OpenDocument.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ data WriterState =
, stInDefinition :: Bool
, stTight :: Bool
, stFirstPara :: Bool
, stImageId :: Int
}

defaultWriterState :: WriterState
Expand All @@ -78,6 +79,7 @@ defaultWriterState =
, stInDefinition = False
, stTight = False
, stFirstPara = False
, stImageId = 1
}

when :: Bool -> Doc -> Doc
Expand Down Expand Up @@ -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
Expand All @@ -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" )
Expand Down
4 changes: 2 additions & 2 deletions tests/writer.opendocument
Original file line number Diff line number Diff line change
Expand Up @@ -1576,9 +1576,9 @@ link in pointy braces</text:span></text:a>.</text:p>
<text:h text:style-name="Heading_20_1" text:outline-level="1">Images</text:h>
<text:p text:style-name="First_20_paragraph">From “Voyage dans la Lune” by
Georges Melies (1902):</text:p>
<text:p text:style-name="Text_20_body"><draw:frame><draw:image xlink:href="lalune.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame></text:p>
<text:p text:style-name="Text_20_body"><draw:frame draw:name="img1"><draw:image xlink:href="lalune.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame></text:p>
<text:p text:style-name="Text_20_body">Here is a movie
<draw:frame><draw:image xlink:href="movie.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame>
<draw:frame draw:name="img2"><draw:image xlink:href="movie.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame>
icon.</text:p>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Footnotes</text:h>
Expand Down

0 comments on commit 7aa4d51

Please sign in to comment.