@@ -261,46 +261,43 @@ resolveDependentRunStyle rPr
261261 | otherwise = return rPr
262262
263263runStyleToTransform :: PandocMonad m => RunStyle -> DocxContext m (Inlines -> Inlines)
264−runStyleToTransform rPr
265− | Just sn <- getStyleName <$> rParentStyle rPr
266− , sn `elem` spansToKeep = do
267− transform <- runStyleToTransform rPr{rParentStyle = Nothing}
268− return $ spanWith ("", [normalizeToClassName sn], []) . transform
269− | Just s <- rParentStyle rPr = do
270− ei <- extraInfo spanWith s
271− transform <- runStyleToTransform rPr{rParentStyle = Nothing}
272− return $ ei . transform
273− | Just True <- isItalic rPr = do
274− transform <- runStyleToTransform rPr{isItalic = Nothing}
275− return $ emph . transform
276− | Just True <- isBold rPr = do
277− transform <- runStyleToTransform rPr{isBold = Nothing}
278− return $ strong . transform
279− | Just True <- isSmallCaps rPr = do
280− transform <- runStyleToTransform rPr{isSmallCaps = Nothing}
281− return $ smallcaps . transform
282− | Just True <- isStrike rPr = do
283− transform <- runStyleToTransform rPr{isStrike = Nothing}
284− return $ strikeout . transform
285− | Just True <- isRTL rPr = do
286− transform <- runStyleToTransform rPr{isRTL = Nothing}
287− return $ spanWith ("",[],[("dir","rtl")]) . transform
288− | Just False <- isRTL rPr = do
289− transform <- runStyleToTransform rPr{isRTL = Nothing}
290− inBidi <- asks docxInBidi
291− return $ if inBidi
292− then spanWith ("",[],[("dir","ltr")]) . transform
293− else transform
294− | Just SupScrpt <- rVertAlign rPr = do
295− transform <- runStyleToTransform rPr{rVertAlign = Nothing}
296− return $ superscript . transform
297− | Just SubScrpt <- rVertAlign rPr = do
298− transform <- runStyleToTransform rPr{rVertAlign = Nothing}
299− return $ subscript . transform
300− | Just "single" <- rUnderline rPr = do
301− transform <- runStyleToTransform rPr{rUnderline = Nothing}
302− return $ Pandoc.underline . transform
303− | otherwise = return id
264+runStyleToTransform rPr' = do
265+ opts <- asks docxOptions
266+ inBidi <- asks docxInBidi
267+ let styles = isEnabled Ext_styles opts
268+ ctl = (Just True == isRTL rPr') || (Just True == isForceCTL rPr')
269+ italic rPr | ctl = isItalicCTL rPr
270+ | otherwise = isItalic rPr
271+ bold rPr | ctl = isBoldCTL rPr
272+ | otherwise = isBold rPr
273+ go rPr
274+ | Just sn <- getStyleName <$> rParentStyle rPr
275+ , sn `elem` spansToKeep =
276+ spanWith ("", [normalizeToClassName sn], [])
277+ . go rPr{rParentStyle = Nothing}
278+ | styles, Just s <- rParentStyle rPr =
279+ spanWith (extraAttr s) . go rPr{rParentStyle = Nothing}
280+ | Just True <- italic rPr =
281+ emph . go rPr{isItalic = Nothing, isItalicCTL = Nothing}
282+ | Just True <- bold rPr =
283+ strong . go rPr{isBold = Nothing, isBoldCTL = Nothing}
284+ | Just True <- isSmallCaps rPr =
285+ smallcaps . go rPr{isSmallCaps = Nothing}
286+ | Just True <- isStrike rPr =
287+ strikeout . go rPr{isStrike = Nothing}
288+ | Just True <- isRTL rPr =
289+ spanWith ("",[],[("dir","rtl")]) . go rPr{isRTL = Nothing}
290+ | inBidi, Just False <- isRTL rPr =
291+ spanWith ("",[],[("dir","ltr")]) . go rPr{isRTL = Nothing}
292+ | Just SupScrpt <- rVertAlign rPr =
293+ superscript . go rPr{rVertAlign = Nothing}
294+ | Just SubScrpt <- rVertAlign rPr = do
295+ subscript . go rPr{rVertAlign = Nothing}
296+ | Just "single" <- rUnderline rPr = do
297+ Pandoc.underline . go rPr{rUnderline = Nothing}
298+ | otherwise = id
299+ return $ go rPr'
300+
304301
305302runToInlines :: PandocMonad m => Run -> DocxContext m Inlines
306303runToInlines (Run rs runElems)
@@ -512,13 +509,8 @@ trimSps (Many ils) = Many $ Seq.dropWhileL isSp $Seq.dropWhileR isSp ils
512509 isSp LineBreak = True
513510 isSp _ = False
514511
515−extraInfo :: (Eq (StyleName a), PandocMonad m, HasStyleName a)
516− => (Attr -> i -> i) -> a -> DocxContext m (i -> i)
517−extraInfo f s = do
518− opts <- asks docxOptions
519− return $ if isEnabled Ext_styles opts
520− then f ("", [], [("custom-style", fromStyleName $ getStyleName s)])
521− else id
512+extraAttr :: (Eq (StyleName a), HasStyleName a) => a -> Attr
513+extraAttr s = ("", [], [("custom-style", fromStyleName $ getStyleName s)])
522514
523515parStyleToTransform :: PandocMonad m => ParagraphStyle -> DocxContext m (Blocks -> Blocks)
524516parStyleToTransform pPr = case pStyle pPr of
@@ -534,8 +526,11 @@ parStyleToTransform pPr = case pStyle pPr of
534526 | otherwise -> do
535527 let pPr' = pPr { pStyle = cs }
536528 transform <- parStyleToTransform pPr'
537− ei <- extraInfo divWith c
538− return $ ei . (if isBlockQuote c then blockQuote else id) . transform
529+ styles <- asks (isEnabled Ext_styles . docxOptions)
530+ return $
531+ (if styles then divWith (extraAttr c) else id)
532+ . (if isBlockQuote c then blockQuote else id)
533+ . transform
539534 []
540535 | Just left <- indentation pPr >>= leftParIndent -> do
541536 let pPr' = pPr { indentation = Nothing }