git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: accept explicit "Italic" and "Bold" rStyles.
194ed88Jesse Rosenthal
src/Text/Pandoc/Readers/Docx.hs+18−5
@@ -202,17 +202,30 @@ runStyleToContainers rPr =
202 [Container $ (\ils -> Code ("", [], []) (concatMap ilToCode ils))]
202 [Container $ (\ils -> Code ("", [], []) (concatMap ilToCode ils))]
203 spanClassToContainers s | s `elem` spansToKeep =
203 spanClassToContainers s | s `elem` spansToKeep =
204 [Container $ Span ("", [s], [])]
204 [Container $ Span ("", [s], [])]
205− spanClassToContainers _ = []
205+ spanClassToContainers _ = []
206
206
207 classContainers = case rStyle rPr of
207 classContainers = case rStyle rPr of
208 Nothing -> []
208 Nothing -> []
209 Just s -> spanClassToContainers s
209 Just s -> spanClassToContainers s
210
210
211+ resolveFmt :: Bool -> Maybe Bool -> Bool
212+ resolveFmt _ (Just True) = True
213+ resolveFmt _ (Just False) = False
214+ resolveFmt bool Nothing = bool
215+
211 formatters = map Container $ mapMaybe id
216 formatters = map Container $ mapMaybe id
217+ [ if resolveFmt (rStyle rPr == Just "Bold") (isBold rPr)
212− [ if isBold rPr then (Just Strong) else Nothing
218+ then (Just Strong)
219+ else Nothing
220+ , if resolveFmt (rStyle rPr == Just "Italic") (isItalic rPr)
213− , if isItalic rPr then (Just Emph) else Nothing
221+ then (Just Emph)
222+ else Nothing
223+ , if resolveFmt False (isSmallCaps rPr)
214− , if isSmallCaps rPr then (Just SmallCaps) else Nothing
224+ then (Just SmallCaps)
225+ else Nothing
226+ , if resolveFmt False (isStrike rPr)
215− , if isStrike rPr then (Just Strikeout) else Nothing
227+ then (Just Strikeout)
228+ else Nothing
216 , if isSuperScript rPr then (Just Superscript) else Nothing
229 , if isSuperScript rPr then (Just Superscript) else Nothing
217 , if isSubScript rPr then (Just Subscript) else Nothing
230 , if isSubScript rPr then (Just Subscript) else Nothing
218 , rUnderline rPr >>=
231 , rUnderline rPr >>=
src/Text/Pandoc/Readers/Docx/Parse.hs+13−13
@@ -196,10 +196,10 @@ data Run = Run RunStyle [RunElem]
196data RunElem = TextRun String | LnBrk | Tab
196data RunElem = TextRun String | LnBrk | Tab
197 deriving Show
197 deriving Show
198
198
199−data RunStyle = RunStyle { isBold :: Bool
199+data RunStyle = RunStyle { isBold :: Maybe Bool
200− , isItalic :: Bool
200+ , isItalic :: Maybe Bool
201− , isSmallCaps :: Bool
201+ , isSmallCaps :: Maybe Bool
202− , isStrike :: Bool
202+ , isStrike :: Maybe Bool
203 , isSuperScript :: Bool
203 , isSuperScript :: Bool
204 , isSubScript :: Bool
204 , isSubScript :: Bool
205 , rUnderline :: Maybe String
205 , rUnderline :: Maybe String
@@ -207,10 +207,10 @@ data RunStyle = RunStyle { isBold :: Bool
207 deriving Show
207 deriving Show
208
208
209defaultRunStyle :: RunStyle
209defaultRunStyle :: RunStyle
210−defaultRunStyle = RunStyle { isBold = False
210+defaultRunStyle = RunStyle { isBold = Nothing
211− , isItalic = False
211+ , isItalic = Nothing
212− , isSmallCaps = False
212+ , isSmallCaps = Nothing
213− , isStrike = False
213+ , isStrike = Nothing
214 , isSuperScript = False
214 , isSuperScript = False
215 , isSubScript = False
215 , isSubScript = False
216 , rUnderline = Nothing
216 , rUnderline = Nothing
@@ -652,20 +652,20 @@ elemToParagraphStyle ns element
652 }
652 }
653elemToParagraphStyle _ _ = defaultParagraphStyle
653elemToParagraphStyle _ _ = defaultParagraphStyle
654
654
655−checkOnOff :: NameSpaces -> Element -> QName -> Bool
655+checkOnOff :: NameSpaces -> Element -> QName -> Maybe Bool
656checkOnOff ns rPr tag
656checkOnOff ns rPr tag
657 | Just t <- findChild tag rPr
657 | Just t <- findChild tag rPr
658 , Just val <- findAttr (elemName ns "w" "val") t =
658 , Just val <- findAttr (elemName ns "w" "val") t =
659− case val of
659+ Just $ case val of
660− "true" -> True
660+ "true" -> True
661 "false" -> False
661 "false" -> False
662 "on" -> True
662 "on" -> True
663 "off" -> False
663 "off" -> False
664 "1" -> True
664 "1" -> True
665 "0" -> False
665 "0" -> False
666 _ -> False
666 _ -> False
667− | Just _ <- findChild tag rPr = True
667+ | Just _ <- findChild tag rPr = Just True
668−checkOnOff _ _ _ = False
668+checkOnOff _ _ _ = Nothing
669
669
670
670
671elemToRunStyle :: NameSpaces -> Element -> RunStyle
671elemToRunStyle :: NameSpaces -> Element -> RunStyle