commit
4c88e64894
6 changed files with 40 additions and 15 deletions
|
@ -177,6 +177,7 @@ Extra-Source-Files:
|
|||
tests/docx.codeblock.docx,
|
||||
tests/docx.deep_normalize.docx,
|
||||
tests/docx.definition_list.docx,
|
||||
tests/docx.drop_cap.docx,
|
||||
tests/docx.hanging_indent.docx,
|
||||
tests/docx.headers.docx,
|
||||
tests/docx.image.docx,
|
||||
|
|
|
@ -105,11 +105,15 @@ readDocx opts bytes =
|
|||
Left _ -> error $ "couldn't parse docx file"
|
||||
|
||||
data DState = DState { docxAnchorMap :: M.Map String String
|
||||
, docxMediaBag :: MediaBag }
|
||||
, docxMediaBag :: MediaBag
|
||||
, docxDropCap :: [Inline]
|
||||
}
|
||||
|
||||
instance Default DState where
|
||||
def = DState { docxAnchorMap = M.empty
|
||||
, docxMediaBag = mempty }
|
||||
, docxMediaBag = mempty
|
||||
, docxDropCap = []
|
||||
}
|
||||
|
||||
data DEnv = DEnv { docxOptions :: ReaderOptions
|
||||
, docxInHeaderBlock :: Bool }
|
||||
|
@ -457,13 +461,17 @@ bodyPartToBlocks (Paragraph pPr parparts)
|
|||
return [hdr]
|
||||
bodyPartToBlocks (Paragraph pPr parparts) = do
|
||||
ils <- parPartsToInlines parparts >>= (return . normalizeSpaces)
|
||||
case ils of
|
||||
[] -> return []
|
||||
_ -> do
|
||||
return $
|
||||
rebuild
|
||||
(parStyleToContainers pPr)
|
||||
[Para ils]
|
||||
dropIls <- gets docxDropCap
|
||||
let ils' = reduceList $ dropIls ++ ils
|
||||
if dropCap pPr
|
||||
then do modify $ \s -> s { docxDropCap = ils' }
|
||||
return []
|
||||
else do modify $ \s -> s { docxDropCap = [] }
|
||||
return $ case ils' of
|
||||
[] -> []
|
||||
_ -> rebuild
|
||||
(parStyleToContainers pPr)
|
||||
[Para $ ils']
|
||||
bodyPartToBlocks (ListItem pPr numId lvl levelInfo parparts) = do
|
||||
let
|
||||
kvs = case levelInfo of
|
||||
|
|
|
@ -146,12 +146,14 @@ data ParIndentation = ParIndentation { leftParIndent :: Maybe Integer
|
|||
|
||||
data ParagraphStyle = ParagraphStyle { pStyle :: [String]
|
||||
, indentation :: Maybe ParIndentation
|
||||
, dropCap :: Bool
|
||||
}
|
||||
deriving Show
|
||||
|
||||
defaultParagraphStyle :: ParagraphStyle
|
||||
defaultParagraphStyle = ParagraphStyle { pStyle = []
|
||||
, indentation = Nothing
|
||||
, dropCap = False
|
||||
}
|
||||
|
||||
|
||||
|
@ -637,8 +639,16 @@ elemToParagraphStyle ns element
|
|||
(findAttr (elemName ns "w" "val"))
|
||||
(findChildren (elemName ns "w" "pStyle") pPr)
|
||||
, indentation =
|
||||
findChild (elemName ns "w" "ind") pPr >>=
|
||||
elemToParIndentation ns
|
||||
findChild (elemName ns "w" "ind") pPr >>=
|
||||
elemToParIndentation ns
|
||||
, dropCap =
|
||||
case
|
||||
findChild (elemName ns "w" "framePr") pPr >>=
|
||||
findAttr (elemName ns "w" "dropCap")
|
||||
of
|
||||
Just "none" -> False
|
||||
Just _ -> True
|
||||
Nothing -> False
|
||||
}
|
||||
elemToParagraphStyle _ _ = defaultParagraphStyle
|
||||
|
||||
|
|
|
@ -82,14 +82,14 @@ compareMediaBagIO docxFile = do
|
|||
df <- B.readFile docxFile
|
||||
let (_, mb) = readDocx def df
|
||||
bools <- mapM
|
||||
(\(fp, _, _) -> compareMediaPathIO fp mb docxFile)
|
||||
(\(fp, _, _) -> compareMediaPathIO fp mb docxFile)
|
||||
(mediaDirectory mb)
|
||||
return $ and bools
|
||||
|
||||
testMediaBagIO :: String -> FilePath -> IO Test
|
||||
testMediaBagIO name docxFile = do
|
||||
outcome <- compareMediaBagIO docxFile
|
||||
return $ testCase name (assertBool
|
||||
return $ testCase name (assertBool
|
||||
("Media didn't match media bag in file " ++ docxFile)
|
||||
outcome)
|
||||
|
||||
|
@ -176,7 +176,10 @@ tests = [ testGroup "inlines"
|
|||
"code block"
|
||||
"docx.codeblock.docx"
|
||||
"docx.codeblock.native"
|
||||
|
||||
, testCompare
|
||||
"dropcap paragraphs"
|
||||
"docx.drop_cap.docx"
|
||||
"docx.drop_cap.native"
|
||||
]
|
||||
, testGroup "track changes"
|
||||
[ testCompare
|
||||
|
@ -229,4 +232,3 @@ tests = [ testGroup "inlines"
|
|||
]
|
||||
|
||||
]
|
||||
|
||||
|
|
BIN
tests/docx.drop_cap.docx
Normal file
BIN
tests/docx.drop_cap.docx
Normal file
Binary file not shown.
4
tests/docx.drop_cap.native
Normal file
4
tests/docx.drop_cap.native
Normal file
|
@ -0,0 +1,4 @@
|
|||
[Para [Str "Drop",Space,Str "cap."]
|
||||
,Para [Str "Next",Space,Str "paragraph."]
|
||||
,Para [Str "Drop",Space,Str "cap",Space,Str "in",Space,Str "margin."]
|
||||
,Para [Str "Drop",Space,Str "cap",Space,Str "(not",Space,Str "really)."]]
|
Loading…
Add table
Reference in a new issue