git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Add ParIndentation type to parser.

This lets us keep more information about the indentation, and act accordingly in the reader.

commitc0fcc8a7891892357854cf498ce262b256fac1ca authorJesse Rosenthal <jrosenthal@jhu.edu> dateSun 29 Jun 2014, 18:44 (12 years ago) parentce69021
1 file changed+26−5
src/Text/Pandoc/Readers/Docx/Parse.hs+26−5
src/Text/Pandoc/Readers/Docx/Parse.hs+26−5
@@ -42,6 +42,7 @@ module Text.Pandoc.Readers.Docx.Parse ( Docx(..)
4242 , Relationship
4343 , Media
4444 , RunStyle(..)
45+ , ParIndentation(..)
4546 , ParagraphStyle(..)
4647 , Row(..)
4748 , Cell(..)
@@ -341,16 +342,37 @@ testBitMask bitMaskS n =
341342 [] -> False
342343 ((n', _) : _) -> ((n' .|. n) /= 0)
343344
345+data ParIndentation = ParIndentation { leftParIndent :: Maybe Integer
346+ , rightParIndent :: Maybe Integer
347+ , hangingParIndent :: Maybe Integer}
348+ deriving Show
349+
344350data ParagraphStyle = ParagraphStyle { pStyle :: [String]
345− , indent :: Maybe Integer
351+ , indentation :: Maybe ParIndentation
346352 }
347353 deriving Show
348354
349355defaultParagraphStyle :: ParagraphStyle
350356defaultParagraphStyle = ParagraphStyle { pStyle = []
351− , indent = Nothing
357+ , indentation = Nothing
352358 }
353359
360+elemToParIndentation :: NameSpaces -> Element -> Maybe ParIndentation
361+elemToParIndentation ns element
362+ | qName (elName element) == "ind" &&
363+ qURI (elName element) == (lookup "w" ns) =
364+ Just $ ParIndentation {
365+ leftParIndent =
366+ findAttr (QName "left" (lookup "w" ns) (Just "w")) element >>=
367+ stringToInteger
368+ , rightParIndent =
369+ findAttr (QName "right" (lookup "w" ns) (Just "w")) element >>=
370+ stringToInteger
371+ , hangingParIndent =
372+ findAttr (QName "hanging" (lookup "w" ns) (Just "w")) element >>=
373+ stringToInteger}
374+elemToParIndentation _ _ = Nothing
375+
354376elemToParagraphStyle :: NameSpaces -> Element -> ParagraphStyle
355377elemToParagraphStyle ns element =
356378 case findChild (QName "pPr" (lookup "w" ns) (Just "w")) element of
@@ -360,10 +382,9 @@ elemToParagraphStyle ns element =
360382 mapMaybe
361383 (findAttr (QName "val" (lookup "w" ns) (Just "w")))
362384 (findChildren (QName "pStyle" (lookup "w" ns) (Just "w")) pPr)
363− , indent =
385+ , indentation =
364386 findChild (QName "ind" (lookup "w" ns) (Just "w")) pPr >>=
365− findAttr (QName "left" (lookup "w" ns) (Just "w")) >>=
366− stringToInteger
387+ elemToParIndentation ns
367388 }
368389 Nothing -> defaultParagraphStyle
369390