@@ -94,7 +94,6 @@ import System.FilePath (combine)
9494import qualified Data.Map as M
9595import Control.Monad.Reader
9696import Control.Monad.State
97−import Control.Applicative (liftA2)
9897
9998readDocx :: ReaderOptions
10099 -> B.ByteString
@@ -154,56 +153,48 @@ runStyleToContainers rPr =
154153 in
155154 classContainers ++ formatters
156155
157−divAttrToContainers :: [String] -> [(String, String)] -> [Container Block]
158−divAttrToContainers (c:cs) _ | Just n <- isHeaderClass c =
159− [Container $ \_ ->
160− Header n ("", delete ("Heading" ++ show n) cs, []) []]
161−divAttrToContainers (c:cs) kvs | c `elem` divsToKeep =
162− (Container $ Div ("", [c], [])) : (divAttrToContainers cs kvs)
163−divAttrToContainers (c:cs) kvs | c `elem` codeDivs =
156+parStyleToContainers :: ParagraphStyle -> [Container Block]
157+parStyleToContainers pPr | (c:cs) <- pStyle pPr, Just n <- isHeaderClass c =
158+ [Container $ \_ -> Header n ("", delete ("Heading" ++ show n) cs, []) []]
159+parStyleToContainers pPr | (c:cs) <- pStyle pPr, c `elem` divsToKeep =
160+ let pPr' = pPr { pStyle = cs }
161+ in
162+ (Container $ Div ("", [c], [])) : (parStyleToContainers pPr')
163+parStyleToContainers pPr | (c:cs) <- pStyle pPr, c `elem` codeDivs =
164164 -- This is a bit of a cludge. We make the codeblock from the raw
165165 -- parparts in bodyPartToBlocks. But we need something to match against.
166− (Container $ \_ -> CodeBlock ("", [], []) "") : (divAttrToContainers cs kvs)
167−divAttrToContainers (c:cs) kvs | c `elem` listParagraphDivs =
168− let kvs' = filter (\(k,_) -> k /= "indent") kvs
169− in
170− (Container $ Div ("", [c], [])) : (divAttrToContainers cs kvs')
171−divAttrToContainers (c:cs) kvs | c `elem` blockQuoteDivs =
172− (Container BlockQuote) : (divAttrToContainers (cs \\ blockQuoteDivs) kvs)
173−divAttrToContainers (_:cs) kvs = divAttrToContainers cs kvs
174−divAttrToContainers [] kvs | Just _ <- lookup "indent" kvs
175− , Just flInd <- lookup "first-line-indent" kvs =
176− let
177− kvs' = filter (\(k,_) -> notElem k ["indent", "first-line-indent"]) kvs
166+ let pPr' = pPr { pStyle = cs }
178167 in
179− case flInd of
180− "0" -> divAttrToContainers [] kvs'
181− ('-':_) -> divAttrToContainers [] kvs'
182− _ -> (Container BlockQuote) : divAttrToContainers [] kvs'
183−divAttrToContainers [] kvs | Just ind <- lookup "indent" kvs =
184− let
185− kvs' = filter (\(k,_) -> notElem k ["indent"]) kvs
168+ (Container $ \_ -> CodeBlock ("", [], []) "") : (parStyleToContainers pPr')
169+parStyleToContainers pPr | (c:cs) <- pStyle pPr, c `elem` listParagraphDivs =
170+ let pPr' = pPr { pStyle = cs, indentation = Nothing}
186171 in
187− case ind of
188− "0" -> divAttrToContainers [] kvs'
189− ('-':_) -> divAttrToContainers [] kvs'
190− _ -> (Container BlockQuote) : divAttrToContainers [] kvs'
191−
192−divAttrToContainers _ _ = []
172+ (Container $ Div ("", [c], [])) : (parStyleToContainers pPr')
193173
194−
195−parStyleToContainers :: ParagraphStyle -> [Container Block]
196−parStyleToContainers pPr =
197− let classes = pStyle pPr
198− indent = indentation pPr >>= leftParIndent
199− hanging = indentation pPr >>= hangingParIndent
200− firstLineIndent = liftA2 (-) indent hanging
201− kvs = mapMaybe id
202− [ indent >>= (\n -> Just ("indent", show n)),
203− firstLineIndent >>= (\n -> Just ("first-line-indent", show n))
204− ]
174+parStyleToContainers pPr | (c:cs) <- pStyle pPr, c `elem` blockQuoteDivs =
175+ let pPr' = pPr { pStyle = cs \\ blockQuoteDivs }
176+ in
177+ (Container BlockQuote) : (parStyleToContainers pPr')
178+parStyleToContainers pPr | (_:cs) <- pStyle pPr =
179+ let pPr' = pPr { pStyle = cs}
180+ in
181+ parStyleToContainers pPr'
182+parStyleToContainers pPr | null (pStyle pPr),
183+ Just left <- indentation pPr >>= leftParIndent,
184+ Just hang <- indentation pPr >>= hangingParIndent =
185+ let pPr' = pPr { indentation = Nothing }
186+ in
187+ case (left - hang) > 0 of
188+ True -> (Container BlockQuote) : (parStyleToContainers pPr')
189+ False -> parStyleToContainers pPr'
190+parStyleToContainers pPr | null (pStyle pPr),
191+ Just left <- indentation pPr >>= leftParIndent =
192+ let pPr' = pPr { indentation = Nothing }
205193 in
206− divAttrToContainers classes kvs
194+ case left > 0 of
195+ True -> (Container BlockQuote) : (parStyleToContainers pPr')
196+ False -> parStyleToContainers pPr'
197+parStyleToContainers _ = []
207198
208199
209200strToInlines :: String -> [Inline]