git.iko.soy/typeable/pandoc
on master help sign in
Naming: Use Docx instead of DocX.

For consistency with the existing writer.

commitbbe99003f8d25dc65ab12851907ecd5d9aad746c authorJohn MacFarlane <jgm@berkeley.edu> dateMon 16 Jun 2014, 22:44 (12 years ago) parent7c1d38a
7 files changed+56−56
pandoc.cabal+4−4 src/Text/Pandoc.hs+3−3 src/Text/Pandoc/Readers/DocX.hs → src/Text/Pandoc/Readers/Docx.hs+33−33 src/Text/Pandoc/Readers/DocX/Lists.hs → src/Text/Pandoc/Readers/Docx/Lists.hs+3−3 src/Text/Pandoc/Readers/DocX/Parse.hs → src/Text/Pandoc/Readers/Docx/Parse.hs+8−8 tests/Tests/Readers/DocX.hs → tests/Tests/Readers/Docx.hs+3−3 tests/test-pandoc.hs+2−2
pandoc.cabal+4−4
@@ -293,7 +293,7 @@ Library
293293 Text.Pandoc.Readers.Textile,
294294 Text.Pandoc.Readers.Native,
295295 Text.Pandoc.Readers.Haddock,
296− Text.Pandoc.Readers.DocX,
296+ Text.Pandoc.Readers.Docx,
297297 Text.Pandoc.Writers.Native,
298298 Text.Pandoc.Writers.Docbook,
299299 Text.Pandoc.Writers.OPML,
@@ -324,8 +324,8 @@ Library
324324 Text.Pandoc.Process
325325 Other-Modules: Text.Pandoc.Readers.Haddock.Lex,
326326 Text.Pandoc.Readers.Haddock.Parse,
327− Text.Pandoc.Readers.DocX.Lists,
328− Text.Pandoc.Readers.DocX.Parse,
327+ Text.Pandoc.Readers.Docx.Lists,
328+ Text.Pandoc.Readers.Docx.Parse,
329329 Text.Pandoc.Writers.Shared,
330330 Text.Pandoc.Asciify,
331331 Text.Pandoc.MIME,
@@ -411,7 +411,7 @@ Test-Suite test-pandoc
411411 Tests.Readers.Markdown
412412 Tests.Readers.Org
413413 Tests.Readers.RST
414− Tests.Readers.DocX
414+ Tests.Readers.Docx
415415 Tests.Writers.Native
416416 Tests.Writers.ConTeXt
417417 Tests.Writers.HTML
src/Text/Pandoc.hs+3−3
@@ -63,7 +63,7 @@ module Text.Pandoc
6363 , writers
6464 -- * Readers: converting /to/ Pandoc format
6565 , Reader (..)
66− , readDocX
66+ , readDocx
6767 , readMarkdown
6868 , readMediaWiki
6969 , readRST
@@ -127,7 +127,7 @@ import Text.Pandoc.Readers.HTML
127127import Text.Pandoc.Readers.Textile
128128import Text.Pandoc.Readers.Native
129129import Text.Pandoc.Readers.Haddock
130−import Text.Pandoc.Readers.DocX
130+import Text.Pandoc.Readers.Docx
131131import Text.Pandoc.Writers.Native
132132import Text.Pandoc.Writers.Markdown
133133import Text.Pandoc.Writers.RST
@@ -222,7 +222,7 @@ readers = [ ("native" , StringReader $ \_ s -> return $ readNative s)
222222 ,("html" , mkStringReader readHtml)
223223 ,("latex" , mkStringReader readLaTeX)
224224 ,("haddock" , mkStringReader readHaddock)
225− ,("docx" , mkBSReader readDocX)
225+ ,("docx" , mkBSReader readDocx)
226226 ]
227227
228228data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
src/Text/Pandoc/Readers/DocX.hs → src/Text/Pandoc/Readers/Docx.hsrenamed+33−33
@@ -17,7 +17,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1717-}
1818
1919{- |
20− Module : Text.Pandoc.Readers.DocX
20+ Module : Text.Pandoc.Readers.Docx
2121 Copyright : Copyright (C) 2014 Jesse Rosenthal
2222 License : GNU GPL, version 2 or above
2323
@@ -25,11 +25,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2525 Stability : alpha
2626 Portability : portable
2727
28−Conversion of DocX type (defined in Text.Pandoc.Readers.DocX.Parse)
28+Conversion of Docx type (defined in Text.Pandoc.Readers.Docx.Parse)
2929to 'Pandoc' document. -}
3030
3131{-
32−Current state of implementation of DocX entities ([x] means
32+Current state of implementation of Docx entities ([x] means
3333implemented, [-] means partially implemented):
3434
3535* Blocks
@@ -68,8 +68,8 @@ implemented, [-] means partially implemented):
6868 - [X] Note (Footnotes and Endnotes are silently combined.)
6969-}
7070
71−module Text.Pandoc.Readers.DocX
72− ( readDocX
71+module Text.Pandoc.Readers.Docx
72+ ( readDocx
7373 ) where
7474
7575import Codec.Archive.Zip
@@ -79,8 +79,8 @@ import Text.Pandoc.Builder (text, toList)
7979import Text.Pandoc.Generic (bottomUp)
8080import Text.Pandoc.MIME (getMimeType)
8181import Text.Pandoc.UTF8 (toString)
82−import Text.Pandoc.Readers.DocX.Parse
83−import Text.Pandoc.Readers.DocX.Lists
82+import Text.Pandoc.Readers.Docx.Parse
83+import Text.Pandoc.Readers.Docx.Lists
8484import Data.Maybe (mapMaybe, isJust, fromJust)
8585import Data.List (delete, isPrefixOf, (\\), intersect)
8686import qualified Data.ByteString as BS
@@ -88,11 +88,11 @@ import qualified Data.ByteString.Lazy as B
8888import Data.ByteString.Base64 (encode)
8989import System.FilePath (combine)
9090
91−readDocX :: ReaderOptions
91+readDocx :: ReaderOptions
9292 -> B.ByteString
9393 -> Pandoc
94−readDocX opts bytes =
95− case archiveToDocX (toArchive bytes) of
94+readDocx opts bytes =
95+ case archiveToDocx (toArchive bytes) of
9696 Just docx -> Pandoc nullMeta (docxToBlocks opts docx)
9797 Nothing -> error $ "couldn't parse docx file"
9898
@@ -148,8 +148,8 @@ strNormalize (Str "" : ils) = strNormalize ils
148148strNormalize ((Str s) : (Str s') : l) = strNormalize ((Str (s++s')) : l)
149149strNormalize (il:ils) = il : (strNormalize ils)
150150
151−runToInlines :: ReaderOptions -> DocX -> Run -> [Inline]
152−runToInlines _ _ (Run rs runElems)
151+runToInlines :: ReaderOptions -> Docx -> Run -> [Inline]
152+runToInlines _ _ (Run rs runElems)
153153 | isJust (rStyle rs) && (fromJust (rStyle rs)) `elem` codeSpans =
154154 case runStyleToSpanAttr rs == ("", [], []) of
155155 True -> [Str (runElemsToString runElems)]
@@ -157,30 +157,30 @@ runToInlines _ _ (Run rs runElems)
157157 | otherwise = case runStyleToSpanAttr rs == ("", [], []) of
158158 True -> concatMap runElemToInlines runElems
159159 False -> [Span (runStyleToSpanAttr rs) (concatMap runElemToInlines runElems)]
160−runToInlines opts docx@(DocX _ notes _ _ _ ) (Footnote fnId) =
160+runToInlines opts docx@(Docx _ notes _ _ _ ) (Footnote fnId) =
161161 case (getFootNote fnId notes) of
162162 Just bodyParts ->
163163 [Note [Div ("", ["footnote"], []) (map (bodyPartToBlock opts docx) bodyParts)]]
164164 Nothing ->
165165 [Note [Div ("", ["footnote"], []) []]]
166−runToInlines opts docx@(DocX _ notes _ _ _) (Endnote fnId) =
166+runToInlines opts docx@(Docx _ notes _ _ _) (Endnote fnId) =
167167 case (getEndNote fnId notes) of
168168 Just bodyParts ->
169169 [Note [Div ("", ["endnote"], []) (map (bodyPartToBlock opts docx) bodyParts)]]
170170 Nothing ->
171171 [Note [Div ("", ["endnote"], []) []]]
172172
173−parPartToInlines :: ReaderOptions -> DocX -> ParPart -> [Inline]
173+parPartToInlines :: ReaderOptions -> Docx -> ParPart -> [Inline]
174174parPartToInlines opts docx (PlainRun r) = runToInlines opts docx r
175175parPartToInlines _ _ (BookMark _ anchor) =
176176 [Span (anchor, ["anchor"], []) []]
177−parPartToInlines _ (DocX _ _ _ rels _) (Drawing relid) =
177+parPartToInlines _ (Docx _ _ _ rels _) (Drawing relid) =
178178 case lookupRelationship relid rels of
179179 Just target -> [Image [] (combine "word" target, "")]
180180 Nothing -> [Image [] ("", "")]
181181parPartToInlines opts docx (InternalHyperLink anchor runs) =
182182 [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) =
184184 case lookupRelationship relid rels of
185185 Just target ->
186186 [Link (concatMap (runToInlines opts docx) runs) (target, "")]
@@ -208,9 +208,9 @@ makeHeaderAnchors h@(Header n (_, classes, kvs) ils) =
208208 False -> Header n (ident, classes, kvs) (ils \\ (x:xs))
209209 _ -> h
210210makeHeaderAnchors blk = blk
211−
212211
213−parPartsToInlines :: ReaderOptions -> DocX -> [ParPart] -> [Inline]
212+
213+parPartsToInlines :: ReaderOptions -> Docx -> [ParPart] -> [Inline]
214214parPartsToInlines opts docx parparts =
215215 --
216216 -- We're going to skip data-uri's for now. It should be an option,
@@ -222,16 +222,16 @@ parPartsToInlines opts docx parparts =
222222 bottomUp spanReduce $
223223 concatMap (parPartToInlines opts docx) parparts
224224
225−cellToBlocks :: ReaderOptions -> DocX -> Cell -> [Block]
225+cellToBlocks :: ReaderOptions -> Docx -> Cell -> [Block]
226226cellToBlocks opts docx (Cell bps) = map (bodyPartToBlock opts docx) bps
227227
228−rowToBlocksList :: ReaderOptions -> DocX -> Row -> [[Block]]
228+rowToBlocksList :: ReaderOptions -> Docx -> Row -> [[Block]]
229229rowToBlocksList opts docx (Row cells) = map (cellToBlocks opts docx) cells
230230
231−bodyPartToBlock :: ReaderOptions -> DocX -> BodyPart -> Block
231+bodyPartToBlock :: ReaderOptions -> Docx -> BodyPart -> Block
232232bodyPartToBlock opts docx (Paragraph pPr parparts) =
233233 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) =
235235 let
236236 kvs = case lookupLevel numId lvl numbering of
237237 Just (_, fmt, txt, Just start) -> [ ("level", lvl)
@@ -240,7 +240,7 @@ bodyPartToBlock opts docx@(DocX _ _ numbering _ _) (ListItem pPr numId lvl parpa
240240 , ("text", txt)
241241 , ("start", (show start))
242242 ]
243−
243+
244244 Just (_, fmt, txt, Nothing) -> [ ("level", lvl)
245245 , ("num-id", numId)
246246 , ("format", fmt)
@@ -262,7 +262,7 @@ bodyPartToBlock opts docx (Tbl cap _ look (r:rs)) =
262262 Just r' -> rowToBlocksList opts docx r'
263263 Nothing -> []
264264 cells = map (rowToBlocksList opts docx) rows
265−
265+
266266 size = case null hdrCells of
267267 True -> length $ head cells
268268 False -> length $ hdrCells
@@ -277,8 +277,8 @@ bodyPartToBlock opts docx (Tbl cap _ look (r:rs)) =
277277 in
278278 Table caption alignments widths hdrCells cells
279279
280−makeImagesSelfContained :: DocX -> Inline -> Inline
281−makeImagesSelfContained (DocX _ _ _ _ media) i@(Image alt (uri, title)) =
280+makeImagesSelfContained :: Docx -> Inline -> Inline
281+makeImagesSelfContained (Docx _ _ _ _ media) i@(Image alt (uri, title)) =
282282 case lookup uri media of
283283 Just bs -> case getMimeType uri of
284284 Just mime -> let data_uri =
@@ -289,11 +289,11 @@ makeImagesSelfContained (DocX _ _ _ _ media) i@(Image alt (uri, title)) =
289289 Nothing -> i
290290makeImagesSelfContained _ inline = inline
291291
292−bodyToBlocks :: ReaderOptions -> DocX -> Body -> [Block]
292+bodyToBlocks :: ReaderOptions -> Docx -> Body -> [Block]
293293bodyToBlocks opts docx (Body bps) =
294294 bottomUp removeEmptyPars $
295− bottomUp strNormalize $
296− bottomUp spanRemove $
295+ bottomUp strNormalize $
296+ bottomUp spanRemove $
297297 bottomUp divRemove $
298298 map (makeHeaderAnchors) $
299299 bottomUp divCorrect $
@@ -303,8 +303,8 @@ bodyToBlocks opts docx (Body bps) =
303303 blocksToBullets $
304304 map (bodyPartToBlock opts docx) bps
305305
306−docxToBlocks :: ReaderOptions -> DocX -> [Block]
307−docxToBlocks opts d@(DocX (Document _ body) _ _ _ _) = bodyToBlocks opts d body
306+docxToBlocks :: ReaderOptions -> Docx -> [Block]
307+docxToBlocks opts d@(Docx (Document _ body) _ _ _ _) = bodyToBlocks opts d body
308308
309309spanReduce :: [Inline] -> [Inline]
310310spanReduce [] = []
@@ -460,7 +460,7 @@ divRemove' blk = [blk]
460460
461461divRemove :: [Block] -> [Block]
462462divRemove = concatMap divRemove'
463−
463+
464464divCorrect' :: Block -> [Block]
465465divCorrect' b@(Div (ident, classes, kvs) blks)
466466 | (not . null) (blockQuoteDivs `intersect` classes) =
src/Text/Pandoc/Readers/DocX/Lists.hs → src/Text/Pandoc/Readers/Docx/Lists.hsrenamed+3−3
@@ -17,7 +17,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1717-}
1818
1919{- |
20− Module : Text.Pandoc.Readers.DocX.Lists
20+ Module : Text.Pandoc.Readers.Docx.Lists
2121 Copyright : Copyright (C) 2014 Jesse Rosenthal
2222 License : GNU GPL, version 2 or above
2323
@@ -25,10 +25,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2525 Stability : alpha
2626 Portability : portable
2727
28−Functions for converting flat DocX paragraphs into nested lists.
28+Functions for converting flat docx paragraphs into nested lists.
2929-}
3030
31−module Text.Pandoc.Readers.DocX.Lists ( blocksToBullets
31+module Text.Pandoc.Readers.Docx.Lists ( blocksToBullets
3232 , blocksToDefinitions) where
3333
3434import Text.Pandoc.JSON
src/Text/Pandoc/Readers/DocX/Parse.hs → src/Text/Pandoc/Readers/Docx/Parse.hsrenamed+8−8
@@ -17,7 +17,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1717-}
1818
1919{- |
20− Module : Text.Pandoc.Readers.DocX.Parse
20+ Module : Text.Pandoc.Readers.Docx.Parse
2121 Copyright : Copyright (C) 2014 Jesse Rosenthal
2222 License : GNU GPL, version 2 or above
2323
@@ -25,11 +25,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2525 Stability : alpha
2626 Portability : portable
2727
28−Conversion of DocX archive into DocX haskell type
28+Conversion of docx archive into Docx haskell type
2929-}
3030
3131
32−module Text.Pandoc.Readers.DocX.Parse ( DocX(..)
32+module Text.Pandoc.Readers.Docx.Parse ( Docx(..)
3333 , Document(..)
3434 , Body(..)
3535 , BodyPart(..)
@@ -49,7 +49,7 @@ module Text.Pandoc.Readers.DocX.Parse ( DocX(..)
4949 , getEndNote
5050 , lookupLevel
5151 , lookupRelationship
52− , archiveToDocX
52+ , archiveToDocx
5353 ) where
5454import Codec.Archive.Zip
5555import Text.XML.Light
@@ -67,17 +67,17 @@ attrToNSPair _ = Nothing
6767
6868type NameSpaces = [(String, String)]
6969
70−data DocX = DocX Document Notes Numbering [Relationship] Media
70+data Docx = Docx Document Notes Numbering [Relationship] Media
7171 deriving Show
7272
73−archiveToDocX :: Archive -> Maybe DocX
74−archiveToDocX archive = do
73+archiveToDocx :: Archive -> Maybe Docx
74+archiveToDocx archive = do
7575 let notes = archiveToNotes archive
7676 rels = archiveToRelationships archive
7777 media = archiveToMedia archive
7878 doc <- archiveToDocument archive
7979 numbering <- archiveToNumbering archive
80− return $ DocX doc notes numbering rels media
80+ return $ Docx doc notes numbering rels media
8181
8282data Document = Document NameSpaces Body
8383 deriving Show
tests/Tests/Readers/DocX.hs → tests/Tests/Readers/Docx.hsrenamed+3−3
@@ -1,4 +1,4 @@
1−module Tests.Readers.DocX (tests) where
1+module Tests.Readers.Docx (tests) where
22
33import Text.Pandoc.Options
44import Text.Pandoc.Readers.Native
@@ -6,13 +6,13 @@ import Text.Pandoc.Definition
66import Tests.Helpers
77import Test.Framework
88import qualified Data.ByteString.Lazy as B
9−import Text.Pandoc.Readers.DocX
9+import Text.Pandoc.Readers.Docx
1010
1111compareOutput :: FilePath -> FilePath -> IO (Pandoc, Pandoc)
1212compareOutput docxFile nativeFile = do
1313 df <- B.readFile docxFile
1414 nf <- Prelude.readFile nativeFile
15− return $ (readDocX def df, readNative nf)
15+ return $ (readDocx def df, readNative nf)
1616
1717testCompare' :: String -> FilePath -> FilePath -> IO Test
1818testCompare' name docxFile nativeFile = do
tests/test-pandoc.hs+2−2
@@ -9,7 +9,7 @@ import qualified Tests.Readers.LaTeX
99import qualified Tests.Readers.Markdown
1010import qualified Tests.Readers.Org
1111import qualified Tests.Readers.RST
12−import qualified Tests.Readers.DocX
12+import qualified Tests.Readers.Docx
1313import qualified Tests.Writers.ConTeXt
1414import qualified Tests.Writers.LaTeX
1515import qualified Tests.Writers.HTML
@@ -39,7 +39,7 @@ tests = [ testGroup "Old" Tests.Old.tests
3939 , testGroup "Markdown" Tests.Readers.Markdown.tests
4040 , testGroup "Org" Tests.Readers.Org.tests
4141 , testGroup "RST" Tests.Readers.RST.tests
42− , testGroup "DocX" Tests.Readers.DocX.tests
42+ , testGroup "Docx" Tests.Readers.Docx.tests
4343
4444 ]
4545 ]