From eb0c0b86ed518982eb5d3336e73ff5cb1d59d87c Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 11 Aug 2013 17:13:46 -0700 Subject: ODT/OpenDocument writer: Minor changes for ODF 1.2 conformance. See #939. We leave the nonconforming contextual-spacing attribute, which is provided by LibreOffice itself and seems to be supported. --- data/reference.odt | Bin 7058 -> 10702 bytes data/templates | 2 +- src/Text/Pandoc/Writers/ODT.hs | 20 ++++++++++++++------ src/Text/Pandoc/Writers/OpenDocument.hs | 3 ++- tests/writer.opendocument | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/data/reference.odt b/data/reference.odt index 6307119d3..29c1777d7 100644 Binary files a/data/reference.odt and b/data/reference.odt differ diff --git a/data/templates b/data/templates index c27f59c01..0cb55f228 160000 --- a/data/templates +++ b/data/templates @@ -1 +1 @@ -Subproject commit c27f59c010b0468f01b710cdf3a3c04a450a03e7 +Subproject commit 0cb55f2289148b106ab78ce8f15efc8d0b8acda0 diff --git a/src/Text/Pandoc/Writers/ODT.hs b/src/Text/Pandoc/Writers/ODT.hs index 751a323f5..cc0a06243 100644 --- a/src/Text/Pandoc/Writers/ODT.hs +++ b/src/Text/Pandoc/Writers/ODT.hs @@ -65,26 +65,30 @@ writeODT opts doc@(Pandoc meta _) = do doc' <- walkM (transformPic opts picEntriesRef) doc let newContents = writeOpenDocument opts{writerWrapText = False} doc' epochtime <- floor `fmap` getPOSIXTime - let contentEntry = toEntry "content.xml" epochtime $ fromStringLazy newContents + let contentEntry = toEntry "content.xml" epochtime + $ fromStringLazy newContents picEntries <- readIORef picEntriesRef - let archive = foldr addEntryToArchive refArchive $ contentEntry : picEntries + let archive = foldr addEntryToArchive refArchive + $ contentEntry : picEntries -- construct META-INF/manifest.xml based on archive let toFileEntry fp = case getMimeType fp of Nothing -> empty Just m -> selfClosingTag "manifest:file-entry" [("manifest:media-type", m) ,("manifest:full-path", fp) + ,("manifest:version", "1.2") ] - let files = [ ent | ent <- filesInArchive archive, not ("META-INF" `isPrefixOf` ent) ] + let files = [ ent | ent <- filesInArchive archive, + not ("META-INF" `isPrefixOf` ent) ] let manifestEntry = toEntry "META-INF/manifest.xml" epochtime $ fromStringLazy $ render Nothing $ text "" $$ ( inTags True "manifest:manifest" - [("xmlns:manifest","urn:oasis:names:tc:opendocument:xmlns:manifest:1.0")] + [("xmlns:manifest","urn:oasis:names:tc:opendocument:xmlns:manifest:1.0") + ,("manifest:version","1.2")] $ ( selfClosingTag "manifest:file-entry" [("manifest:media-type","application/vnd.oasis.opendocument.text") - ,("manifest:version","1.2") ,("manifest:full-path","/")] $$ vcat ( map toFileEntry $ files ) ) @@ -107,7 +111,11 @@ writeODT opts doc@(Pandoc meta _) = do ) ) ) - let archive'' = addEntryToArchive metaEntry archive' + -- make sure mimetype is first + let mimetypeEntry = toEntry "mimetype" epochtime + $ fromStringLazy "application/vnd.oasis.opendocument.text" + let archive'' = addEntryToArchive mimetypeEntry + $ addEntryToArchive metaEntry archive' return $ fromArchive archive'' transformPic :: WriterOptions -> IORef [Entry] -> Inline -> IO Inline diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index 05c576c20..3ec5c2073 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -461,7 +461,8 @@ tableStyle :: Int -> [(Char,Double)] -> Doc tableStyle num wcs = let tableId = "Table" ++ show (num + 1) table = inTags True "style:style" - [("style:name", tableId)] $ + [("style:name", tableId) + ,("style:family", "table")] $ selfClosingTag "style:table-properties" [("table:align" , "center")] colStyle (c,0) = selfClosingTag "style:style" diff --git a/tests/writer.opendocument b/tests/writer.opendocument index 9e1661475..1cee01f76 100644 --- a/tests/writer.opendocument +++ b/tests/writer.opendocument @@ -1,5 +1,5 @@ - + -- cgit v1.2.3