git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Avoid repeated spans in custom styles.

The previous commit had a bug where custom-style spans would be read with every recurrsion. This fixes that, and changes the example given in the manual.

commit87e0728b87846cdacb8866e19b9a8e127490b4bf authorJesse Rosenthal <jrosenthal@jhu.edu> dateThu 22 Feb 2018, 13:27 (9 years ago) parent03eda21
3 files changed+24−15
MANUAL.txt+3−4 src/Text/Pandoc/Readers/Docx.hs+20−10 test/docx/custom-style-with-styles.native+1−1
MANUAL.txt+3−4
@@ -4532,15 +4532,14 @@ Without the `+styles` extension:
45324532And with the extension:
45334533
45344534 $ pandoc test/docx/custom-style-reference.docx -f docx+styles -t markdown
4535+
45354536 ::: {custom-style="FirstParagraph"}
45364537 This is some text.
45374538 :::
45384539
45394540 ::: {custom-style="BodyText"}
4540− This is text with an
4541− *[[emphasized]{custom-style="Emphatic"}]{custom-style="Emphatic"}* text
4542− style. And this is text with a
4543− **[[strengthened]{custom-style="Strengthened"}]{custom-style="Strengthened"}**
4541+ This is text with an *[emphasized]{custom-style="Emphatic"}* text style.
4542+ And this is text with a **[strengthened]{custom-style="Strengthened"}**
45444543 text style.
45454544 :::
45464545
src/Text/Pandoc/Readers/Docx.hs+20−10
@@ -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
test/docx/custom-style-with-styles.native+1−1
@@ -1,7 +1,7 @@
11[Div ("",[],[("custom-style","FirstParagraph")])
22 [Para [Str "This",Space,Str "is",Space,Str "some",Space,Str "text."]]
33,Div ("",[],[("custom-style","BodyText")])
4− [Para [Str "This",Space,Str "is",Space,Str "text",Space,Str "with",Space,Str "an",Space,Emph [Span ("",[],[("custom-style","Emphatic")]) [Span ("",[],[("custom-style","Emphatic")]) [Str "emphasized"]]],Space,Str "text",Space,Str "style.",Space,Str "And",Space,Str "this",Space,Str "is",Space,Str "text",Space,Str "with",Space,Str "a",Space,Strong [Span ("",[],[("custom-style","Strengthened")]) [Span ("",[],[("custom-style","Strengthened")]) [Str "strengthened"]]],Space,Str "text",Space,Str "style."]]
4+ [Para [Str "This",Space,Str "is",Space,Str "text",Space,Str "with",Space,Str "an",Space,Emph [Span ("",[],[("custom-style","Emphatic")]) [Str "emphasized"]],Space,Str "text",Space,Str "style.",Space,Str "And",Space,Str "this",Space,Str "is",Space,Str "text",Space,Str "with",Space,Str "a",Space,Strong [Span ("",[],[("custom-style","Strengthened")]) [Str "strengthened"]],Space,Str "text",Space,Str "style."]]
55,Div ("",[],[("custom-style","MyBlockStyle")])
66 [BlockQuote
77 [Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "styled",Space,Str "paragraph",Space,Str "that",Space,Str "inherits",Space,Str "from",Space,Str "Block",Space,Str "Text."]]]]