git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: accept explicit "Italic" and "Bold" rStyles.

Note that "Italic" can be on, and, from the last commit, `<w:i>` can be present, but be turned off. In that case, the turned-off tag takes precedence. So, we have to distinguish between something being off and something not being there. Hence, isItalic, isBold, isStrike, and isSmallCaps have become Maybes.

commit194ed8885236d8446b34f44ecf16d4fa9e5c5cbe authorJesse Rosenthal <jrosenthal@jhu.edu> dateTue 12 Aug 2014, 22:15 (12 years ago) parentaae71ad
2 files changed+31−18
src/Text/Pandoc/Readers/Docx.hs+18−5 src/Text/Pandoc/Readers/Docx/Parse.hs+13−13
src/Text/Pandoc/Readers/Docx.hs+18−5
@@ -202,17 +202,30 @@ runStyleToContainers rPr =
202202 [Container $ (\ils -> Code ("", [], []) (concatMap ilToCode ils))]
203203 spanClassToContainers s | s `elem` spansToKeep =
204204 [Container $ Span ("", [s], [])]
205− spanClassToContainers _ = []
205+ spanClassToContainers _ = []
206206
207207 classContainers = case rStyle rPr of
208208 Nothing -> []
209209 Just s -> spanClassToContainers s
210210
211+ resolveFmt :: Bool -> Maybe Bool -> Bool
212+ resolveFmt _ (Just True) = True
213+ resolveFmt _ (Just False) = False
214+ resolveFmt bool Nothing = bool
215+
211216 formatters = map Container $ mapMaybe id
212− [ if isBold rPr then (Just Strong) else Nothing
213− , if isItalic rPr then (Just Emph) else Nothing
214− , if isSmallCaps rPr then (Just SmallCaps) else Nothing
215− , if isStrike rPr then (Just Strikeout) else Nothing
217+ [ if resolveFmt (rStyle rPr == Just "Bold") (isBold rPr)
218+ then (Just Strong)
219+ else Nothing
220+ , if resolveFmt (rStyle rPr == Just "Italic") (isItalic rPr)
221+ then (Just Emph)
222+ else Nothing
223+ , if resolveFmt False (isSmallCaps rPr)
224+ then (Just SmallCaps)
225+ else Nothing
226+ , if resolveFmt False (isStrike rPr)
227+ then (Just Strikeout)
228+ else Nothing
216229 , if isSuperScript rPr then (Just Superscript) else Nothing
217230 , if isSubScript rPr then (Just Subscript) else Nothing
218231 , rUnderline rPr >>=
src/Text/Pandoc/Readers/Docx/Parse.hs+13−13
@@ -196,10 +196,10 @@ data Run = Run RunStyle [RunElem]
196196data RunElem = TextRun String | LnBrk | Tab
197197 deriving Show
198198
199−data RunStyle = RunStyle { isBold :: Bool
200− , isItalic :: Bool
201− , isSmallCaps :: Bool
202− , isStrike :: Bool
199+data RunStyle = RunStyle { isBold :: Maybe Bool
200+ , isItalic :: Maybe Bool
201+ , isSmallCaps :: Maybe Bool
202+ , isStrike :: Maybe Bool
203203 , isSuperScript :: Bool
204204 , isSubScript :: Bool
205205 , rUnderline :: Maybe String
@@ -207,10 +207,10 @@ data RunStyle = RunStyle { isBold :: Bool
207207 deriving Show
208208
209209defaultRunStyle :: RunStyle
210−defaultRunStyle = RunStyle { isBold = False
211− , isItalic = False
212− , isSmallCaps = False
213− , isStrike = False
210+defaultRunStyle = RunStyle { isBold = Nothing
211+ , isItalic = Nothing
212+ , isSmallCaps = Nothing
213+ , isStrike = Nothing
214214 , isSuperScript = False
215215 , isSubScript = False
216216 , rUnderline = Nothing
@@ -652,20 +652,20 @@ elemToParagraphStyle ns element
652652 }
653653elemToParagraphStyle _ _ = defaultParagraphStyle
654654
655−checkOnOff :: NameSpaces -> Element -> QName -> Bool
655+checkOnOff :: NameSpaces -> Element -> QName -> Maybe Bool
656656checkOnOff ns rPr tag
657657 | Just t <- findChild tag rPr
658658 , Just val <- findAttr (elemName ns "w" "val") t =
659− case val of
660− "true" -> True
659+ Just $ case val of
660+ "true" -> True
661661 "false" -> False
662662 "on" -> True
663663 "off" -> False
664664 "1" -> True
665665 "0" -> False
666666 _ -> False
667− | Just _ <- findChild tag rPr = True
668−checkOnOff _ _ _ = False
667+ | Just _ <- findChild tag rPr = Just True
668+checkOnOff _ _ _ = Nothing
669669
670670
671671elemToRunStyle :: NameSpaces -> Element -> RunStyle