summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Docx
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-06-29 21:31:44 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-06-29 21:31:44 -0700
commitaad618d9dbd68d5ea625945d23674befddf3a072 (patch)
tree59041fd81a80921a0925feebb24877a7ff6c4add /src/Text/Pandoc/Readers/Docx
parent45d26fd01adc3aa14dd090f3faedf9d47718b54f (diff)
parent1405e7b7091dedb50578c9e0cafd62f2c77ca689 (diff)
Merge pull request #1386 from jkr/hanging_indent
Fix hanging indent behavior
Diffstat (limited to 'src/Text/Pandoc/Readers/Docx')
-rw-r--r--src/Text/Pandoc/Readers/Docx/Parse.hs31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs
index 07f34450d..537c5c272 100644
--- a/src/Text/Pandoc/Readers/Docx/Parse.hs
+++ b/src/Text/Pandoc/Readers/Docx/Parse.hs
@@ -42,6 +42,7 @@ module Text.Pandoc.Readers.Docx.Parse ( Docx(..)
, Relationship
, Media
, RunStyle(..)
+ , ParIndentation(..)
, ParagraphStyle(..)
, Row(..)
, Cell(..)
@@ -341,16 +342,37 @@ testBitMask bitMaskS n =
[] -> False
((n', _) : _) -> ((n' .|. n) /= 0)
+data ParIndentation = ParIndentation { leftParIndent :: Maybe Integer
+ , rightParIndent :: Maybe Integer
+ , hangingParIndent :: Maybe Integer}
+ deriving Show
+
data ParagraphStyle = ParagraphStyle { pStyle :: [String]
- , indent :: Maybe Integer
+ , indentation :: Maybe ParIndentation
}
deriving Show
defaultParagraphStyle :: ParagraphStyle
defaultParagraphStyle = ParagraphStyle { pStyle = []
- , indent = Nothing
+ , indentation = Nothing
}
+elemToParIndentation :: NameSpaces -> Element -> Maybe ParIndentation
+elemToParIndentation ns element
+ | qName (elName element) == "ind" &&
+ qURI (elName element) == (lookup "w" ns) =
+ Just $ ParIndentation {
+ leftParIndent =
+ findAttr (QName "left" (lookup "w" ns) (Just "w")) element >>=
+ stringToInteger
+ , rightParIndent =
+ findAttr (QName "right" (lookup "w" ns) (Just "w")) element >>=
+ stringToInteger
+ , hangingParIndent =
+ findAttr (QName "hanging" (lookup "w" ns) (Just "w")) element >>=
+ stringToInteger}
+elemToParIndentation _ _ = Nothing
+
elemToParagraphStyle :: NameSpaces -> Element -> ParagraphStyle
elemToParagraphStyle ns element =
case findChild (QName "pPr" (lookup "w" ns) (Just "w")) element of
@@ -360,10 +382,9 @@ elemToParagraphStyle ns element =
mapMaybe
(findAttr (QName "val" (lookup "w" ns) (Just "w")))
(findChildren (QName "pStyle" (lookup "w" ns) (Just "w")) pPr)
- , indent =
+ , indentation =
findChild (QName "ind" (lookup "w" ns) (Just "w")) pPr >>=
- findAttr (QName "left" (lookup "w" ns) (Just "w")) >>=
- stringToInteger
+ elemToParIndentation ns
}
Nothing -> defaultParagraphStyle