aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-10-08 14:33:27 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-10-08 14:33:27 -0700
commitb60c64d06e1fa7d5f3e41cc0c93da965a286e11c (patch)
treea006d85c36350ec529e476503bc4a52f74760885 /src/Text
parentb02c25b2cafb56f9f5bbcb0edf9f957b93b4afd0 (diff)
downloadpandoc-b60c64d06e1fa7d5f3e41cc0c93da965a286e11c.tar.gz
ODT writer: improve metadata.
- Author, date added to metadata. - Remaining metadata properties (besides author, date, title, lang) are added as meta:user-defined tags.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/ODT.hs33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/ODT.hs b/src/Text/Pandoc/Writers/ODT.hs
index 1c9481630..ac2ed5b4c 100644
--- a/src/Text/Pandoc/Writers/ODT.hs
+++ b/src/Text/Pandoc/Writers/ODT.hs
@@ -36,8 +36,9 @@ import Control.Monad.Except (catchError)
import Control.Monad.State.Strict
import qualified Data.ByteString.Lazy as B
import Data.Generics (everywhere', mkT)
-import Data.List (isPrefixOf)
+import Data.List (isPrefixOf, intercalate)
import Data.Maybe (fromMaybe)
+import qualified Data.Map as Map
import qualified Data.Text.Lazy as TL
import System.FilePath (takeDirectory, takeExtension, (<.>))
import Text.Pandoc.BCP47 (Lang (..), getLang, renderLang)
@@ -49,7 +50,8 @@ import Text.Pandoc.Logging
import Text.Pandoc.MIME (extensionFromMimeType, getMimeType)
import Text.Pandoc.Options (WrapOption (..), WriterOptions (..))
import Text.Pandoc.Pretty
-import Text.Pandoc.Shared (stringify)
+import Text.Pandoc.Shared (stringify, normalizeDate)
+import Text.Pandoc.Writers.Shared (lookupMetaString)
import Text.Pandoc.UTF8 (fromStringLazy, fromTextLazy, toStringLazy)
import Text.Pandoc.Walk
import Text.Pandoc.Writers.OpenDocument (writeOpenDocument)
@@ -81,6 +83,7 @@ pandocToODT :: PandocMonad m
-> O m B.ByteString
pandocToODT opts doc@(Pandoc meta _) = do
let title = docTitle meta
+ let authors = docAuthors meta
lang <- toLang (getLang opts meta)
refArchive <-
case writerReferenceDoc opts of
@@ -123,6 +126,15 @@ pandocToODT opts doc@(Pandoc meta _) = do
)
)
let archive' = addEntryToArchive manifestEntry archive
+ let userDefinedMetaFields = [k | k <- Map.keys (unMeta meta)
+ , k `notElem` ["title", "lang", "author", "date"]]
+ let escapedText = text . escapeStringForXML
+ let userDefinedMeta =
+ map (\k -> inTags False "meta:user-defined"
+ [ ("meta_name", escapeStringForXML k)
+ ,("meta-value-type", "string")
+ ] (escapedText $ lookupMetaString k meta)) userDefinedMetaFields
+ let metaTag metafield = inTagsSimple metafield . escapedText
let metaEntry = toEntry "meta.xml" epochtime
$ fromStringLazy $ render Nothing
$ text "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
@@ -134,14 +146,21 @@ pandocToODT opts doc@(Pandoc meta _) = do
,("xmlns:meta","urn:oasis:names:tc:opendocument:xmlns:meta:1.0")
,("xmlns:ooo","http://openoffice.org/2004/office")
,("xmlns:grddl","http://www.w3.org/2003/g/data-view#")
- ,("office:version","1.2")] ( inTagsSimple "office:meta" $
- ( inTagsSimple "dc:title"
- (text $ escapeStringForXML (stringify title))
+ ,("office:version","1.2")] ( inTags True "office:meta" [] $
+ ( metaTag "dc:title" (stringify title)
$$
case lang of
- Just l -> inTagsSimple "dc:language"
- (text (escapeStringForXML (renderLang l)))
+ Just l -> metaTag "dc:language" (renderLang l)
Nothing -> empty
+ $$
+ metaTag "dc:creator"
+ (intercalate "; " (map stringify authors))
+ $$
+ maybe mempty
+ (metaTag "dc:date")
+ (normalizeDate (lookupMetaString "date" meta))
+ $$
+ vcat userDefinedMeta
)
)
)