git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Make use of new ParIndentation info.

Here, when hanging indents are greater than or equal to left indents, we don't set it to block quote. Such indents are frequently used in academic bibliographies. (Thanks to Caleb McDaniel.)

commit0f59196e0ef2f0977d404699ae16a48009fa7632 authorJesse Rosenthal <jrosenthal@jhu.edu> dateSun 29 Jun 2014, 22:50 (12 years ago) parentc0fcc8a
1 file changed+25−10
src/Text/Pandoc/Readers/Docx.hs+25−10
src/Text/Pandoc/Readers/Docx.hs+25−10
@@ -94,6 +94,7 @@ import System.FilePath (combine)
9494import qualified Data.Map as M
9595import Control.Monad.Reader
9696import Control.Monad.State
97+import Control.Applicative (liftA2)
9798
9899readDocx :: ReaderOptions
99100 -> B.ByteString
@@ -148,7 +149,6 @@ runStyleToContainers rPr =
148149 in
149150 classContainers ++ formatters
150151
151−
152152divAttrToContainers :: [String] -> [(String, String)] -> [Container Block]
153153divAttrToContainers (c:cs) _ | Just n <- isHeaderClass c =
154154 [Container $ \_ ->
@@ -166,22 +166,37 @@ divAttrToContainers (c:cs) kvs | c `elem` listParagraphDivs =
166166divAttrToContainers (c:cs) kvs | c `elem` blockQuoteDivs =
167167 (Container BlockQuote) : (divAttrToContainers (cs \\ blockQuoteDivs) kvs)
168168divAttrToContainers (_:cs) kvs = divAttrToContainers cs kvs
169−divAttrToContainers [] kvs | Just numString <- lookup "indent" kvs =
170− let kvs' = filter (\(k,_) -> k /= "indent") kvs
169+divAttrToContainers [] kvs | Just _ <- lookup "indent" kvs
170+ , Just flInd <- lookup "first-line-indent" kvs =
171+ let
172+ kvs' = filter (\(k,_) -> notElem k ["indent", "first-line-indent"]) kvs
171173 in
172− case numString of
173− "0" -> divAttrToContainers [] kvs'
174− ('-' : _) -> divAttrToContainers [] kvs'
175− _ -> (Container BlockQuote) : divAttrToContainers [] kvs'
174+ case flInd of
175+ "0" -> divAttrToContainers [] kvs'
176+ ('-':_) -> divAttrToContainers [] kvs'
177+ _ -> (Container BlockQuote) : divAttrToContainers [] kvs'
178+divAttrToContainers [] kvs | Just ind <- lookup "indent" kvs =
179+ let
180+ kvs' = filter (\(k,_) -> notElem k ["indent"]) kvs
181+ in
182+ case ind of
183+ "0" -> divAttrToContainers [] kvs'
184+ ('-':_) -> divAttrToContainers [] kvs'
185+ _ -> (Container BlockQuote) : divAttrToContainers [] kvs'
186+
176187divAttrToContainers _ _ = []
177188
178189
179190parStyleToContainers :: ParagraphStyle -> [Container Block]
180191parStyleToContainers pPr =
181192 let classes = pStyle pPr
182− kvs = case indent pPr of
183− Just n -> [("indent", show n)]
184− Nothing -> []
193+ indent = indentation pPr >>= leftParIndent
194+ hanging = indentation pPr >>= hangingParIndent
195+ firstLineIndent = liftA2 (-) indent hanging
196+ kvs = mapMaybe id
197+ [ indent >>= (\n -> Just ("indent", show n)),
198+ firstLineIndent >>= (\n -> Just ("first-line-indent", show n))
199+ ]
185200 in
186201 divAttrToContainers classes kvs
187202