git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: simplify custom-style reading code.
commit3e10caad63b8886a8eff9d0372c7c68eb57f4610 authorJesse Rosenthal <jrosenthal@jhu.edu> dateFri 23 Feb 2018, 14:47 (9 years ago) parent5ada5cc
1 file changed+23−41
src/Text/Pandoc/Readers/Docx.hs+23−41
src/Text/Pandoc/Readers/Docx.hs+23−41
@@ -142,11 +142,10 @@ instance Default DState where
142142
143143data DEnv = DEnv { docxOptions :: ReaderOptions
144144 , docxInHeaderBlock :: Bool
145− , docxCustomStyleAlready :: Bool
146145 }
147146
148147instance Default DEnv where
149− def = DEnv def False False
148+ def = DEnv def False
150149
151150type DocxContext m = ReaderT DEnv (StateT DState m)
152151
@@ -283,16 +282,6 @@ resolveDependentRunStyle rPr
283282 , rStyle = rStyle rPr }
284283 | otherwise = return rPr
285284
286−extraRunStyleInfo :: PandocMonad m => RunStyle -> DocxContext m (Inlines -> Inlines)
287−extraRunStyleInfo rPr
288− | Just (s, _) <- rStyle rPr = do
289− already <- asks docxCustomStyleAlready
290− opts <- asks docxOptions
291− return $ if isEnabled Ext_styles opts && not already
292− then spanWith ("", [], [("custom-style", s)])
293− else id
294− | otherwise = return id
295−
296285runStyleToTransform :: PandocMonad m => RunStyle -> DocxContext m (Inlines -> Inlines)
297286runStyleToTransform rPr
298287 | Just (s, _) <- rStyle rPr
@@ -300,42 +289,35 @@ runStyleToTransform rPr
300289 let rPr' = rPr{rStyle = Nothing}
301290 transform <- runStyleToTransform rPr'
302291 return $ spanWith ("", [s], []) . transform
292+ | Just (s, _) <- rStyle rPr = do
293+ opts <- asks docxOptions
294+ let extraInfo = if isEnabled Ext_styles opts
295+ then spanWith ("", [], [("custom-style", s)])
296+ else id
297+ transform <- runStyleToTransform rPr {rStyle = Nothing}
298+ return $ extraInfo . transform
303299 | Just True <- isItalic rPr = do
304− extraInfo <- extraRunStyleInfo rPr
305− transform <- local (\e -> e{docxCustomStyleAlready = True}) $
306− runStyleToTransform rPr {isItalic = Nothing}
307− return $ extraInfo . emph . transform
300+ transform <- runStyleToTransform rPr {isItalic = Nothing}
301+ return $ emph . transform
308302 | Just True <- isBold rPr = do
309− extraInfo <- extraRunStyleInfo rPr
310− transform <- local (\e -> e{docxCustomStyleAlready = True}) $
311− runStyleToTransform rPr {isBold = Nothing}
312− return $ extraInfo . strong . transform
303+ transform <- runStyleToTransform rPr {isBold = Nothing}
304+ return $ strong . transform
313305 | Just True <- isSmallCaps rPr = do
314− extraInfo <- extraRunStyleInfo rPr
315− transform <- local (\e -> e{docxCustomStyleAlready = True}) $
316− runStyleToTransform rPr {isSmallCaps = Nothing}
317− return $ extraInfo . smallcaps . transform
306+ transform <- runStyleToTransform rPr {isSmallCaps = Nothing}
307+ return $ smallcaps . transform
318308 | Just True <- isStrike rPr = do
319− extraInfo <- extraRunStyleInfo rPr
320− transform <- local (\e -> e{docxCustomStyleAlready = True}) $
321− runStyleToTransform rPr {isStrike = Nothing}
322− return $ extraInfo . strikeout . transform
309+ transform <- runStyleToTransform rPr {isStrike = Nothing}
310+ return $ strikeout . transform
323311 | Just SupScrpt <- rVertAlign rPr = do
324− extraInfo <- extraRunStyleInfo rPr
325− transform <- local (\e -> e{docxCustomStyleAlready = True}) $
326− runStyleToTransform rPr {rVertAlign = Nothing}
327− return $ extraInfo . superscript . transform
312+ transform <- runStyleToTransform rPr {rVertAlign = Nothing}
313+ return $ superscript . transform
328314 | Just SubScrpt <- rVertAlign rPr = do
329− extraInfo <- extraRunStyleInfo rPr
330− transform <- local (\e -> e{docxCustomStyleAlready = True}) $
331− runStyleToTransform rPr {rVertAlign = Nothing}
332− return $ extraInfo . subscript . transform
315+ transform <- runStyleToTransform rPr {rVertAlign = Nothing}
316+ return $ subscript . transform
333317 | Just "single" <- rUnderline rPr = do
334− extraInfo <- extraRunStyleInfo rPr
335− transform <- local (\e -> e{docxCustomStyleAlready = True}) $
336− runStyleToTransform rPr {rUnderline = Nothing}
337− return $ extraInfo . underlineSpan . transform
338− | otherwise = extraRunStyleInfo rPr
318+ transform <- runStyleToTransform rPr {rUnderline = Nothing}
319+ return $ underlineSpan . transform
320+ | otherwise = return id
339321
340322runToInlines :: PandocMonad m => Run -> DocxContext m Inlines
341323runToInlines (Run rs runElems)