Docx reader: Change behavior of Super/Subscript

In docx, super- and subscript are attributes of Vertalign. It makes more
sense to follow this, and have different possible values of Vertalign in
runStyle. This is mainly a preparatory step for real style parsing,
since it can distinguish between vertical align being explicitly turned
off and it not being set.

In addition, it makes parsing a bit clearer, and makes sure we don't do
docx-impossible things like being simultaneously super and sub.
This commit is contained in:
Jesse Rosenthal 2014-08-17 08:20:00 -04:00
parent 9d52ecdd42
commit dc5b0ba09b
2 changed files with 17 additions and 16 deletions

View file

@ -257,10 +257,10 @@ runStyleToTransform rPr
smallcaps . (runStyleToTransform rPr {isSmallCaps = Nothing}) smallcaps . (runStyleToTransform rPr {isSmallCaps = Nothing})
| Just True <- isStrike rPr = | Just True <- isStrike rPr =
strikeout . (runStyleToTransform rPr {isStrike = Nothing}) strikeout . (runStyleToTransform rPr {isStrike = Nothing})
| isSuperScript rPr = | Just SupScrpt <- rVertAlign rPr =
superscript . (runStyleToTransform rPr {isSuperScript = False}) superscript . (runStyleToTransform rPr {rVertAlign = Nothing})
| isSubScript rPr = | Just SubScrpt <- rVertAlign rPr =
subscript . (runStyleToTransform rPr {isSubScript = False}) subscript . (runStyleToTransform rPr {rVertAlign = Nothing})
| Just "single" <- rUnderline rPr = | Just "single" <- rUnderline rPr =
emph . (runStyleToTransform rPr {rUnderline = Nothing}) emph . (runStyleToTransform rPr {rUnderline = Nothing})
| otherwise = id | otherwise = id

View file

@ -43,6 +43,7 @@ module Text.Pandoc.Readers.Docx.Parse ( Docx(..)
, Relationship , Relationship
, Media , Media
, RunStyle(..) , RunStyle(..)
, VertAlign(..)
, ParIndentation(..) , ParIndentation(..)
, ParagraphStyle(..) , ParagraphStyle(..)
, Row(..) , Row(..)
@ -196,12 +197,14 @@ data Run = Run RunStyle [RunElem]
data RunElem = TextRun String | LnBrk | Tab data RunElem = TextRun String | LnBrk | Tab
deriving Show deriving Show
data VertAlign = BaseLn | SupScrpt | SubScrpt
deriving Show
data RunStyle = RunStyle { isBold :: Maybe Bool data RunStyle = RunStyle { isBold :: Maybe Bool
, isItalic :: Maybe Bool , isItalic :: Maybe Bool
, isSmallCaps :: Maybe Bool , isSmallCaps :: Maybe Bool
, isStrike :: Maybe Bool , isStrike :: Maybe Bool
, isSuperScript :: Bool , rVertAlign :: Maybe VertAlign
, isSubScript :: Bool
, rUnderline :: Maybe String , rUnderline :: Maybe String
, rStyle :: Maybe String } , rStyle :: Maybe String }
deriving Show deriving Show
@ -211,8 +214,7 @@ defaultRunStyle = RunStyle { isBold = Nothing
, isItalic = Nothing , isItalic = Nothing
, isSmallCaps = Nothing , isSmallCaps = Nothing
, isStrike = Nothing , isStrike = Nothing
, isSuperScript = False , rVertAlign = Nothing
, isSubScript = False
, rUnderline = Nothing , rUnderline = Nothing
, rStyle = Nothing , rStyle = Nothing
} }
@ -677,14 +679,13 @@ elemToRunStyle ns element
, isItalic = checkOnOff ns rPr (elemName ns "w" "i") , isItalic = checkOnOff ns rPr (elemName ns "w" "i")
, isSmallCaps = checkOnOff ns rPr (elemName ns "w" "smallCaps") , isSmallCaps = checkOnOff ns rPr (elemName ns "w" "smallCaps")
, isStrike = checkOnOff ns rPr (elemName ns "w" "strike") , isStrike = checkOnOff ns rPr (elemName ns "w" "strike")
, isSuperScript = , rVertAlign =
(Just "superscript" == findChild (elemName ns "w" "vertAlign") rPr >>=
(findChild (elemName ns "w" "vertAlign") rPr >>= findAttr (elemName ns "w" "val") >>=
findAttr (elemName ns "w" "val"))) \v -> Just $ case v of
, isSubScript = "superscript" -> SupScrpt
(Just "subscript" == "subscript" -> SubScrpt
(findChild (elemName ns "w" "vertAlign") rPr >>= _ -> BaseLn
findAttr (elemName ns "w" "val")))
, rUnderline = , rUnderline =
findChild (elemName ns "w" "u") rPr >>= findChild (elemName ns "w" "u") rPr >>=
findAttr (elemName ns "w" "val") findAttr (elemName ns "w" "val")