git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1388 from jkr/divattrToCont-cleanup
124cfb8John MacFarlane
src/Text/Pandoc/Readers/Docx.hs+36−45
@@ -94,7 +94,6 @@ import System.FilePath (combine)
94import qualified Data.Map as M
94import qualified Data.Map as M
95import Control.Monad.Reader
95import Control.Monad.Reader
96import Control.Monad.State
96import Control.Monad.State
97−import Control.Applicative (liftA2)
98
97
99readDocx :: ReaderOptions
98readDocx :: ReaderOptions
100 -> B.ByteString
99 -> B.ByteString
@@ -154,56 +153,48 @@ runStyleToContainers rPr =
154 in
153 in
155 classContainers ++ formatters
154 classContainers ++ formatters
156
155
157−divAttrToContainers :: [String] -> [(String, String)] -> [Container Block]
156+parStyleToContainers :: ParagraphStyle -> [Container Block]
158−divAttrToContainers (c:cs) _ | Just n <- isHeaderClass c =
157+parStyleToContainers pPr | (c:cs) <- pStyle pPr, Just n <- isHeaderClass c =
159− [Container $ \_ ->
160− Header n ("", delete ("Heading" ++ show n) cs, []) []]
158+ [Container $ \_ -> Header n ("", delete ("Heading" ++ show n) cs, []) []]
161−divAttrToContainers (c:cs) kvs | c `elem` divsToKeep =
159+parStyleToContainers pPr | (c:cs) <- pStyle pPr, c `elem` divsToKeep =
162− (Container $ Div ("", [c], [])) : (divAttrToContainers cs kvs)
160+ let pPr' = pPr { pStyle = cs }
163−divAttrToContainers (c:cs) kvs | c `elem` codeDivs =
161+ in
162+ (Container $ Div ("", [c], [])) : (parStyleToContainers pPr')
163+parStyleToContainers pPr | (c:cs) <- pStyle pPr, c `elem` codeDivs =
164 -- This is a bit of a cludge. We make the codeblock from the raw
164 -- This is a bit of a cludge. We make the codeblock from the raw
165 -- parparts in bodyPartToBlocks. But we need something to match against.
165 -- parparts in bodyPartToBlocks. But we need something to match against.
166− (Container $ \_ -> CodeBlock ("", [], []) "") : (divAttrToContainers cs kvs)
166+ let pPr' = pPr { pStyle = cs }
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
178 in
167 in
179− case flInd of
168+ (Container $ \_ -> CodeBlock ("", [], []) "") : (parStyleToContainers pPr')
180− "0" -> divAttrToContainers [] kvs'
169+parStyleToContainers pPr | (c:cs) <- pStyle pPr, c `elem` listParagraphDivs =
181− ('-':_) -> divAttrToContainers [] kvs'
170+ let pPr' = pPr { pStyle = cs, indentation = Nothing}
182− _ -> (Container BlockQuote) : divAttrToContainers [] kvs'
183−divAttrToContainers [] kvs | Just ind <- lookup "indent" kvs =
184− let
185− kvs' = filter (\(k,_) -> notElem k ["indent"]) kvs
186 in
171 in
187− case ind of
172+ (Container $ Div ("", [c], [])) : (parStyleToContainers pPr')
188− "0" -> divAttrToContainers [] kvs'
189− ('-':_) -> divAttrToContainers [] kvs'
190− _ -> (Container BlockQuote) : divAttrToContainers [] kvs'
191−
192−divAttrToContainers _ _ = []
193
173
194−
174+parStyleToContainers pPr | (c:cs) <- pStyle pPr, c `elem` blockQuoteDivs =
195−parStyleToContainers :: ParagraphStyle -> [Container Block]
175+ let pPr' = pPr { pStyle = cs \\ blockQuoteDivs }
176+ in
177+ (Container BlockQuote) : (parStyleToContainers pPr')
196−parStyleToContainers pPr =
178+parStyleToContainers pPr | (_:cs) <- pStyle pPr =
197− let classes = pStyle pPr
179+ let pPr' = pPr { pStyle = cs}
180+ in
181+ parStyleToContainers pPr'
182+parStyleToContainers pPr | null (pStyle pPr),
198− indent = indentation pPr >>= leftParIndent
183+ Just left <- indentation pPr >>= leftParIndent,
199− hanging = indentation pPr >>= hangingParIndent
184+ Just hang <- indentation pPr >>= hangingParIndent =
200− firstLineIndent = liftA2 (-) indent hanging
185+ let pPr' = pPr { indentation = Nothing }
201− kvs = mapMaybe id
186+ in
202− [ indent >>= (\n -> Just ("indent", show n)),
187+ case (left - hang) > 0 of
203− firstLineIndent >>= (\n -> Just ("first-line-indent", show n))
188+ True -> (Container BlockQuote) : (parStyleToContainers pPr')
204− ]
189+ False -> parStyleToContainers pPr'
190+parStyleToContainers pPr | null (pStyle pPr),
191+ Just left <- indentation pPr >>= leftParIndent =
192+ let pPr' = pPr { indentation = Nothing }
205 in
193 in
206− divAttrToContainers classes kvs
194+ case left > 0 of
195+ True -> (Container BlockQuote) : (parStyleToContainers pPr')
196+ False -> parStyleToContainers pPr'
197+parStyleToContainers _ = []
207
198
208
199
209strToInlines :: String -> [Inline]
200strToInlines :: String -> [Inline]