summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Writers/ODT.hs38
-rw-r--r--src/Text/Pandoc/Writers/OpenDocument.hs20
-rw-r--r--test/writer.opendocument2
3 files changed, 51 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Writers/ODT.hs b/src/Text/Pandoc/Writers/ODT.hs
index 390d7c3ba..08b4206e3 100644
--- a/src/Text/Pandoc/Writers/ODT.hs
+++ b/src/Text/Pandoc/Writers/ODT.hs
@@ -56,7 +56,7 @@ import Text.Pandoc.XML
import Text.TeXMath
import Text.XML.Light
-data ODTState = ODTState { stEntries :: [Entry]
+newtype ODTState = ODTState { stEntries :: [Entry]
}
type O m = StateT ODTState m
@@ -224,17 +224,39 @@ transformPicMath _ (Math t math) = do
let dirname = "Formula-" ++ show (length entries) ++ "/"
let fname = dirname ++ "content.xml"
let entry = toEntry fname epochtime (fromStringLazy mathml)
- modify $ \st -> st{ stEntries = entry : entries }
+ let fname' = dirname ++ "settings.xml"
+ let entry' = toEntry fname' epochtime $ documentSettings (t == InlineMath)
+ modify $ \st -> st{ stEntries = entry' : (entry : entries) }
return $ RawInline (Format "opendocument") $ render Nothing $
- inTags False "draw:frame" [("text:anchor-type",
- if t == DisplayMath
- then "paragraph"
- else "as-char")
- ,("style:vertical-pos", "middle")
- ,("style:vertical-rel", "text")] $
+ inTags False "draw:frame" (if t == DisplayMath
+ then [("draw:style-name","fr2")
+ -- `draw:frame` does not support either
+ -- `style:vertical-pos` or `style:vertical-rel`,
+ -- therefore those attributes must go into the
+ -- `style:style` element
+ ,("text:anchor-type","paragraph")]
+ else [("draw:style-name","fr1")
+ ,("text:anchor-type","as-char")]) $
selfClosingTag "draw:object" [("xlink:href", dirname)
, ("xlink:type", "simple")
, ("xlink:show", "embed")
, ("xlink:actuate", "onLoad")]
transformPicMath _ x = return x
+
+documentSettings :: Bool -> B.ByteString
+documentSettings isTextMode = fromStringLazy $ render Nothing
+ $ text "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ $$
+ (inTags True "office:document-settings"
+ [("xmlns:office","urn:oasis:names:tc:opendocument:xmlns:office:1.0")
+ ,("xmlns:xlink","http://www.w3.org/1999/xlink")
+ ,("xmlns:config","urn:oasis:names:tc:opendocument:xmlns:config:1.0")
+ ,("xmlns:ooo","http://openoffice.org/2004/office")
+ ,("office:version","1.2")] $
+ inTagsSimple "office:settings" $
+ inTags False "config:config-item-set"
+ [("config:name", "ooo:configuration-settings")] $
+ inTags False "config:config-item" [("config:name", "IsTextMode")
+ ,("config:type", "boolean")] $
+ text $ if isTextMode then "true" else "false")
diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs
index 8aa19dbb5..dc7d14d05 100644
--- a/src/Text/Pandoc/Writers/OpenDocument.hs
+++ b/src/Text/Pandoc/Writers/OpenDocument.hs
@@ -173,6 +173,24 @@ inTextStyle d = do
return $ inTags False
"text:span" [("text:style-name",styleName)] d
+formulaStyles :: [Doc]
+formulaStyles = [formulaStyle InlineMath, formulaStyle DisplayMath]
+
+formulaStyle :: MathType -> Doc
+formulaStyle mt = inTags False "style:style"
+ [("style:name", if mt == InlineMath then "fr1" else "fr2")
+ ,("style:family", "graphic")
+ ,("style:parent-style-name", "Formula")]
+ $ selfClosingTag "style:graphic-properties" $ if mt == InlineMath then
+ [("style:vertical-pos", "middle")
+ ,("style:vertical-rel", "text")]
+ else
+ [("style:vertical-pos", "middle")
+ ,("style:vertical-rel", "paragraph-content")
+ ,("style:horizontal-pos", "center")
+ ,("style:horizontal-rel", "paragraph-content")
+ ,("style:wrap", "none")]
+
inHeaderTags :: PandocMonad m => Int -> Doc -> OD m Doc
inHeaderTags i d =
return $ inTags False "text:h" [ ("text:style-name", "Heading_20_" ++ show i)
@@ -211,7 +229,7 @@ writeOpenDocument opts (Pandoc meta blocks) = do
meta
b <- render' `fmap` blocksToOpenDocument opts blocks
return (b, m)
- let styles = stTableStyles s ++ stParaStyles s ++
+ let styles = stTableStyles s ++ stParaStyles s ++ formulaStyles ++
map snd (sortBy (flip (comparing fst)) (
Map.elems (stTextStyles s)))
listStyle (n,l) = inTags True "text:list-style"
diff --git a/test/writer.opendocument b/test/writer.opendocument
index 77c79d13c..081b33971 100644
--- a/test/writer.opendocument
+++ b/test/writer.opendocument
@@ -639,6 +639,8 @@
<style:style style:name="T6" style:family="text"><style:text-properties style:text-position="super 58%" /></style:style>
<style:style style:name="T7" style:family="text"><style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic" style:text-position="super 58%" /></style:style>
<style:style style:name="T8" style:family="text"><style:text-properties style:text-position="sub 58%" /></style:style>
+ <style:style style:name="fr2" style:family="graphic" style:parent-style-name="Formula"><style:graphic-properties style:vertical-pos="middle" style:vertical-rel="paragraph-content" style:horizontal-pos="center" style:horizontal-rel="paragraph-content" style:wrap="none" /></style:style>
+ <style:style style:name="fr1" style:family="graphic" style:parent-style-name="Formula"><style:graphic-properties style:vertical-pos="middle" style:vertical-rel="text" /></style:style>
<style:style style:name="P1" style:family="paragraph" style:parent-style-name="Quotations">
<style:paragraph-properties fo:margin-left="0.5in" fo:margin-right="0in" fo:text-indent="0in" style:auto-text-indent="false" />
</style:style>