git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Don't look up dependant run styles if +styles is enabled.

It makes more sense not to interpret -- otherwise using the original document as the reference-doc would produce two of everything: the interpreted version and the uninterpreted style version.

commit5ada5cceaceb05316dbb7241bca7d3effb4d9767 authorJesse Rosenthal <jrosenthal@jhu.edu> dateFri 23 Feb 2018, 14:23 (9 years ago) parent8f8f0f8
3 files changed+42−39
MANUAL.txt+2−2 src/Text/Pandoc/Readers/Docx.hs+39−36 test/docx/custom-style-with-styles.native+1−1
MANUAL.txt+2−2
@@ -4562,8 +4562,8 @@ And with the extension:
45624562 :::
45634563
45644564 ::: {custom-style="BodyText"}
4565− This is text with an [*emphasized*]{custom-style="Emphatic"} text style.
4566− And this is text with a [**strengthened**]{custom-style="Strengthened"}
4565+ This is text with an [emphasized]{custom-style="Emphatic"} text style.
4566+ And this is text with a [strengthened]{custom-style="Strengthened"}
45674567 text style.
45684568 :::
45694569
src/Text/Pandoc/Readers/Docx.hs+39−36
@@ -252,33 +252,36 @@ parPartToString _ = ""
252252blacklistedCharStyles :: [String]
253253blacklistedCharStyles = ["Hyperlink"]
254254
255−resolveDependentRunStyle :: RunStyle -> RunStyle
255+resolveDependentRunStyle :: PandocMonad m => RunStyle -> DocxContext m RunStyle
256256resolveDependentRunStyle rPr
257257 | Just (s, _) <- rStyle rPr, s `elem` blacklistedCharStyles =
258− rPr
259− | Just (_, cs) <- rStyle rPr =
260− let rPr' = resolveDependentRunStyle cs
261− in
262− RunStyle { isBold = case isBold rPr of
263− Just bool -> Just bool
264− Nothing -> isBold rPr'
265− , isItalic = case isItalic rPr of
266− Just bool -> Just bool
267− Nothing -> isItalic rPr'
268− , isSmallCaps = case isSmallCaps rPr of
269− Just bool -> Just bool
270− Nothing -> isSmallCaps rPr'
271− , isStrike = case isStrike rPr of
272− Just bool -> Just bool
273− Nothing -> isStrike rPr'
274− , rVertAlign = case rVertAlign rPr of
275− Just valign -> Just valign
276− Nothing -> rVertAlign rPr'
277− , rUnderline = case rUnderline rPr of
278− Just ulstyle -> Just ulstyle
279− Nothing -> rUnderline rPr'
280− , rStyle = rStyle rPr }
281− | otherwise = rPr
258+ return rPr
259+ | Just (_, cs) <- rStyle rPr = do
260+ opts <- asks docxOptions
261+ if isEnabled Ext_styles opts
262+ then return rPr
263+ else do rPr' <- resolveDependentRunStyle cs
264+ return $
265+ RunStyle { isBold = case isBold rPr of
266+ Just bool -> Just bool
267+ Nothing -> isBold rPr'
268+ , isItalic = case isItalic rPr of
269+ Just bool -> Just bool
270+ Nothing -> isItalic rPr'
271+ , isSmallCaps = case isSmallCaps rPr of
272+ Just bool -> Just bool
273+ Nothing -> isSmallCaps rPr'
274+ , isStrike = case isStrike rPr of
275+ Just bool -> Just bool
276+ Nothing -> isStrike rPr'
277+ , rVertAlign = case rVertAlign rPr of
278+ Just valign -> Just valign
279+ Nothing -> rVertAlign rPr'
280+ , rUnderline = case rUnderline rPr of
281+ Just ulstyle -> Just ulstyle
282+ Nothing -> rUnderline rPr'
283+ , rStyle = rStyle rPr }
284+ | otherwise = return rPr
282285
283286extraRunStyleInfo :: PandocMonad m => RunStyle -> DocxContext m (Inlines -> Inlines)
284287extraRunStyleInfo rPr
@@ -337,18 +340,18 @@ runStyleToTransform rPr
337340runToInlines :: PandocMonad m => Run -> DocxContext m Inlines
338341runToInlines (Run rs runElems)
339342 | Just (s, _) <- rStyle rs
340− , s `elem` codeStyles =
341− let rPr = resolveDependentRunStyle rs
342− codeString = code $ concatMap runElemToString runElems
343− in
344− return $ case rVertAlign rPr of
345− Just SupScrpt -> superscript codeString
346− Just SubScrpt -> subscript codeString
347− _ -> codeString
343+ , s `elem` codeStyles = do
344+ rPr <- resolveDependentRunStyle rs
345+ let codeString = code $ concatMap runElemToString runElems
346+ return $ case rVertAlign rPr of
347+ Just SupScrpt -> superscript codeString
348+ Just SubScrpt -> subscript codeString
349+ _ -> codeString
348350 | otherwise = do
349− let ils = smushInlines (map runElemToInlines runElems)
350− transform <- runStyleToTransform $ resolveDependentRunStyle rs
351− return $ transform ils
351+ rPr <- resolveDependentRunStyle rs
352+ let ils = smushInlines (map runElemToInlines runElems)
353+ transform <- runStyleToTransform rPr
354+ return $ transform ils
352355runToInlines (Footnote bps) = do
353356 blksList <- smushBlocks <$> mapM bodyPartToBlocks bps
354357 return $ note blksList
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,Span ("",[],[("custom-style","Emphatic")]) [Emph [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,Span ("",[],[("custom-style","Strengthened")]) [Strong [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,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,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."]]]]