git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Only use LTR when it is overriding BiDi setting

The left-to-right direction setting in docx is used in the spec only for overriding an explicit right-to-left setting. We only process it when it happens in a paragraph set with BiDi. This is especially important for docs exported from Google Docs, which explicitly (and unnecessarily) set "rtl=0" for every paragraph. Closes: #5723

commit11945ea5ec0a9ed42b0c24f6f9ecff69e86784a1 authorJesse Rosenthal <jrosenthal@jhu.edu> dateSun 3 Nov 2019, 21:25 (7 years ago) parenta6612b3
3 files changed+14−2
src/Text/Pandoc/Readers/Docx.hs+10−2 src/Text/Pandoc/Readers/Docx/Parse.hs+3 src/Text/Pandoc/Readers/Docx/Parse/Styles.hs+1
src/Text/Pandoc/Readers/Docx.hs+10−2
@@ -124,10 +124,11 @@ instance Default DState where
124124
125125data DEnv = DEnv { docxOptions :: ReaderOptions
126126 , docxInHeaderBlock :: Bool
127+ , docxInBidi :: Bool
127128 }
128129
129130instance Default DEnv where
130− def = DEnv def False
131+ def = DEnv def False False
131132
132133type DocxContext m = ReaderT DEnv (StateT DState m)
133134
@@ -290,7 +291,10 @@ runStyleToTransform rPr
290291 return $ spanWith ("",[],[("dir","rtl")]) . transform
291292 | Just False <- isRTL rPr = do
292293 transform <- runStyleToTransform rPr{isRTL = Nothing}
293− return $ spanWith ("",[],[("dir","ltr")]) . transform
294+ inBidi <- asks docxInBidi
295+ return $ if inBidi
296+ then spanWith ("",[],[("dir","ltr")]) . transform
297+ else transform
294298 | Just SupScrpt <- rVertAlign rPr = do
295299 transform <- runStyleToTransform rPr{rVertAlign = Nothing}
296300 return $ superscript . transform
@@ -561,6 +565,10 @@ normalizeToClassName = map go . fromStyleName
561565
562566bodyPartToBlocks :: PandocMonad m => BodyPart -> DocxContext m Blocks
563567bodyPartToBlocks (Paragraph pPr parparts)
568+ | Just True <- pBidi pPr = do
569+ let pPr' = pPr { pBidi = Nothing }
570+ local (\s -> s{ docxInBidi = True })
571+ (bodyPartToBlocks (Paragraph pPr' parparts))
564572 | isCodeDiv pPr = do
565573 transform <- parStyleToTransform pPr
566574 return $
src/Text/Pandoc/Readers/Docx/Parse.hs+3
@@ -224,6 +224,7 @@ data ParagraphStyle = ParagraphStyle { pStyle :: [ParStyle]
224224 , indentation :: Maybe ParIndentation
225225 , dropCap :: Bool
226226 , pChange :: Maybe TrackedChange
227+ , pBidi :: Maybe Bool
227228 }
228229 deriving Show
229230
@@ -232,6 +233,7 @@ defaultParagraphStyle = ParagraphStyle { pStyle = []
232233 , indentation = Nothing
233234 , dropCap = False
234235 , pChange = Nothing
236+ , pBidi = Just False
235237 }
236238
237239
@@ -998,6 +1000,7 @@ elemToParagraphStyle ns element sty
9981000 isElem ns "w" "moveFrom" e
9991001 ) >>=
10001002 getTrackedChange ns
1003+ , pBidi = checkOnOff ns pPr (elemName ns "w" "bidi")
10011004 }
10021005elemToParagraphStyle _ _ _ = defaultParagraphStyle
10031006
src/Text/Pandoc/Readers/Docx/Parse/Styles.hs+1
@@ -40,6 +40,7 @@ module Text.Pandoc.Readers.Docx.Parse.Styles (
4040 , getNumInfo
4141 , elemToRunStyle
4242 , defaultRunStyle
43+ , checkOnOff
4344 ) where
4445import Prelude
4546import Codec.Archive.Zip