git.iko.soy/typeable/pandoc
on master help sign in
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.)

commit6a3d1cf2108a2a6408098621b31cffb189c561f2 authorJesse Rosenthal <jrosenthal@jhu.edu> dateMon 3 Oct 2016, 07:50 (10 years ago) parent1435906
1 file changed+17−8
src/Text/Pandoc/Writers/Docx.hs+17−8
src/Text/Pandoc/Writers/Docx.hs+17−8
@@ -54,6 +54,7 @@ import Text.XML.Light as XML
5454import Text.TeXMath
5555import Text.Pandoc.Readers.Docx.StyleMap
5656import Text.Pandoc.Readers.Docx.Util (elemName)
57+import Control.Monad.Reader
5758import Control.Monad.State
5859import Text.Highlighting.Kate
5960import Data.Unique (hashUnique, newUnique)
@@ -91,6 +92,11 @@ listMarkerToId (NumberMarker sty delim n) =
9192 OneParen -> '2'
9293 TwoParens -> '3'
9394
95+data WriterEnv = WriterEnv{ envRTL :: Bool }
96+
97+defaultWriterEnv :: WriterEnv
98+defaultWriterEnv = WriterEnv{ envRTL = False }
99+
94100data WriterState = WriterState{
95101 stTextProperties :: [Element]
96102 , stParaProperties :: [Element]
@@ -138,7 +144,7 @@ defaultWriterState = WriterState{
138144 , stDynamicTextProps = []
139145 }
140146
141−type WS a = StateT WriterState IO a
147+type WS = ReaderT WriterEnv (StateT WriterState IO)
142148
143149mknode :: Node t => String -> [(String,String)] -> t -> Element
144150mknode s attrs =
@@ -249,13 +255,16 @@ writeDocx opts doc@(Pandoc meta _) = do
249255 let tocTitle = fromMaybe (stTocTitle defaultWriterState) $
250256 metaValueToInlines <$> lookupMeta "toc-title" meta
251257
252− ((contents, footnotes), st) <- runStateT (writeOpenXML opts{writerWrapText = WrapNone} doc')
253− defaultWriterState{ stChangesAuthor = fromMaybe "unknown" username
254− , stChangesDate = formatTime defaultTimeLocale "%FT%XZ" utctime
255− , stPrintWidth = (maybe 420 (\x -> quot x 20) pgContentWidth)
256− , stStyleMaps = styleMaps
257− , stTocTitle = tocTitle
258− }
258+ ((contents, footnotes), st) <- runStateT (
259+ runReaderT
260+ (writeOpenXML opts{writerWrapText = WrapNone} doc')
261+ defaultWriterEnv
262+ ) defaultWriterState{ stChangesAuthor = fromMaybe "unknown" username
263+ , stChangesDate = formatTime defaultTimeLocale "%FT%XZ" utctime
264+ , stPrintWidth = (maybe 420 (\x -> quot x 20) pgContentWidth)
265+ , stStyleMaps = styleMaps
266+ , stTocTitle = tocTitle
267+ }
259268 let epochtime = floor $ utcTimeToPOSIXSeconds utctime
260269 let imgs = M.elems $ stImages st
261270