From bca74a2bd0187c0dab522e768d7d18f8f53abfa9 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Mon, 11 Aug 2014 21:42:02 -0400 Subject: Add dropCap to paragraph style. --- src/Text/Pandoc/Readers/Docx/Parse.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs index 1abd4bc6b..175bf2784 100644 --- a/src/Text/Pandoc/Readers/Docx/Parse.hs +++ b/src/Text/Pandoc/Readers/Docx/Parse.hs @@ -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 -- cgit v1.2.3 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 From 45ec035e93ec0c32f9fb7d7f2f99ca17de73ebf9 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Mon, 11 Aug 2014 23:30:12 -0400 Subject: Docx reader: combine inlines properly in dropcaps. Make sure that adjacent inlines are combined properly in dropcaps. This updates the test results as well. --- src/Text/Pandoc/Readers/Docx.hs | 2 +- tests/docx.drop_cap.native | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index d6d5f317c..c856ca30a 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -462,7 +462,7 @@ bodyPartToBlocks (Paragraph pPr parparts) bodyPartToBlocks (Paragraph pPr parparts) = do ils <- parPartsToInlines parparts >>= (return . normalizeSpaces) dropIls <- gets docxDropCap - let ils' = dropIls ++ ils + let ils' = reduceList $ dropIls ++ ils if dropCap pPr then do modify $ \s -> s { docxDropCap = ils' } return [] diff --git a/tests/docx.drop_cap.native b/tests/docx.drop_cap.native index e6eb29de7..d361cfb0b 100644 --- a/tests/docx.drop_cap.native +++ b/tests/docx.drop_cap.native @@ -1,4 +1,4 @@ -[Para [Str "D",Str "rop",Space,Str "cap."] +[Para [Str "Drop",Space,Str "cap."] ,Para [Str "Next",Space,Str "paragraph."] -,Para [Str "D",Str "rop",Space,Str "cap",Space,Str "in",Space,Str "margin."] +,Para [Str "Drop",Space,Str "cap",Space,Str "in",Space,Str "margin."] ,Para [Str "Drop",Space,Str "cap",Space,Str "(not",Space,Str "really)."]] -- cgit v1.2.3