@@ -17,7 +17,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20− Module : Text.Pandoc.Readers.DocX
20+ Module : Text.Pandoc.Readers.Docx
21 Copyright : Copyright (C) 2014 Jesse Rosenthal
21 Copyright : Copyright (C) 2014 Jesse Rosenthal
22 License : GNU GPL, version 2 or above
22 License : GNU GPL, version 2 or above
@@ -25,11 +25,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 Stability : alpha
25 Stability : alpha
26 Portability : portable
26 Portability : portable
28−Conversion of DocX type (defined in Text.Pandoc.Readers.DocX.Parse)
28+Conversion of Docx type (defined in Text.Pandoc.Readers.Docx.Parse)
29to 'Pandoc' document. -}
29to 'Pandoc' document. -}
32−Current state of implementation of DocX entities ([x] means
32+Current state of implementation of Docx entities ([x] means
33implemented, [-] means partially implemented):
33implemented, [-] means partially implemented):
@@ -68,8 +68,8 @@ implemented, [-] means partially implemented):
68 - [X] Note (Footnotes and Endnotes are silently combined.)
68 - [X] Note (Footnotes and Endnotes are silently combined.)
71−module Text.Pandoc.Readers.DocX
71+module Text.Pandoc.Readers.Docx
72− ( readDocX
72+ ( readDocx
75import Codec.Archive.Zip
75import Codec.Archive.Zip
@@ -79,8 +79,8 @@ import Text.Pandoc.Builder (text, toList)
79import Text.Pandoc.Generic (bottomUp)
79import Text.Pandoc.Generic (bottomUp)
80import Text.Pandoc.MIME (getMimeType)
80import Text.Pandoc.MIME (getMimeType)
81import Text.Pandoc.UTF8 (toString)
81import Text.Pandoc.UTF8 (toString)
82−import Text.Pandoc.Readers.DocX.Parse
82+import Text.Pandoc.Readers.Docx.Parse
83−import Text.Pandoc.Readers.DocX.Lists
83+import Text.Pandoc.Readers.Docx.Lists
84import Data.Maybe (mapMaybe, isJust, fromJust)
84import Data.Maybe (mapMaybe, isJust, fromJust)
85import Data.List (delete, isPrefixOf, (\\), intersect)
85import Data.List (delete, isPrefixOf, (\\), intersect)
86import qualified Data.ByteString as BS
86import qualified Data.ByteString as BS
@@ -88,11 +88,11 @@ import qualified Data.ByteString.Lazy as B
88import Data.ByteString.Base64 (encode)
88import Data.ByteString.Base64 (encode)
89import System.FilePath (combine)
89import System.FilePath (combine)
91−readDocX :: ReaderOptions
91+readDocx :: ReaderOptions
92 -> B.ByteString
92 -> B.ByteString
94−readDocX opts bytes =
94+readDocx opts bytes =
95− case archiveToDocX (toArchive bytes) of
95+ case archiveToDocx (toArchive bytes) of
96 Just docx -> Pandoc nullMeta (docxToBlocks opts docx)
96 Just docx -> Pandoc nullMeta (docxToBlocks opts docx)
97 Nothing -> error $ "couldn't parse docx file"
97 Nothing -> error $ "couldn't parse docx file"
@@ -148,8 +148,8 @@ strNormalize (Str "" : ils) = strNormalize ils
148strNormalize ((Str s) : (Str s') : l) = strNormalize ((Str (s++s')) : l)
148strNormalize ((Str s) : (Str s') : l) = strNormalize ((Str (s++s')) : l)
149strNormalize (il:ils) = il : (strNormalize ils)
149strNormalize (il:ils) = il : (strNormalize ils)
151−runToInlines :: ReaderOptions -> DocX -> Run -> [Inline]
151+runToInlines :: ReaderOptions -> Docx -> Run -> [Inline]
152−runToInlines _ _ (Run rs runElems)
152+runToInlines _ _ (Run rs runElems)
153 | isJust (rStyle rs) && (fromJust (rStyle rs)) `elem` codeSpans =
153 | isJust (rStyle rs) && (fromJust (rStyle rs)) `elem` codeSpans =
154 case runStyleToSpanAttr rs == ("", [], []) of
154 case runStyleToSpanAttr rs == ("", [], []) of
155 True -> [Str (runElemsToString runElems)]
155 True -> [Str (runElemsToString runElems)]
@@ -157,30 +157,30 @@ runToInlines _ _ (Run rs runElems)
157 | otherwise = case runStyleToSpanAttr rs == ("", [], []) of
157 | otherwise = case runStyleToSpanAttr rs == ("", [], []) of
158 True -> concatMap runElemToInlines runElems
158 True -> concatMap runElemToInlines runElems
159 False -> [Span (runStyleToSpanAttr rs) (concatMap runElemToInlines runElems)]
159 False -> [Span (runStyleToSpanAttr rs) (concatMap runElemToInlines runElems)]
160−runToInlines opts docx@(DocX _ notes _ _ _ ) (Footnote fnId) =
160+runToInlines opts docx@(Docx _ notes _ _ _ ) (Footnote fnId) =
161 case (getFootNote fnId notes) of
161 case (getFootNote fnId notes) of
162 Just bodyParts ->
162 Just bodyParts ->
163 [Note [Div ("", ["footnote"], []) (map (bodyPartToBlock opts docx) bodyParts)]]
163 [Note [Div ("", ["footnote"], []) (map (bodyPartToBlock opts docx) bodyParts)]]
164 Nothing ->
164 Nothing ->
165 [Note [Div ("", ["footnote"], []) []]]
165 [Note [Div ("", ["footnote"], []) []]]
166−runToInlines opts docx@(DocX _ notes _ _ _) (Endnote fnId) =
166+runToInlines opts docx@(Docx _ notes _ _ _) (Endnote fnId) =
167 case (getEndNote fnId notes) of
167 case (getEndNote fnId notes) of
168 Just bodyParts ->
168 Just bodyParts ->
169 [Note [Div ("", ["endnote"], []) (map (bodyPartToBlock opts docx) bodyParts)]]
169 [Note [Div ("", ["endnote"], []) (map (bodyPartToBlock opts docx) bodyParts)]]
170 Nothing ->
170 Nothing ->
171 [Note [Div ("", ["endnote"], []) []]]
171 [Note [Div ("", ["endnote"], []) []]]
173−parPartToInlines :: ReaderOptions -> DocX -> ParPart -> [Inline]
173+parPartToInlines :: ReaderOptions -> Docx -> ParPart -> [Inline]
174parPartToInlines opts docx (PlainRun r) = runToInlines opts docx r
174parPartToInlines opts docx (PlainRun r) = runToInlines opts docx r
175parPartToInlines _ _ (BookMark _ anchor) =
175parPartToInlines _ _ (BookMark _ anchor) =
176 [Span (anchor, ["anchor"], []) []]
176 [Span (anchor, ["anchor"], []) []]
177−parPartToInlines _ (DocX _ _ _ rels _) (Drawing relid) =
177+parPartToInlines _ (Docx _ _ _ rels _) (Drawing relid) =
178 case lookupRelationship relid rels of
178 case lookupRelationship relid rels of
179 Just target -> [Image [] (combine "word" target, "")]
179 Just target -> [Image [] (combine "word" target, "")]
180 Nothing -> [Image [] ("", "")]
180 Nothing -> [Image [] ("", "")]
181parPartToInlines opts docx (InternalHyperLink anchor runs) =
181parPartToInlines opts docx (InternalHyperLink anchor runs) =
182 [Link (concatMap (runToInlines opts docx) runs) ('#' : anchor, "")]
182 [Link (concatMap (runToInlines opts docx) runs) ('#' : anchor, "")]
183−parPartToInlines opts docx@(DocX _ _ _ rels _) (ExternalHyperLink relid runs) =
183+parPartToInlines opts docx@(Docx _ _ _ rels _) (ExternalHyperLink relid runs) =
184 case lookupRelationship relid rels of
184 case lookupRelationship relid rels of
185 Just target ->
185 Just target ->
186 [Link (concatMap (runToInlines opts docx) runs) (target, "")]
186 [Link (concatMap (runToInlines opts docx) runs) (target, "")]
@@ -208,9 +208,9 @@ makeHeaderAnchors h@(Header n (_, classes, kvs) ils) =
208 False -> Header n (ident, classes, kvs) (ils \\ (x:xs))
208 False -> Header n (ident, classes, kvs) (ils \\ (x:xs))
210makeHeaderAnchors blk = blk
210makeHeaderAnchors blk = blk
213−parPartsToInlines :: ReaderOptions -> DocX -> [ParPart] -> [Inline]
213+parPartsToInlines :: ReaderOptions -> Docx -> [ParPart] -> [Inline]
214parPartsToInlines opts docx parparts =
214parPartsToInlines opts docx parparts =
216 -- We're going to skip data-uri's for now. It should be an option,
216 -- We're going to skip data-uri's for now. It should be an option,
@@ -222,16 +222,16 @@ parPartsToInlines opts docx parparts =
222 bottomUp spanReduce $
222 bottomUp spanReduce $
223 concatMap (parPartToInlines opts docx) parparts
223 concatMap (parPartToInlines opts docx) parparts
225−cellToBlocks :: ReaderOptions -> DocX -> Cell -> [Block]
225+cellToBlocks :: ReaderOptions -> Docx -> Cell -> [Block]
226cellToBlocks opts docx (Cell bps) = map (bodyPartToBlock opts docx) bps
226cellToBlocks opts docx (Cell bps) = map (bodyPartToBlock opts docx) bps
228−rowToBlocksList :: ReaderOptions -> DocX -> Row -> [[Block]]
228+rowToBlocksList :: ReaderOptions -> Docx -> Row -> [[Block]]
229rowToBlocksList opts docx (Row cells) = map (cellToBlocks opts docx) cells
229rowToBlocksList opts docx (Row cells) = map (cellToBlocks opts docx) cells
231−bodyPartToBlock :: ReaderOptions -> DocX -> BodyPart -> Block
231+bodyPartToBlock :: ReaderOptions -> Docx -> BodyPart -> Block
232bodyPartToBlock opts docx (Paragraph pPr parparts) =
232bodyPartToBlock opts docx (Paragraph pPr parparts) =
233 Div (parStyleToDivAttr pPr) [Para (parPartsToInlines opts docx parparts)]
233 Div (parStyleToDivAttr pPr) [Para (parPartsToInlines opts docx parparts)]
234−bodyPartToBlock opts docx@(DocX _ _ numbering _ _) (ListItem pPr numId lvl parparts) =
234+bodyPartToBlock opts docx@(Docx _ _ numbering _ _) (ListItem pPr numId lvl parparts) =
236 kvs = case lookupLevel numId lvl numbering of
236 kvs = case lookupLevel numId lvl numbering of
237 Just (_, fmt, txt, Just start) -> [ ("level", lvl)
237 Just (_, fmt, txt, Just start) -> [ ("level", lvl)
@@ -240,7 +240,7 @@ bodyPartToBlock opts docx@(DocX _ _ numbering _ _) (ListItem pPr numId lvl parpa
240 , ("text", txt)
240 , ("text", txt)
241 , ("start", (show start))
241 , ("start", (show start))
244 Just (_, fmt, txt, Nothing) -> [ ("level", lvl)
244 Just (_, fmt, txt, Nothing) -> [ ("level", lvl)
245 , ("num-id", numId)
245 , ("num-id", numId)
246 , ("format", fmt)
246 , ("format", fmt)
@@ -262,7 +262,7 @@ bodyPartToBlock opts docx (Tbl cap _ look (r:rs)) =
262 Just r' -> rowToBlocksList opts docx r'
262 Just r' -> rowToBlocksList opts docx r'
263 Nothing -> []
263 Nothing -> []
264 cells = map (rowToBlocksList opts docx) rows
264 cells = map (rowToBlocksList opts docx) rows
266 size = case null hdrCells of
266 size = case null hdrCells of
267 True -> length $ head cells
267 True -> length $ head cells
268 False -> length $ hdrCells
268 False -> length $ hdrCells
@@ -277,8 +277,8 @@ bodyPartToBlock opts docx (Tbl cap _ look (r:rs)) =
278 Table caption alignments widths hdrCells cells
278 Table caption alignments widths hdrCells cells
280−makeImagesSelfContained :: DocX -> Inline -> Inline
280+makeImagesSelfContained :: Docx -> Inline -> Inline
281−makeImagesSelfContained (DocX _ _ _ _ media) i@(Image alt (uri, title)) =
281+makeImagesSelfContained (Docx _ _ _ _ media) i@(Image alt (uri, title)) =
282 case lookup uri media of
282 case lookup uri media of
283 Just bs -> case getMimeType uri of
283 Just bs -> case getMimeType uri of
284 Just mime -> let data_uri =
284 Just mime -> let data_uri =
@@ -289,11 +289,11 @@ makeImagesSelfContained (DocX _ _ _ _ media) i@(Image alt (uri, title)) =
289 Nothing -> i
289 Nothing -> i
290makeImagesSelfContained _ inline = inline
290makeImagesSelfContained _ inline = inline
292−bodyToBlocks :: ReaderOptions -> DocX -> Body -> [Block]
292+bodyToBlocks :: ReaderOptions -> Docx -> Body -> [Block]
293bodyToBlocks opts docx (Body bps) =
293bodyToBlocks opts docx (Body bps) =
294 bottomUp removeEmptyPars $
294 bottomUp removeEmptyPars $
295− bottomUp strNormalize $
295+ bottomUp strNormalize $
296− bottomUp spanRemove $
296+ bottomUp spanRemove $
297 bottomUp divRemove $
297 bottomUp divRemove $
298 map (makeHeaderAnchors) $
298 map (makeHeaderAnchors) $
299 bottomUp divCorrect $
299 bottomUp divCorrect $
@@ -303,8 +303,8 @@ bodyToBlocks opts docx (Body bps) =
303 blocksToBullets $
303 blocksToBullets $
304 map (bodyPartToBlock opts docx) bps
304 map (bodyPartToBlock opts docx) bps
306−docxToBlocks :: ReaderOptions -> DocX -> [Block]
306+docxToBlocks :: ReaderOptions -> Docx -> [Block]
307−docxToBlocks opts d@(DocX (Document _ body) _ _ _ _) = bodyToBlocks opts d body
307+docxToBlocks opts d@(Docx (Document _ body) _ _ _ _) = bodyToBlocks opts d body
309spanReduce :: [Inline] -> [Inline]
309spanReduce :: [Inline] -> [Inline]
310spanReduce [] = []
310spanReduce [] = []
@@ -460,7 +460,7 @@ divRemove' blk = [blk]
461divRemove :: [Block] -> [Block]
461divRemove :: [Block] -> [Block]
462divRemove = concatMap divRemove'
462divRemove = concatMap divRemove'
464divCorrect' :: Block -> [Block]
464divCorrect' :: Block -> [Block]
465divCorrect' b@(Div (ident, classes, kvs) blks)
465divCorrect' b@(Div (ident, classes, kvs) blks)
466 | (not . null) (blockQuoteDivs `intersect` classes) =
466 | (not . null) (blockQuoteDivs `intersect` classes) =