summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Docx.hs
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.hs
parent45d26fd01adc3aa14dd090f3faedf9d47718b54f (diff)
parent1405e7b7091dedb50578c9e0cafd62f2c77ca689 (diff)
Merge pull request #1386 from jkr/hanging_indent
Fix hanging indent behavior
Diffstat (limited to 'src/Text/Pandoc/Readers/Docx.hs')
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index 2e10ae3a4..6e9cf44b5 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -94,6 +94,7 @@ import System.FilePath (combine)
import qualified Data.Map as M
import Control.Monad.Reader
import Control.Monad.State
+import Control.Applicative (liftA2)
readDocx :: ReaderOptions
-> B.ByteString
@@ -153,7 +154,6 @@ runStyleToContainers rPr =
in
classContainers ++ formatters
-
divAttrToContainers :: [String] -> [(String, String)] -> [Container Block]
divAttrToContainers (c:cs) _ | Just n <- isHeaderClass c =
[Container $ \_ ->
@@ -171,22 +171,37 @@ divAttrToContainers (c:cs) kvs | c `elem` listParagraphDivs =
divAttrToContainers (c:cs) kvs | c `elem` blockQuoteDivs =
(Container BlockQuote) : (divAttrToContainers (cs \\ blockQuoteDivs) kvs)
divAttrToContainers (_:cs) kvs = divAttrToContainers cs kvs
-divAttrToContainers [] kvs | Just numString <- lookup "indent" kvs =
- let kvs' = filter (\(k,_) -> k /= "indent") kvs
+divAttrToContainers [] kvs | Just _ <- lookup "indent" kvs
+ , Just flInd <- lookup "first-line-indent" kvs =
+ let
+ kvs' = filter (\(k,_) -> notElem k ["indent", "first-line-indent"]) kvs
in
- case numString of
- "0" -> divAttrToContainers [] kvs'
- ('-' : _) -> divAttrToContainers [] kvs'
- _ -> (Container BlockQuote) : divAttrToContainers [] kvs'
+ case flInd of
+ "0" -> divAttrToContainers [] kvs'
+ ('-':_) -> divAttrToContainers [] kvs'
+ _ -> (Container BlockQuote) : divAttrToContainers [] kvs'
+divAttrToContainers [] kvs | Just ind <- lookup "indent" kvs =
+ let
+ kvs' = filter (\(k,_) -> notElem k ["indent"]) kvs
+ in
+ case ind of
+ "0" -> divAttrToContainers [] kvs'
+ ('-':_) -> divAttrToContainers [] kvs'
+ _ -> (Container BlockQuote) : divAttrToContainers [] kvs'
+
divAttrToContainers _ _ = []
parStyleToContainers :: ParagraphStyle -> [Container Block]
parStyleToContainers pPr =
let classes = pStyle pPr
- kvs = case indent pPr of
- Just n -> [("indent", show n)]
- Nothing -> []
+ indent = indentation pPr >>= leftParIndent
+ hanging = indentation pPr >>= hangingParIndent
+ firstLineIndent = liftA2 (-) indent hanging
+ kvs = mapMaybe id
+ [ indent >>= (\n -> Just ("indent", show n)),
+ firstLineIndent >>= (\n -> Just ("first-line-indent", show n))
+ ]
in
divAttrToContainers classes kvs