Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 16:12:37 -05:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2019-02-04 22:52:31 +01:00
|
|
|
{- |
|
|
|
|
Module : Tests.Readers.Docx
|
2020-03-13 17:52:47 +01:00
|
|
|
Copyright : © 2017-2020 Jesse Rosenthal, John MacFarlane
|
2019-02-04 22:52:31 +01:00
|
|
|
License : GNU GPL, version 2 or above
|
|
|
|
|
|
|
|
Maintainer : Jesse Rosenthal <jrosenthal@jhu.edu>
|
|
|
|
Stability : alpha
|
|
|
|
Portability : portable
|
|
|
|
|
|
|
|
Tests for the word docx reader.
|
|
|
|
-}
|
2014-06-16 22:44:40 -07:00
|
|
|
module Tests.Readers.Docx (tests) where
|
2014-06-15 14:55:17 -04:00
|
|
|
|
2017-03-04 13:03:41 +01:00
|
|
|
import Codec.Archive.Zip
|
2017-06-10 18:26:44 +02:00
|
|
|
import qualified Data.ByteString as BS
|
2017-10-27 20:28:29 -07:00
|
|
|
import qualified Data.ByteString.Lazy as B
|
2014-06-20 18:26:15 -04:00
|
|
|
import qualified Data.Map as M
|
2017-10-27 20:28:29 -07:00
|
|
|
import qualified Data.Text as T
|
2018-01-19 21:25:24 -08:00
|
|
|
import Data.Maybe
|
2017-10-27 20:28:29 -07:00
|
|
|
import System.IO.Unsafe
|
2017-03-14 17:05:36 +01:00
|
|
|
import Test.Tasty
|
|
|
|
import Test.Tasty.HUnit
|
2017-03-04 13:03:41 +01:00
|
|
|
import Tests.Helpers
|
|
|
|
import Text.Pandoc
|
2016-12-01 12:47:05 -05:00
|
|
|
import qualified Text.Pandoc.Class as P
|
2021-05-23 22:57:02 -07:00
|
|
|
import qualified Text.Pandoc.MediaBag as MB
|
2017-10-27 20:28:29 -07:00
|
|
|
import Text.Pandoc.UTF8 as UTF8
|
2014-06-15 14:55:17 -04:00
|
|
|
|
2014-06-20 18:26:15 -04:00
|
|
|
-- We define a wrapper around pandoc that doesn't normalize in the
|
|
|
|
-- tests. Since we do our own normalization, we want to make sure
|
|
|
|
-- we're doing it right.
|
|
|
|
|
2020-09-13 10:48:14 -04:00
|
|
|
newtype NoNormPandoc = NoNormPandoc {unNoNorm :: Pandoc}
|
2014-06-20 18:26:15 -04:00
|
|
|
deriving Show
|
|
|
|
|
|
|
|
noNorm :: Pandoc -> NoNormPandoc
|
|
|
|
noNorm = NoNormPandoc
|
|
|
|
|
2017-01-15 20:42:00 +01:00
|
|
|
defopts :: ReaderOptions
|
|
|
|
defopts = def{ readerExtensions = getDefaultExtensions "docx" }
|
|
|
|
|
2014-06-20 18:26:15 -04:00
|
|
|
instance ToString NoNormPandoc where
|
2017-06-10 23:39:49 +02:00
|
|
|
toString d = T.unpack $ purely (writeNative def{ writerTemplate = s }) $ toPandoc d
|
2014-06-20 18:26:15 -04:00
|
|
|
where s = case d of
|
|
|
|
NoNormPandoc (Pandoc (Meta m) _)
|
2016-11-30 15:34:58 +01:00
|
|
|
| M.null m -> Nothing
|
2019-07-26 12:00:44 -07:00
|
|
|
| otherwise -> Just mempty -- need this to get meta output
|
2014-06-20 18:26:15 -04:00
|
|
|
|
|
|
|
instance ToPandoc NoNormPandoc where
|
|
|
|
toPandoc = unNoNorm
|
|
|
|
|
2017-12-04 10:31:06 -08:00
|
|
|
compareOutput :: ReaderOptions
|
|
|
|
-> FilePath
|
|
|
|
-> FilePath
|
|
|
|
-> IO (NoNormPandoc, NoNormPandoc)
|
|
|
|
compareOutput opts docxFile nativeFile = do
|
2014-06-15 14:55:17 -04:00
|
|
|
df <- B.readFile docxFile
|
2017-06-10 18:26:44 +02:00
|
|
|
nf <- UTF8.toText <$> BS.readFile nativeFile
|
2016-12-01 12:47:05 -05:00
|
|
|
p <- runIOorExplode $ readDocx opts df
|
2016-12-10 16:52:35 +01:00
|
|
|
df' <- runIOorExplode $ readNative def nf
|
2018-01-19 21:25:24 -08:00
|
|
|
return (noNorm p, noNorm df')
|
2014-06-15 14:55:17 -04:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
testCompareWithOptsIO :: ReaderOptions -> String -> FilePath -> FilePath -> IO TestTree
|
2014-06-19 12:05:16 -04:00
|
|
|
testCompareWithOptsIO opts name docxFile nativeFile = do
|
2017-12-04 10:31:06 -08:00
|
|
|
(dp, np) <- compareOutput opts docxFile nativeFile
|
2014-06-15 14:55:17 -04:00
|
|
|
return $ test id name (dp, np)
|
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
testCompareWithOpts :: ReaderOptions -> String -> FilePath -> FilePath -> TestTree
|
2014-06-19 12:05:16 -04:00
|
|
|
testCompareWithOpts opts name docxFile nativeFile =
|
2017-03-14 17:05:36 +01:00
|
|
|
unsafePerformIO $ testCompareWithOptsIO opts name docxFile nativeFile
|
2014-06-19 12:05:16 -04:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
testCompare :: String -> FilePath -> FilePath -> TestTree
|
2017-01-15 20:42:00 +01:00
|
|
|
testCompare = testCompareWithOpts defopts
|
2014-06-15 14:55:17 -04:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
testForWarningsWithOptsIO :: ReaderOptions -> String -> FilePath -> [String] -> IO TestTree
|
2016-06-23 10:45:14 -04:00
|
|
|
testForWarningsWithOptsIO opts name docxFile expected = do
|
|
|
|
df <- B.readFile docxFile
|
2017-03-14 21:06:14 +01:00
|
|
|
logs <- runIOorExplode $ setVerbosity ERROR >> readDocx opts df >> P.getLog
|
2017-02-10 23:59:47 +01:00
|
|
|
let warns = [m | DocxParserWarning m <- logs]
|
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 16:12:37 -05:00
|
|
|
return $ test id name (T.unlines warns, unlines expected)
|
2016-06-23 10:45:14 -04:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
testForWarningsWithOpts :: ReaderOptions -> String -> FilePath -> [String] -> TestTree
|
2016-06-23 10:45:14 -04:00
|
|
|
testForWarningsWithOpts opts name docxFile expected =
|
2017-03-14 17:05:36 +01:00
|
|
|
unsafePerformIO $ testForWarningsWithOptsIO opts name docxFile expected
|
2016-06-23 10:45:14 -04:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
-- testForWarnings :: String -> FilePath -> [String] -> TestTree
|
2017-01-15 20:42:00 +01:00
|
|
|
-- testForWarnings = testForWarningsWithOpts defopts
|
2016-06-23 10:45:14 -04:00
|
|
|
|
2014-07-31 12:10:33 -04:00
|
|
|
getMedia :: FilePath -> FilePath -> IO (Maybe B.ByteString)
|
2020-03-29 01:48:47 -04:00
|
|
|
getMedia archivePath mediaPath = fmap fromEntry . findEntryByPath
|
|
|
|
("word/" ++ mediaPath) . toArchive <$> B.readFile archivePath
|
2014-07-31 12:10:33 -04:00
|
|
|
|
2021-05-23 22:57:02 -07:00
|
|
|
compareMediaPathIO :: FilePath -> MB.MediaBag -> FilePath -> IO Bool
|
2014-07-31 12:10:33 -04:00
|
|
|
compareMediaPathIO mediaPath mediaBag docxPath = do
|
|
|
|
docxMedia <- getMedia docxPath mediaPath
|
2021-05-23 22:57:02 -07:00
|
|
|
let mbBS = case MB.lookupMedia mediaPath mediaBag of
|
|
|
|
Just item -> MB.mediaContents item
|
2014-07-31 12:10:33 -04:00
|
|
|
Nothing -> error ("couldn't find " ++
|
|
|
|
mediaPath ++
|
|
|
|
" in media bag")
|
2018-01-19 21:25:24 -08:00
|
|
|
docxBS = fromMaybe (error ("couldn't find " ++
|
|
|
|
mediaPath ++
|
|
|
|
" in media bag")) docxMedia
|
2014-07-31 12:10:33 -04:00
|
|
|
return $ mbBS == docxBS
|
|
|
|
|
|
|
|
compareMediaBagIO :: FilePath -> IO Bool
|
|
|
|
compareMediaBagIO docxFile = do
|
2014-07-30 22:31:38 -04:00
|
|
|
df <- B.readFile docxFile
|
2017-03-14 21:06:14 +01:00
|
|
|
mb <- runIOorExplode $ readDocx defopts df >> P.getMediaBag
|
2014-07-31 12:10:33 -04:00
|
|
|
bools <- mapM
|
2014-08-11 23:10:50 -04:00
|
|
|
(\(fp, _, _) -> compareMediaPathIO fp mb docxFile)
|
2021-05-23 22:57:02 -07:00
|
|
|
(MB.mediaDirectory mb)
|
2014-07-31 12:10:33 -04:00
|
|
|
return $ and bools
|
2014-07-30 22:31:38 -04:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
testMediaBagIO :: String -> FilePath -> IO TestTree
|
2014-07-31 12:10:33 -04:00
|
|
|
testMediaBagIO name docxFile = do
|
|
|
|
outcome <- compareMediaBagIO docxFile
|
2014-08-11 23:10:50 -04:00
|
|
|
return $ testCase name (assertBool
|
2014-07-31 12:10:33 -04:00
|
|
|
("Media didn't match media bag in file " ++ docxFile)
|
|
|
|
outcome)
|
2014-07-30 22:31:38 -04:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
testMediaBag :: String -> FilePath -> TestTree
|
|
|
|
testMediaBag name docxFile = unsafePerformIO $ testMediaBagIO name docxFile
|
2014-06-15 14:55:17 -04:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
tests :: [TestTree]
|
2019-02-06 21:11:51 -05:00
|
|
|
tests = [ testGroup "document"
|
|
|
|
[ testCompare
|
|
|
|
"allow different document.xml file as defined in _rels/.rels"
|
|
|
|
"docx/alternate_document_path.docx"
|
|
|
|
"docx/alternate_document_path.native"
|
|
|
|
]
|
|
|
|
, testGroup "inlines"
|
2014-06-15 14:55:17 -04:00
|
|
|
[ testCompare
|
|
|
|
"font formatting"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/inline_formatting.docx"
|
|
|
|
"docx/inline_formatting.native"
|
2014-08-16 14:05:56 -04:00
|
|
|
, testCompare
|
|
|
|
"font formatting with character styles"
|
|
|
|
"docx/char_styles.docx"
|
|
|
|
"docx/char_styles.native"
|
2014-06-15 14:55:17 -04:00
|
|
|
, testCompare
|
|
|
|
"hyperlinks"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/links.docx"
|
|
|
|
"docx/links.native"
|
2018-01-16 13:20:01 -05:00
|
|
|
, testCompare
|
|
|
|
"hyperlinks in <w:instrText> tag"
|
|
|
|
"docx/instrText_hyperlink.docx"
|
|
|
|
"docx/instrText_hyperlink.native"
|
2014-06-15 14:55:17 -04:00
|
|
|
, testCompare
|
2014-08-07 15:34:49 -04:00
|
|
|
"inline image"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/image.docx"
|
|
|
|
"docx/image_no_embed.native"
|
2015-01-21 13:38:04 -05:00
|
|
|
, testCompare
|
|
|
|
"VML image"
|
|
|
|
"docx/image_vml.docx"
|
|
|
|
"docx/image_vml.native"
|
2021-04-29 18:11:44 +02:00
|
|
|
, testCompare
|
|
|
|
"VML image as object"
|
|
|
|
"docx/image_vml_as_object.docx"
|
|
|
|
"docx/image_vml_as_object.native"
|
2014-08-07 15:34:49 -04:00
|
|
|
, testCompare
|
|
|
|
"inline image in links"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/inline_images.docx"
|
|
|
|
"docx/inline_images.native"
|
2014-06-15 14:55:17 -04:00
|
|
|
, testCompare
|
|
|
|
"handling unicode input"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/unicode.docx"
|
|
|
|
"docx/unicode.native"
|
2014-06-19 19:33:22 -04:00
|
|
|
, testCompare
|
|
|
|
"literal tabs"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/tabs.docx"
|
|
|
|
"docx/tabs.native"
|
2015-10-04 06:08:17 -04:00
|
|
|
, testCompare
|
|
|
|
"special punctuation"
|
|
|
|
"docx/special_punctuation.docx"
|
|
|
|
"docx/special_punctuation.native"
|
2014-06-21 17:58:32 -04:00
|
|
|
, testCompare
|
|
|
|
"normalizing inlines"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/normalize.docx"
|
|
|
|
"docx/normalize.native"
|
2014-06-22 01:58:41 -04:00
|
|
|
, testCompare
|
|
|
|
"normalizing inlines deep inside blocks"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/deep_normalize.docx"
|
|
|
|
"docx/deep_normalize.native"
|
2014-06-23 15:40:34 -04:00
|
|
|
, testCompare
|
|
|
|
"move trailing spaces outside of formatting"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/trailing_spaces_in_formatting.docx"
|
|
|
|
"docx/trailing_spaces_in_formatting.native"
|
2014-06-24 10:33:49 -04:00
|
|
|
, testCompare
|
2019-02-18 15:49:00 -05:00
|
|
|
"remove trailing spaces from last inline"
|
|
|
|
"docx/trim_last_inline.docx"
|
|
|
|
"docx/trim_last_inline.native"
|
|
|
|
, testCompare
|
2014-06-24 10:33:49 -04:00
|
|
|
"inline code (with VerbatimChar style)"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/inline_code.docx"
|
|
|
|
"docx/inline_code.native"
|
2015-02-21 08:44:13 -05:00
|
|
|
, testCompare
|
|
|
|
"inline code in subscript and superscript"
|
|
|
|
"docx/verbatim_subsuper.docx"
|
|
|
|
"docx/verbatim_subsuper.native"
|
2017-12-27 10:01:45 -05:00
|
|
|
, testCompare
|
|
|
|
"inlines inside of Structured Document Tags"
|
|
|
|
"docx/sdt_elements.docx"
|
|
|
|
"docx/sdt_elements.native"
|
2019-02-12 17:26:37 -05:00
|
|
|
, testCompare
|
|
|
|
"Structured Document Tags in footnotes"
|
|
|
|
"docx/sdt_in_footnote.docx"
|
|
|
|
"docx/sdt_in_footnote.native"
|
2018-02-28 16:27:18 -05:00
|
|
|
, testCompare
|
|
|
|
"nested Structured Document Tags"
|
|
|
|
"docx/nested_sdt.docx"
|
|
|
|
"docx/nested_sdt.native"
|
2018-03-13 22:12:55 -04:00
|
|
|
, testCompare
|
|
|
|
"nested Smart Tags"
|
|
|
|
"docx/nested_smart_tags.docx"
|
|
|
|
"docx/nested_smart_tags.native"
|
2017-12-30 22:43:33 -05:00
|
|
|
, testCompare
|
|
|
|
"remove anchor spans with nothing pointing to them"
|
|
|
|
"docx/unused_anchors.docx"
|
|
|
|
"docx/unused_anchors.native"
|
2017-12-31 09:36:42 -05:00
|
|
|
, testCompare
|
|
|
|
"collapse overlapping targets (anchor spans)"
|
|
|
|
"docx/overlapping_targets.docx"
|
|
|
|
"docx/overlapping_targets.native"
|
2014-06-19 19:33:22 -04:00
|
|
|
]
|
2014-06-15 14:55:17 -04:00
|
|
|
, testGroup "blocks"
|
|
|
|
[ testCompare
|
|
|
|
"headers"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/headers.docx"
|
|
|
|
"docx/headers.native"
|
2014-07-15 10:25:32 +01:00
|
|
|
, testCompare
|
|
|
|
"headers already having auto identifiers"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/already_auto_ident.docx"
|
|
|
|
"docx/already_auto_ident.native"
|
2017-08-06 19:36:25 -07:00
|
|
|
, testCompare
|
|
|
|
"avoid zero-level headers"
|
|
|
|
"docx/0_level_headers.docx"
|
|
|
|
"docx/0_level_headers.native"
|
2016-08-29 08:35:59 -04:00
|
|
|
, testCompare
|
|
|
|
"nested anchor spans in header"
|
|
|
|
"docx/nested_anchors_in_header.docx"
|
|
|
|
"docx/nested_anchors_in_header.native"
|
2014-09-04 19:39:49 -04:00
|
|
|
, testCompare
|
2016-03-16 12:56:17 -04:00
|
|
|
"single numbered item not made into list"
|
2014-09-04 19:39:49 -04:00
|
|
|
"docx/numbered_header.docx"
|
|
|
|
"docx/numbered_header.native"
|
2016-03-16 12:56:17 -04:00
|
|
|
, testCompare
|
|
|
|
"enumerated headers not made into numbered list"
|
|
|
|
"docx/enumerated_headings.docx"
|
|
|
|
"docx/enumerated_headings.native"
|
2014-10-25 16:00:27 -04:00
|
|
|
, testCompare
|
|
|
|
"i18n blocks (headers and blockquotes)"
|
|
|
|
"docx/i18n_blocks.docx"
|
|
|
|
"docx/i18n_blocks.native"
|
2014-06-15 14:55:17 -04:00
|
|
|
, testCompare
|
|
|
|
"lists"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/lists.docx"
|
|
|
|
"docx/lists.native"
|
[Docx Reader] Use style names, not ids, for assigning semantic meaning
Motivating issues: #5523, #5052, #5074
Style name comparisons are case-insensitive, since those are
case-insensitive in Word.
w:styleId will be used as style name if w:name is missing (this should
only happen for malformed docx and is kept as a fallback to avoid
failing altogether on malformed documents)
Block quote detection code moved from Docx.Parser to Readers.Docx
Code styles, i.e. "Source Code" and "Verbatim Char" now honor style
inheritance
Docx Reader now honours "Compact" style (used in Pandoc-generated docx).
The side-effect is that "Compact" style no longer shows up in
docx+styles output. Styles inherited from "Compact" will still
show up.
Removed obsolete list-item style from divsToKeep. That didn't
really do anything for a while now.
Add newtypes to differentiate between style names, ids, and
different style types (that is, paragraph and character styles)
Since docx style names can have spaces in them, and pandoc-markdown
classes can't, anywhere when style name is used as a class name,
spaces are replaced with ASCII dashes `-`.
Get rid of extraneous intermediate types, carrying styleId information.
Instead, styleId is saved with other style data.
Use RunStyle for inline style definitions only (lacking styleId and styleName);
for Character Styles use CharStyle type (which is basicaly RunStyle with styleId
and StyleName bolted onto it).
2019-09-15 01:40:23 +03:00
|
|
|
, testCompare
|
|
|
|
"compact lists"
|
|
|
|
"docx/lists-compact.docx"
|
|
|
|
"docx/lists-compact.native"
|
2018-12-10 19:23:03 -05:00
|
|
|
, testCompare
|
|
|
|
"lists with level overrides"
|
|
|
|
"docx/lists_level_override.docx"
|
|
|
|
"docx/lists_level_override.native"
|
2017-12-13 15:14:23 -05:00
|
|
|
, testCompare
|
|
|
|
"lists continuing after interruption"
|
|
|
|
"docx/lists_continuing.docx"
|
|
|
|
"docx/lists_continuing.native"
|
|
|
|
, testCompare
|
|
|
|
"lists restarting after interruption"
|
|
|
|
"docx/lists_restarting.docx"
|
|
|
|
"docx/lists_restarting.native"
|
2019-11-03 12:54:42 -08:00
|
|
|
, testCompare
|
|
|
|
"sublists reset numbering to 1"
|
|
|
|
"docx/lists_sublist_reset.docx"
|
|
|
|
"docx/lists_sublist_reset.native"
|
2014-06-24 11:48:23 -04:00
|
|
|
, testCompare
|
|
|
|
"definition lists"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/definition_list.docx"
|
|
|
|
"docx/definition_list.native"
|
2015-02-19 00:24:04 -05:00
|
|
|
, testCompare
|
|
|
|
"custom defined lists in styles"
|
|
|
|
"docx/german_styled_lists.docx"
|
|
|
|
"docx/german_styled_lists.native"
|
2015-11-18 13:15:23 -05:00
|
|
|
, testCompare
|
|
|
|
"user deletes bullet after list item (=> part of item par)"
|
|
|
|
"docx/dummy_item_after_list_item.docx"
|
|
|
|
"docx/dummy_item_after_list_item.native"
|
|
|
|
, testCompare
|
|
|
|
"user deletes bullet after par (=> new par)"
|
|
|
|
"docx/dummy_item_after_paragraph.docx"
|
|
|
|
"docx/dummy_item_after_paragraph.native"
|
2014-06-15 14:55:17 -04:00
|
|
|
, testCompare
|
|
|
|
"footnotes and endnotes"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/notes.docx"
|
|
|
|
"docx/notes.native"
|
2015-11-14 13:45:29 -05:00
|
|
|
, testCompare
|
|
|
|
"links in footnotes and endnotes"
|
|
|
|
"docx/link_in_notes.docx"
|
|
|
|
"docx/link_in_notes.native"
|
2014-06-15 14:55:17 -04:00
|
|
|
, testCompare
|
|
|
|
"blockquotes (parsing indent as blockquote)"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/block_quotes.docx"
|
|
|
|
"docx/block_quotes_parse_indent.native"
|
2014-06-29 23:37:00 -04:00
|
|
|
, testCompare
|
|
|
|
"hanging indents"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/hanging_indent.docx"
|
|
|
|
"docx/hanging_indent.native"
|
2014-06-15 14:55:17 -04:00
|
|
|
, testCompare
|
|
|
|
"tables"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/tables.docx"
|
|
|
|
"docx/tables.native"
|
2015-02-13 09:08:07 -05:00
|
|
|
, testCompare
|
|
|
|
"tables with lists in cells"
|
|
|
|
"docx/table_with_list_cell.docx"
|
|
|
|
"docx/table_with_list_cell.native"
|
Docx reader: Support new table features.
* Column spans
* Row spans
- The spec says that if the `val` attribute is ommitted, its value
should be assumed to be `continue`, and that its values are
restricted to {`restart`, `continue`}. If the value has any other
value, I think it seems reasonable to default it to `continue`. It
might cause problems if the spec is extended in the future by adding
a third possible value, in which case this would probably give
incorrect behaviour, and wouldn't error.
* Allow multiple header rows
* Include table description in simple caption
- The table description element is like alt text for a table (along
with the table caption element). It seems like we should include
this somewhere, but I’m not 100% sure how – I’m pairing it with the
simple caption for the moment. (Should it maybe go in the block
caption instead?)
* Detect table captions
- Check for caption paragraph style /and/ either the simple or
complex table field. This means the caption detection fails for
captions which don’t contain a field, as in an example doc I added
as a test. However, I think it’s better to be too conservative: a
missed table caption will still show up as a paragraph next to the
table, whereas if I incorrectly classify something else as a table
caption it could cause havoc by pairing it up with a table it’s
not at all related to, or dropping it entirely.
* Update tests and add new ones
Partially fixes: #6316
2020-06-18 09:53:32 +01:00
|
|
|
, testCompare
|
|
|
|
"a table with a header which contains rowspans greater than 1"
|
|
|
|
"docx/table_header_rowspan.docx"
|
|
|
|
"docx/table_header_rowspan.native"
|
2016-12-08 06:57:38 -05:00
|
|
|
, testCompare
|
|
|
|
"tables with one row"
|
|
|
|
"docx/table_one_row.docx"
|
|
|
|
"docx/table_one_row.native"
|
Docx reader: Support new table features.
* Column spans
* Row spans
- The spec says that if the `val` attribute is ommitted, its value
should be assumed to be `continue`, and that its values are
restricted to {`restart`, `continue`}. If the value has any other
value, I think it seems reasonable to default it to `continue`. It
might cause problems if the spec is extended in the future by adding
a third possible value, in which case this would probably give
incorrect behaviour, and wouldn't error.
* Allow multiple header rows
* Include table description in simple caption
- The table description element is like alt text for a table (along
with the table caption element). It seems like we should include
this somewhere, but I’m not 100% sure how – I’m pairing it with the
simple caption for the moment. (Should it maybe go in the block
caption instead?)
* Detect table captions
- Check for caption paragraph style /and/ either the simple or
complex table field. This means the caption detection fails for
captions which don’t contain a field, as in an example doc I added
as a test. However, I think it’s better to be too conservative: a
missed table caption will still show up as a paragraph next to the
table, whereas if I incorrectly classify something else as a table
caption it could cause havoc by pairing it up with a table it’s
not at all related to, or dropping it entirely.
* Update tests and add new ones
Partially fixes: #6316
2020-06-18 09:53:32 +01:00
|
|
|
, testCompare
|
|
|
|
"tables with just one row, which is a header"
|
|
|
|
"docx/table_one_header_row.docx"
|
|
|
|
"docx/table_one_header_row.native"
|
2018-02-12 17:10:29 +01:00
|
|
|
, testCompare
|
|
|
|
"tables with variable width"
|
|
|
|
"docx/table_variable_width.docx"
|
|
|
|
"docx/table_variable_width.native"
|
Docx reader: Support new table features.
* Column spans
* Row spans
- The spec says that if the `val` attribute is ommitted, its value
should be assumed to be `continue`, and that its values are
restricted to {`restart`, `continue`}. If the value has any other
value, I think it seems reasonable to default it to `continue`. It
might cause problems if the spec is extended in the future by adding
a third possible value, in which case this would probably give
incorrect behaviour, and wouldn't error.
* Allow multiple header rows
* Include table description in simple caption
- The table description element is like alt text for a table (along
with the table caption element). It seems like we should include
this somewhere, but I’m not 100% sure how – I’m pairing it with the
simple caption for the moment. (Should it maybe go in the block
caption instead?)
* Detect table captions
- Check for caption paragraph style /and/ either the simple or
complex table field. This means the caption detection fails for
captions which don’t contain a field, as in an example doc I added
as a test. However, I think it’s better to be too conservative: a
missed table caption will still show up as a paragraph next to the
table, whereas if I incorrectly classify something else as a table
caption it could cause havoc by pairing it up with a table it’s
not at all related to, or dropping it entirely.
* Update tests and add new ones
Partially fixes: #6316
2020-06-18 09:53:32 +01:00
|
|
|
, testCompare
|
|
|
|
"tables with captions which contain a Table field"
|
|
|
|
"docx/table_captions_with_field.docx"
|
|
|
|
"docx/table_captions_with_field.native"
|
|
|
|
, testCompare
|
|
|
|
"tables with captions which don't contain a Table field"
|
|
|
|
"docx/table_captions_no_field.docx"
|
|
|
|
"docx/table_captions_no_field.native"
|
2014-06-24 10:33:49 -04:00
|
|
|
, testCompare
|
|
|
|
"code block"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/codeblock.docx"
|
|
|
|
"docx/codeblock.native"
|
2018-04-17 09:29:54 -04:00
|
|
|
, testCompare
|
|
|
|
"combine adjacent code blocks"
|
|
|
|
"docx/adjacent_codeblocks.docx"
|
|
|
|
"docx/adjacent_codeblocks.native"
|
2014-08-11 23:10:50 -04:00
|
|
|
, testCompare
|
|
|
|
"dropcap paragraphs"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/drop_cap.docx"
|
|
|
|
"docx/drop_cap.native"
|
2014-06-15 14:55:17 -04:00
|
|
|
]
|
2014-06-25 11:09:28 -04:00
|
|
|
, testGroup "track changes"
|
|
|
|
[ testCompare
|
2014-06-25 16:13:59 -04:00
|
|
|
"insertion (default)"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/track_changes_insertion.docx"
|
|
|
|
"docx/track_changes_insertion_accept.native"
|
2014-06-25 16:13:59 -04:00
|
|
|
, testCompareWithOpts def{readerTrackChanges=AcceptChanges}
|
|
|
|
"insert insertion (accept)"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/track_changes_insertion.docx"
|
|
|
|
"docx/track_changes_insertion_accept.native"
|
2014-06-25 16:13:59 -04:00
|
|
|
, testCompareWithOpts def{readerTrackChanges=RejectChanges}
|
|
|
|
"remove insertion (reject)"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/track_changes_insertion.docx"
|
|
|
|
"docx/track_changes_insertion_reject.native"
|
2014-06-25 11:09:28 -04:00
|
|
|
, testCompare
|
2014-06-25 16:13:59 -04:00
|
|
|
"deletion (default)"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/track_changes_deletion.docx"
|
|
|
|
"docx/track_changes_deletion_accept.native"
|
2014-06-25 16:13:59 -04:00
|
|
|
, testCompareWithOpts def{readerTrackChanges=AcceptChanges}
|
|
|
|
"remove deletion (accept)"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/track_changes_deletion.docx"
|
|
|
|
"docx/track_changes_deletion_accept.native"
|
2014-06-25 16:13:59 -04:00
|
|
|
, testCompareWithOpts def{readerTrackChanges=RejectChanges}
|
|
|
|
"insert deletion (reject)"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/track_changes_deletion.docx"
|
|
|
|
"docx/track_changes_deletion_reject.native"
|
2014-06-25 16:13:59 -04:00
|
|
|
, testCompareWithOpts def{readerTrackChanges=AllChanges}
|
|
|
|
"keep insertion (all)"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/track_changes_deletion.docx"
|
|
|
|
"docx/track_changes_deletion_all.native"
|
2014-06-25 16:13:59 -04:00
|
|
|
, testCompareWithOpts def{readerTrackChanges=AllChanges}
|
|
|
|
"keep deletion (all)"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/track_changes_deletion.docx"
|
|
|
|
"docx/track_changes_deletion_all.native"
|
2016-04-16 08:39:25 -04:00
|
|
|
, testCompareWithOpts def{readerTrackChanges=AcceptChanges}
|
|
|
|
"move text (accept)"
|
|
|
|
"docx/track_changes_move.docx"
|
|
|
|
"docx/track_changes_move_accept.native"
|
|
|
|
, testCompareWithOpts def{readerTrackChanges=RejectChanges}
|
|
|
|
"move text (reject)"
|
|
|
|
"docx/track_changes_move.docx"
|
|
|
|
"docx/track_changes_move_reject.native"
|
|
|
|
, testCompareWithOpts def{readerTrackChanges=AllChanges}
|
|
|
|
"move text (all)"
|
|
|
|
"docx/track_changes_move.docx"
|
|
|
|
"docx/track_changes_move_all.native"
|
2016-06-23 10:46:01 -04:00
|
|
|
, testCompareWithOpts def{readerTrackChanges=AcceptChanges}
|
|
|
|
"comments (accept -- no comments)"
|
|
|
|
"docx/comments.docx"
|
|
|
|
"docx/comments_no_comments.native"
|
|
|
|
, testCompareWithOpts def{readerTrackChanges=RejectChanges}
|
|
|
|
"comments (reject -- comments)"
|
|
|
|
"docx/comments.docx"
|
|
|
|
"docx/comments_no_comments.native"
|
|
|
|
, testCompareWithOpts def{readerTrackChanges=AllChanges}
|
|
|
|
"comments (all comments)"
|
|
|
|
"docx/comments.docx"
|
|
|
|
"docx/comments.native"
|
2018-01-02 11:24:26 -05:00
|
|
|
, testCompareWithOpts def{readerTrackChanges=AcceptChanges}
|
|
|
|
"paragraph insertion/deletion (accept)"
|
|
|
|
"docx/paragraph_insertion_deletion.docx"
|
|
|
|
"docx/paragraph_insertion_deletion_accept.native"
|
|
|
|
, testCompareWithOpts def{readerTrackChanges=RejectChanges}
|
|
|
|
"paragraph insertion/deletion (reject)"
|
|
|
|
"docx/paragraph_insertion_deletion.docx"
|
|
|
|
"docx/paragraph_insertion_deletion_reject.native"
|
|
|
|
, testCompareWithOpts def{readerTrackChanges=AllChanges}
|
|
|
|
"paragraph insertion/deletion (all)"
|
|
|
|
"docx/paragraph_insertion_deletion.docx"
|
|
|
|
"docx/paragraph_insertion_deletion_all.native"
|
2020-10-06 23:03:00 -05:00
|
|
|
, testCompareWithOpts def{readerTrackChanges=AllChanges}
|
|
|
|
"paragraph insertion/deletion (all)"
|
|
|
|
"docx/track_changes_scrubbed_metadata.docx"
|
|
|
|
"docx/track_changes_scrubbed_metadata.native"
|
2016-06-23 10:46:01 -04:00
|
|
|
, testForWarningsWithOpts def{readerTrackChanges=AcceptChanges}
|
|
|
|
"comment warnings (accept -- no warnings)"
|
|
|
|
"docx/comments_warning.docx"
|
|
|
|
[]
|
|
|
|
, testForWarningsWithOpts def{readerTrackChanges=RejectChanges}
|
|
|
|
"comment warnings (reject -- no warnings)"
|
|
|
|
"docx/comments_warning.docx"
|
|
|
|
[]
|
|
|
|
, testForWarningsWithOpts def{readerTrackChanges=AllChanges}
|
|
|
|
"comment warnings (all)"
|
|
|
|
"docx/comments_warning.docx"
|
|
|
|
["Docx comment 1 will not retain formatting"]
|
2014-06-25 11:09:28 -04:00
|
|
|
]
|
2014-07-30 22:32:55 -04:00
|
|
|
, testGroup "media"
|
2014-07-31 12:10:33 -04:00
|
|
|
[ testMediaBag
|
2014-07-30 22:32:55 -04:00
|
|
|
"image extraction"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/image.docx"
|
2014-07-30 22:32:55 -04:00
|
|
|
]
|
2018-02-22 12:06:25 -05:00
|
|
|
, testGroup "custom styles"
|
|
|
|
[ testCompare
|
|
|
|
"custom styles (`+styles`) not enabled (default)"
|
|
|
|
"docx/custom-style-reference.docx"
|
|
|
|
"docx/custom-style-no-styles.native"
|
|
|
|
, testCompareWithOpts
|
|
|
|
def{readerExtensions=extensionsFromList [Ext_styles]}
|
|
|
|
"custom styles (`+styles`) enabled"
|
|
|
|
"docx/custom-style-reference.docx"
|
|
|
|
"docx/custom-style-with-styles.native"
|
[Docx Reader] Use style names, not ids, for assigning semantic meaning
Motivating issues: #5523, #5052, #5074
Style name comparisons are case-insensitive, since those are
case-insensitive in Word.
w:styleId will be used as style name if w:name is missing (this should
only happen for malformed docx and is kept as a fallback to avoid
failing altogether on malformed documents)
Block quote detection code moved from Docx.Parser to Readers.Docx
Code styles, i.e. "Source Code" and "Verbatim Char" now honor style
inheritance
Docx Reader now honours "Compact" style (used in Pandoc-generated docx).
The side-effect is that "Compact" style no longer shows up in
docx+styles output. Styles inherited from "Compact" will still
show up.
Removed obsolete list-item style from divsToKeep. That didn't
really do anything for a while now.
Add newtypes to differentiate between style names, ids, and
different style types (that is, paragraph and character styles)
Since docx style names can have spaces in them, and pandoc-markdown
classes can't, anywhere when style name is used as a class name,
spaces are replaced with ASCII dashes `-`.
Get rid of extraneous intermediate types, carrying styleId information.
Instead, styleId is saved with other style data.
Use RunStyle for inline style definitions only (lacking styleId and styleName);
for Character Styles use CharStyle type (which is basicaly RunStyle with styleId
and StyleName bolted onto it).
2019-09-15 01:40:23 +03:00
|
|
|
, testCompareWithOpts
|
|
|
|
def{readerExtensions=extensionsFromList [Ext_styles]}
|
|
|
|
"custom styles (`+styles`): Compact style is removed from output"
|
|
|
|
"docx/compact-style-removal.docx"
|
|
|
|
"docx/compact-style-removal.native"
|
2018-02-22 12:06:25 -05:00
|
|
|
]
|
2014-07-27 15:11:18 -04:00
|
|
|
, testGroup "metadata"
|
|
|
|
[ testCompareWithOpts def{readerStandalone=True}
|
|
|
|
"metadata fields"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/metadata.docx"
|
|
|
|
"docx/metadata.native"
|
2014-07-27 15:11:18 -04:00
|
|
|
, testCompareWithOpts def{readerStandalone=True}
|
|
|
|
"stop recording metadata with normal text"
|
2014-08-13 11:16:50 -07:00
|
|
|
"docx/metadata_after_normal.docx"
|
|
|
|
"docx/metadata_after_normal.native"
|
2014-07-27 15:11:18 -04:00
|
|
|
]
|
2014-06-15 14:55:17 -04:00
|
|
|
]
|