aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2016-10-03 07:50:40 -0400
committerJesse Rosenthal <jrosenthal@jhu.edu>2016-10-03 07:50:40 -0400
commit6a3d1cf2108a2a6408098621b31cffb189c561f2 (patch)
treef09a636275e75439344418f0fc4f950a11568998 /src/Text/Pandoc/Writers
parent1435906f097fa8d5ad08728c3b95cd2992678230 (diff)
downloadpandoc-6a3d1cf2108a2a6408098621b31cffb189c561f2.tar.gz
Add ReaderT env to the docx writer:
This will allow us to add text and paragraph properties depending on if rtl is already set or not. (It would probably be cleaner and safer to move the paraprops and textprops to this part of the stack in the future.)
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