git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Add support for w:rtl (ltr annotation).

Closes #5545.

commitad9770fe86d0f7d9e8ccfe09eada1e7a60ef3d25 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 4 Jun 2019, 09:49 (7 years ago) parentb5af8ee
2 files changed+19−4
src/Text/Pandoc/Readers/Docx.hs+11−1 src/Text/Pandoc/Readers/Docx/Parse.hs+8−3
src/Text/Pandoc/Readers/Docx.hs+11−1
@@ -252,13 +252,17 @@ resolveDependentRunStyle rPr
252252 , isStrike = case isStrike rPr of
253253 Just bool -> Just bool
254254 Nothing -> isStrike rPr'
255+ , isRTL = case isRTL rPr of
256+ Just bool -> Just bool
257+ Nothing -> isRTL rPr'
255258 , rVertAlign = case rVertAlign rPr of
256259 Just valign -> Just valign
257260 Nothing -> rVertAlign rPr'
258261 , rUnderline = case rUnderline rPr of
259262 Just ulstyle -> Just ulstyle
260263 Nothing -> rUnderline rPr'
261− , rStyle = rStyle rPr }
264+ , rStyle = rStyle rPr
265+ }
262266 | otherwise = return rPr
263267
264268runStyleToTransform :: PandocMonad m => RunStyle -> DocxContext m (Inlines -> Inlines)
@@ -286,6 +290,12 @@ runStyleToTransform rPr
286290 | Just True <- isStrike rPr = do
287291 transform <- runStyleToTransform rPr{isStrike = Nothing}
288292 return $ strikeout . transform
293+ | Just True <- isRTL rPr = do
294+ transform <- runStyleToTransform rPr{isRTL = Nothing}
295+ return $ spanWith ("",[],[("dir","rtl")]) . transform
296+ | Just False <- isRTL rPr = do
297+ transform <- runStyleToTransform rPr{isRTL = Nothing}
298+ return $ spanWith ("",[],[("dir","ltr")]) . transform
289299 | Just SupScrpt <- rVertAlign rPr = do
290300 transform <- runStyleToTransform rPr{rVertAlign = Nothing}
291301 return $ superscript . transform
src/Text/Pandoc/Readers/Docx/Parse.hs+8−3
@@ -289,9 +289,11 @@ data RunStyle = RunStyle { isBold :: Maybe Bool
289289 , isItalic :: Maybe Bool
290290 , isSmallCaps :: Maybe Bool
291291 , isStrike :: Maybe Bool
292+ , isRTL :: Maybe Bool
292293 , rVertAlign :: Maybe VertAlign
293294 , rUnderline :: Maybe String
294− , rStyle :: Maybe CharStyle}
295+ , rStyle :: Maybe CharStyle
296+ }
295297 deriving Show
296298
297299data ParStyleData = ParStyleData { headingLev :: Maybe (String, Int)
@@ -305,9 +307,11 @@ defaultRunStyle = RunStyle { isBold = Nothing
305307 , isItalic = Nothing
306308 , isSmallCaps = Nothing
307309 , isStrike = Nothing
310+ , isRTL = Nothing
308311 , rVertAlign = Nothing
309312 , rUnderline = Nothing
310− , rStyle = Nothing}
313+ , rStyle = Nothing
314+ }
311315
312316type Target = String
313317type Anchor = String
@@ -1106,6 +1110,7 @@ elemToRunStyle ns element parentStyle
11061110 checkOnOff ns rPr (elemName ns "w" "iCs")
11071111 , isSmallCaps = checkOnOff ns rPr (elemName ns "w" "smallCaps")
11081112 , isStrike = checkOnOff ns rPr (elemName ns "w" "strike")
1113+ , isRTL = checkOnOff ns rPr (elemName ns "w" "rtl")
11091114 , rVertAlign =
11101115 findChildByName ns "w" "vertAlign" rPr >>=
11111116 findAttrByName ns "w" "val" >>=
@@ -1117,7 +1122,7 @@ elemToRunStyle ns element parentStyle
11171122 findChildByName ns "w" "u" rPr >>=
11181123 findAttrByName ns "w" "val"
11191124 , rStyle = parentStyle
1120− }
1125+ }
11211126elemToRunStyle _ _ _ = defaultRunStyle
11221127
11231128getHeaderLevel :: NameSpaces -> Element -> Maybe (String,Int)