From 3e32cd5bb1ed4f5a5f408a7f676b323318bdb945 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Mon, 11 Aug 2014 22:00:03 -0400 Subject: Docx reader: Use dropcap state. If we get to a dropcap, we keep hold the inlines until the next paragraph, and combine it there. --- src/Text/Pandoc/Readers/Docx.hs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 085ee01fc..d6d5f317c 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -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' = 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 -- cgit v1.2.3