diff options
author | Jesse Rosenthal <jrosenthal@jhu.edu> | 2016-10-03 21:33:57 -0400 |
---|---|---|
committer | Jesse Rosenthal <jrosenthal@jhu.edu> | 2016-10-03 21:39:40 -0400 |
commit | ab31d5ea8d0fc17b900a5843104784a25a2c8ed9 (patch) | |
tree | 22a4853c938928874fb80872b4e18a0dd50f5f32 /src/Text/Pandoc/Writers | |
parent | 666c042e80b82f969b67224046c2905e61fc7213 (diff) | |
download | pandoc-ab31d5ea8d0fc17b900a5843104784a25a2c8ed9.tar.gz |
Remove bool on setRTL.
We had to use this because we set the env, which means that setRTL
wouldn't do anything at the top level. We now don't set the env (it will
always be false at the outset), which means the toplevel setRTL will
work if necessary.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r-- | src/Text/Pandoc/Writers/Docx.hs | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 36e20fc61..407df18e7 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -261,16 +261,9 @@ writeDocx opts doc@(Pandoc meta _) = do let tocTitle = fromMaybe (stTocTitle defaultWriterState) $ metaValueToInlines <$> lookupMeta "toc-title" meta - let isRTL = case lookupMeta "dir" meta of - Just (MetaString "rtl") -> True - Just (MetaInlines [Str "rtl"]) -> True - _ -> False - - ((contents, footnotes), st) <- runStateT ( - runReaderT - (writeOpenXML opts{writerWrapText = WrapNone} doc') - defaultWriterEnv { envRTL = isRTL } - ) defaultWriterState{ stChangesAuthor = fromMaybe "unknown" username + ((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 @@ -723,8 +716,11 @@ makeTOC _ = return [] -- OpenXML elements (the main document and footnotes). writeOpenXML :: WriterOptions -> Pandoc -> WS ([Element], [Element]) writeOpenXML opts (Pandoc meta blocks) = do - isRTL <- asks envRTL - (if isRTL then (setRTL True) else id) $ do + let isRTL = case lookupMeta "dir" meta of + Just (MetaString "rtl") -> True + Just (MetaInlines [Str "rtl"]) -> True + _ -> False + (if isRTL then setRTL else id) $ do let tit = docTitle meta ++ case lookupMeta "subtitle" meta of Just (MetaBlocks [Plain xs]) -> LineBreak : xs _ -> [] @@ -797,7 +793,7 @@ blockToOpenXML opts (Div (ident,classes,kvs) bs) withParaPropM (pStyleM sty) $ blocksToOpenXML opts bs | Just "rtl" <- lookup "dir" kvs = do let kvs' = filter (("dir", "rtl")/=) kvs - setRTL False $ blockToOpenXML opts (Div (ident,classes,kvs') bs) + setRTL $ blockToOpenXML opts (Div (ident,classes,kvs') bs) | Just "ltr" <- lookup "dir" kvs = do let kvs' = filter (("dir", "ltr")/=) kvs setLTR $ blockToOpenXML opts (Div (ident,classes,kvs') bs) @@ -1042,7 +1038,7 @@ inlineToOpenXML opts (Span (ident,classes,kvs) ils) inlineToOpenXML opts (Span (ident,classes,kvs') ils) | Just "rtl" <- lookup "dir" kvs = do let kvs' = filter (("dir", "rtl")/=) kvs - setRTL False $ inlineToOpenXML opts (Span (ident,classes,kvs') ils) + setRTL $ inlineToOpenXML opts (Span (ident,classes,kvs') ils) | Just "ltr" <- lookup "dir" kvs = do let kvs' = filter (("dir", "ltr")/=) kvs setLTR $ inlineToOpenXML opts (Span (ident,classes,kvs') ils) @@ -1275,10 +1271,10 @@ fitToPage (x, y) pageWidth (pageWidth, floor $ ((fromIntegral pageWidth) / x) * y) | otherwise = (floor x, floor y) -setRTL :: Bool -> WS a -> WS a -setRTL topLevel x = do +setRTL :: WS a -> WS a +setRTL x = do isRTL <- asks envRTL - if isRTL && not topLevel + if isRTL then x else flip local x $ \env -> env { envRTL = True |