@@ -141,10 +141,12 @@ instance Default DState where
141141 }
142142
143143data DEnv = DEnv { docxOptions :: ReaderOptions
144− , docxInHeaderBlock :: Bool }
144+ , docxInHeaderBlock :: Bool
145+ , docxCustomStyleAlready :: Bool
146+ }
145147
146148instance Default DEnv where
147− def = DEnv def False
149+ def = DEnv def False False
148150
149151type DocxContext m = ReaderT DEnv (StateT DState m)
150152
@@ -281,8 +283,9 @@ resolveDependentRunStyle rPr
281283extraRunStyleInfo :: PandocMonad m => RunStyle -> DocxContext m (Inlines -> Inlines)
282284extraRunStyleInfo rPr
283285 | Just (s, _) <- rStyle rPr = do
286+ already <- asks docxCustomStyleAlready
284287 opts <- asks docxOptions
285− return $ if isEnabled Ext_styles opts
288+ return $ if isEnabled Ext_styles opts && not already
286289 then spanWith ("", [], [("custom-style", s)])
287290 else id
288291 | otherwise = return id
@@ -295,32 +298,39 @@ runStyleToTransform rPr
295298 transform <- runStyleToTransform rPr'
296299 return $ spanWith ("", [s], []) . transform
297300 | Just True <- isItalic rPr = do
298− transform <- runStyleToTransform rPr {isItalic = Nothing}
299301 extraInfo <- extraRunStyleInfo rPr
302+ transform <- local (\e -> e{docxCustomStyleAlready = True}) $
303+ runStyleToTransform rPr {isItalic = Nothing}
300304 return $ emph . extraInfo . transform
301305 | Just True <- isBold rPr = do
302− transform <- runStyleToTransform rPr {isBold = Nothing}
303306 extraInfo <- extraRunStyleInfo rPr
307+ transform <- local (\e -> e{docxCustomStyleAlready = True}) $
308+ runStyleToTransform rPr {isBold = Nothing}
304309 return $ strong . extraInfo . transform
305310 | Just True <- isSmallCaps rPr = do
306− transform <- runStyleToTransform rPr {isSmallCaps = Nothing}
307311 extraInfo <- extraRunStyleInfo rPr
312+ transform <- local (\e -> e{docxCustomStyleAlready = True}) $
313+ runStyleToTransform rPr {isSmallCaps = Nothing}
308314 return $ smallcaps . extraInfo .transform
309315 | Just True <- isStrike rPr = do
310− transform <- runStyleToTransform rPr {isStrike = Nothing}
311316 extraInfo <- extraRunStyleInfo rPr
317+ transform <- local (\e -> e{docxCustomStyleAlready = True}) $
318+ runStyleToTransform rPr {isStrike = Nothing}
312319 return $ strikeout . extraInfo . transform
313320 | Just SupScrpt <- rVertAlign rPr = do
314− transform <- runStyleToTransform rPr {rVertAlign = Nothing}
315321 extraInfo <- extraRunStyleInfo rPr
322+ transform <- local (\e -> e{docxCustomStyleAlready = True}) $
323+ runStyleToTransform rPr {rVertAlign = Nothing}
316324 return $ superscript . extraInfo . transform
317325 | Just SubScrpt <- rVertAlign rPr = do
318− transform <- runStyleToTransform rPr {rVertAlign = Nothing}
319326 extraInfo <- extraRunStyleInfo rPr
327+ transform <- local (\e -> e{docxCustomStyleAlready = True}) $
328+ runStyleToTransform rPr {rVertAlign = Nothing}
320329 return $ subscript . extraInfo . transform
321330 | Just "single" <- rUnderline rPr = do
322− transform <- runStyleToTransform rPr {rUnderline = Nothing}
323331 extraInfo <- extraRunStyleInfo rPr
332+ transform <- local (\e -> e{docxCustomStyleAlready = True}) $
333+ runStyleToTransform rPr {rUnderline = Nothing}
324334 return $ underlineSpan . extraInfo . transform
325335 | otherwise = extraRunStyleInfo rPr
326336