aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index d31928b01..50c28d20c 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -54,6 +54,7 @@ import Text.XML.Light as XML
import Text.TeXMath
import Text.Pandoc.Readers.Docx.StyleMap
import Text.Pandoc.Readers.Docx.Util (elemName)
+import Control.Monad.Reader
import Control.Monad.State
import Text.Highlighting.Kate
import Data.Unique (hashUnique, newUnique)
@@ -91,6 +92,11 @@ listMarkerToId (NumberMarker sty delim n) =
OneParen -> '2'
TwoParens -> '3'
+data WriterEnv = WriterEnv{ envRTL :: Bool }
+
+defaultWriterEnv :: WriterEnv
+defaultWriterEnv = WriterEnv{ envRTL = False }
+
data WriterState = WriterState{
stTextProperties :: [Element]
, stParaProperties :: [Element]
@@ -138,7 +144,7 @@ defaultWriterState = WriterState{
, stDynamicTextProps = []
}
-type WS a = StateT WriterState IO a
+type WS = ReaderT WriterEnv (StateT WriterState IO)
mknode :: Node t => String -> [(String,String)] -> t -> Element
mknode s attrs =
@@ -249,13 +255,16 @@ writeDocx opts doc@(Pandoc meta _) = do
let tocTitle = fromMaybe (stTocTitle defaultWriterState) $
metaValueToInlines <$> lookupMeta "toc-title" meta
- ((contents, footnotes), st) <- runStateT (writeOpenXML opts{writerWrapText = WrapNone} doc')
- defaultWriterState{ stChangesAuthor = fromMaybe "unknown" username
- , stChangesDate = formatTime defaultTimeLocale "%FT%XZ" utctime
- , stPrintWidth = (maybe 420 (\x -> quot x 20) pgContentWidth)
- , stStyleMaps = styleMaps
- , stTocTitle = tocTitle
- }
+ ((contents, footnotes), st) <- runStateT (
+ runReaderT
+ (writeOpenXML opts{writerWrapText = WrapNone} doc')
+ defaultWriterEnv
+ ) defaultWriterState{ stChangesAuthor = fromMaybe "unknown" username
+ , stChangesDate = formatTime defaultTimeLocale "%FT%XZ" utctime
+ , stPrintWidth = (maybe 420 (\x -> quot x 20) pgContentWidth)
+ , stStyleMaps = styleMaps
+ , stTocTitle = tocTitle
+ }
let epochtime = floor $ utcTimeToPOSIXSeconds utctime
let imgs = M.elems $ stImages st