git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: don't strip out empty paragraphs.
d6c58ebJohn MacFarlane
src/Text/Pandoc/Readers/Docx.hs+1−3
@@ -534,9 +534,7 @@ bodyPartToBlocks (Paragraph pPr parparts)
534 then do modify $ \s -> s { docxDropCap = ils' }
534 then do modify $ \s -> s { docxDropCap = ils' }
535 return mempty
535 return mempty
536 else do modify $ \s -> s { docxDropCap = mempty }
536 else do modify $ \s -> s { docxDropCap = mempty }
537− return $ case isNull ils' of
538− True -> mempty
539− _ -> parStyleToTransform pPr $ para ils'
537+ return $ parStyleToTransform pPr $ para ils'
540bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
538bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
541 let
539 let
542 kvs = case levelInfo of
540 kvs = case levelInfo of
test/Tests/Readers/Docx.hs+20−7
@@ -10,6 +10,7 @@ import Test.Tasty
10import Test.Tasty.HUnit
10import Test.Tasty.HUnit
11import Tests.Helpers
11import Tests.Helpers
12import Text.Pandoc
12import Text.Pandoc
13+import Text.Pandoc.Shared (stripEmptyParagraphs)
13import qualified Text.Pandoc.Class as P
14import qualified Text.Pandoc.Class as P
14import Text.Pandoc.MediaBag (MediaBag, lookupMedia, mediaDirectory)
15import Text.Pandoc.MediaBag (MediaBag, lookupMedia, mediaDirectory)
15import Text.Pandoc.UTF8 as UTF8
16import Text.Pandoc.UTF8 as UTF8
@@ -37,20 +38,23 @@ instance ToString NoNormPandoc where
37instance ToPandoc NoNormPandoc where
38instance ToPandoc NoNormPandoc where
38 toPandoc = unNoNorm
39 toPandoc = unNoNorm
39
40
41+compareOutput :: Bool
40−compareOutput :: ReaderOptions
42+ -> ReaderOptions
41− -> FilePath
43+ -> FilePath
42− -> FilePath
44+ -> FilePath
43− -> IO (NoNormPandoc, NoNormPandoc)
45+ -> IO (NoNormPandoc, NoNormPandoc)
44−compareOutput opts docxFile nativeFile = do
46+compareOutput strip opts docxFile nativeFile = do
45 df <- B.readFile docxFile
47 df <- B.readFile docxFile
46 nf <- UTF8.toText <$> BS.readFile nativeFile
48 nf <- UTF8.toText <$> BS.readFile nativeFile
47 p <- runIOorExplode $ readDocx opts df
49 p <- runIOorExplode $ readDocx opts df
48 df' <- runIOorExplode $ readNative def nf
50 df' <- runIOorExplode $ readNative def nf
49− return $ (noNorm p, noNorm df')
51+ return $ (noNorm (if strip
52+ then stripEmptyParagraphs p
53+ else p), noNorm df')
50
54
51testCompareWithOptsIO :: ReaderOptions -> String -> FilePath -> FilePath -> IO TestTree
55testCompareWithOptsIO :: ReaderOptions -> String -> FilePath -> FilePath -> IO TestTree
52testCompareWithOptsIO opts name docxFile nativeFile = do
56testCompareWithOptsIO opts name docxFile nativeFile = do
53− (dp, np) <- compareOutput opts docxFile nativeFile
57+ (dp, np) <- compareOutput True opts docxFile nativeFile
54 return $ test id name (dp, np)
58 return $ test id name (dp, np)
55
59
56testCompareWithOpts :: ReaderOptions -> String -> FilePath -> FilePath -> TestTree
60testCompareWithOpts :: ReaderOptions -> String -> FilePath -> FilePath -> TestTree
@@ -71,6 +75,11 @@ testForWarningsWithOpts :: ReaderOptions -> String -> FilePath -> [String] -> Te
71testForWarningsWithOpts opts name docxFile expected =
75testForWarningsWithOpts opts name docxFile expected =
72 unsafePerformIO $ testForWarningsWithOptsIO opts name docxFile expected
76 unsafePerformIO $ testForWarningsWithOptsIO opts name docxFile expected
73
77
78+testCompareNoStrip :: String -> FilePath -> FilePath -> TestTree
79+testCompareNoStrip name docxFile nativeFile = unsafePerformIO $ do
80+ (dp, np) <- compareOutput False defopts docxFile nativeFile
81+ return $ test id name (dp, np)
82+
74-- testForWarnings :: String -> FilePath -> [String] -> TestTree
83-- testForWarnings :: String -> FilePath -> [String] -> TestTree
75-- testForWarnings = testForWarningsWithOpts defopts
84-- testForWarnings = testForWarningsWithOpts defopts
76
85
@@ -257,6 +266,10 @@ tests = [ testGroup "inlines"
257 "dropcap paragraphs"
266 "dropcap paragraphs"
258 "docx/drop_cap.docx"
267 "docx/drop_cap.docx"
259 "docx/drop_cap.native"
268 "docx/drop_cap.native"
269+ , testCompareNoStrip
270+ "empty paragraphs without stripping"
271+ "docx/drop_cap.docx"
272+ "docx/drop_cap_nostrip.native"
260 ]
273 ]
261 , testGroup "track changes"
274 , testGroup "track changes"
262 [ testCompare
275 [ testCompare
test/docx/0_level_headers.native+8−8
@@ -1,15 +1,15 @@
1[Table [] [AlignDefault] [0.0]
1[Table [] [AlignDefault] [0.0]
2 [[]]
2 [[]]
3− [[[]]
3+ [[[Plain []]]
4 ,[[Plain [Str "User\8217s",Space,Str "Guide"]]]
4 ,[[Plain [Str "User\8217s",Space,Str "Guide"]]]
5− ,[[]]
5+ ,[[Plain []]]
6− ,[[]]
6+ ,[[Plain []]]
7− ,[[]]
7+ ,[[Plain []]]
8 ,[[Plain [Str "11",Space,Str "August",Space,Str "2017"]]]
8 ,[[Plain [Str "11",Space,Str "August",Space,Str "2017"]]]
9− ,[[]]
9+ ,[[Plain []]]
10− ,[[]]
10+ ,[[Plain []]]
11− ,[[]]
11+ ,[[Plain []]]
12− ,[[]]]
12+ ,[[Plain []]]]
13,Para [Str "CONTENTS"]
13,Para [Str "CONTENTS"]
14,Para [Strong [Str "Section",Space,Str "Page"]]
14,Para [Strong [Str "Section",Space,Str "Page"]]
15,Para [Str "FIGURES",Space,Str "iv"]
15,Para [Str "FIGURES",Space,Str "iv"]
test/docx/comments.native+1−1
@@ -1,4 +1,4 @@
1[Para [Str "I",Space,Str "want",Space,Span ("",["comment-start"],[("id","0"),("author","Jesse Rosenthal"),("date","2016-05-09T16:13:00Z")]) [Str "I",Space,Str "left",Space,Str "a",Space,Str "comment."],Str "some",Space,Str "text",Space,Str "to",Space,Str "have",Space,Str "a",Space,Str "comment",Space,Span ("",["comment-end"],[("id","0")]) [],Str "on",Space,Str "it."]
1[Para [Str "I",Space,Str "want",Space,Span ("",["comment-start"],[("id","0"),("author","Jesse Rosenthal"),("date","2016-05-09T16:13:00Z")]) [Str "I",Space,Str "left",Space,Str "a",Space,Str "comment."],Str "some",Space,Str "text",Space,Str "to",Space,Str "have",Space,Str "a",Space,Str "comment",Space,Span ("",["comment-end"],[("id","0")]) [],Str "on",Space,Str "it."]
2,Para [Str "This",Space,Str "is",Space,Span ("",["comment-start"],[("id","1"),("author","Jesse Rosenthal"),("date","2016-05-09T16:13:00Z")]) [Str "A",Space,Str "comment",Space,Str "across",Space,Str "paragraphs."],Str "a",Space,Str "new",Space,Str "paragraph."]
2,Para [Str "This",Space,Str "is",Space,Span ("",["comment-start"],[("id","1"),("author","Jesse Rosenthal"),("date","2016-05-09T16:13:00Z")]) [Str "A",Space,Str "comment",Space,Str "across",Space,Str "paragraphs."],Str "a",Space,Str "new",Space,Str "paragraph."]
3,Para [Str "And",Space,Str "so",Span ("",["comment-end"],[("id","1")]) [],Space,Str "is",Space,Str "this."]
3,Para [Str "And",Space,Str "so",Span ("",["comment-end"],[("id","1")]) [],Space,Str "is",Space,Str "this."]
4−,Para [Str "One",Space,Span ("",["comment-start"],[("id","2"),("author","Jesse Rosenthal"),("date","2016-05-09T16:14:00Z")]) [Str "This",Space,Str "one",Space,Str "has",Space,Str "multiple",Space,Str "paragraphs.",Space,Str "\182",Space,Str "See?"],Str "more",Span ("",["comment-end"],[("id","2")]) [],Str ".",Space,Str "And",Space,Str "this",Space,Str "is",Space,Str "one",Space,Str "with",Space,Str "a",Space,Span ("",["comment-start"],[("id","3"),("author","Jesse Rosenthal"),("date","2016-06-22T14:35:00Z")]) [Str "Do",Space,Str "something."],Span ("",["comment-start"],[("id","4"),("author","Jesse Rosenthal"),("date","2016-06-22T14:36:00Z")]) [Str "Do",Space,Str "something",Space,Str "else."],Str "comment",Space,Str "in",Space,Str "a",Space,Str "comment",Span ("",["comment-end"],[("id","3")]) [Span ("",["comment-end"],[("id","4")]) []],Str "."]]
4+,Para [Str "One",Space,Span ("",["comment-start"],[("id","2"),("author","Jesse Rosenthal"),("date","2016-05-09T16:14:00Z")]) [Str "This",Space,Str "one",Space,Str "has",Space,Str "multiple",Space,Str "paragraphs.",Space,Str "\182",Space,Str "\182",Space,Str "See?"],Str "more",Span ("",["comment-end"],[("id","2")]) [],Str ".",Space,Str "And",Space,Str "this",Space,Str "is",Space,Str "one",Space,Str "with",Space,Str "a",Space,Span ("",["comment-start"],[("id","3"),("author","Jesse Rosenthal"),("date","2016-06-22T14:35:00Z")]) [Str "Do",Space,Str "something."],Span ("",["comment-start"],[("id","4"),("author","Jesse Rosenthal"),("date","2016-06-22T14:36:00Z")]) [Str "Do",Space,Str "something",Space,Str "else."],Str "comment",Space,Str "in",Space,Str "a",Space,Str "comment",Span ("",["comment-end"],[("id","3")]) [Span ("",["comment-end"],[("id","4")]) []],Str "."]]
test/docx/drop_cap_nostrip.nativenew file+9
@@ -0,0 +1,9 @@
1+[Para [Str "Drop",Space,Str "cap."]
2+,Para []
3+,Para [Str "Next",Space,Str "paragraph."]
4+,Para []
5+,Para [Str "Drop",Space,Str "cap",Space,Str "in",Space,Str "margin."]
6+,Para []
7+,Para []
8+,Para []
9+,Para [Str "Drop",Space,Str "cap",Space,Str "(not",Space,Str "really)."]]