git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1522 from jkr/dropCap

Drop cap

commit4c88e64894af56a71a15289a70b2ae7950157f86 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 11 Aug 2014, 20:38 (12 years ago) parent86d4da945ec035
6 files changed+40−15
pandoc.cabal+1 src/Text/Pandoc/Readers/Docx.hs+17−9 src/Text/Pandoc/Readers/Docx/Parse.hs+12−2 tests/Tests/Readers/Docx.hs+6−4 tests/docx.drop_cap.docx tests/docx.drop_cap.native+4
pandoc.cabal+1
@@ -177,6 +177,7 @@ Extra-Source-Files:
177177 tests/docx.codeblock.docx,
178178 tests/docx.deep_normalize.docx,
179179 tests/docx.definition_list.docx,
180+ tests/docx.drop_cap.docx,
180181 tests/docx.hanging_indent.docx,
181182 tests/docx.headers.docx,
182183 tests/docx.image.docx,
src/Text/Pandoc/Readers/Docx.hs+17−9
@@ -105,11 +105,15 @@ readDocx opts bytes =
105105 Left _ -> error $ "couldn't parse docx file"
106106
107107data DState = DState { docxAnchorMap :: M.Map String String
108− , docxMediaBag :: MediaBag }
108+ , docxMediaBag :: MediaBag
109+ , docxDropCap :: [Inline]
110+ }
109111
110112instance Default DState where
111113 def = DState { docxAnchorMap = M.empty
112− , docxMediaBag = mempty }
114+ , docxMediaBag = mempty
115+ , docxDropCap = []
116+ }
113117
114118data DEnv = DEnv { docxOptions :: ReaderOptions
115119 , docxInHeaderBlock :: Bool }
@@ -457,13 +461,17 @@ bodyPartToBlocks (Paragraph pPr parparts)
457461 return [hdr]
458462bodyPartToBlocks (Paragraph pPr parparts) = do
459463 ils <- parPartsToInlines parparts >>= (return . normalizeSpaces)
460− case ils of
461− [] -> return []
462− _ -> do
463− return $
464− rebuild
465− (parStyleToContainers pPr)
466− [Para ils]
464+ dropIls <- gets docxDropCap
465+ let ils' = reduceList $ dropIls ++ ils
466+ if dropCap pPr
467+ then do modify $ \s -> s { docxDropCap = ils' }
468+ return []
469+ else do modify $ \s -> s { docxDropCap = [] }
470+ return $ case ils' of
471+ [] -> []
472+ _ -> rebuild
473+ (parStyleToContainers pPr)
474+ [Para $ ils']
467475bodyPartToBlocks (ListItem pPr numId lvl levelInfo parparts) = do
468476 let
469477 kvs = case levelInfo of
src/Text/Pandoc/Readers/Docx/Parse.hs+12−2
@@ -146,12 +146,14 @@ data ParIndentation = ParIndentation { leftParIndent :: Maybe Integer
146146
147147data ParagraphStyle = ParagraphStyle { pStyle :: [String]
148148 , indentation :: Maybe ParIndentation
149+ , dropCap :: Bool
149150 }
150151 deriving Show
151152
152153defaultParagraphStyle :: ParagraphStyle
153154defaultParagraphStyle = ParagraphStyle { pStyle = []
154155 , indentation = Nothing
156+ , dropCap = False
155157 }
156158
157159
@@ -637,8 +639,16 @@ elemToParagraphStyle ns element
637639 (findAttr (elemName ns "w" "val"))
638640 (findChildren (elemName ns "w" "pStyle") pPr)
639641 , indentation =
640− findChild (elemName ns "w" "ind") pPr >>=
641− elemToParIndentation ns
642+ findChild (elemName ns "w" "ind") pPr >>=
643+ elemToParIndentation ns
644+ , dropCap =
645+ case
646+ findChild (elemName ns "w" "framePr") pPr >>=
647+ findAttr (elemName ns "w" "dropCap")
648+ of
649+ Just "none" -> False
650+ Just _ -> True
651+ Nothing -> False
642652 }
643653elemToParagraphStyle _ _ = defaultParagraphStyle
644654
tests/Tests/Readers/Docx.hs+6−4
@@ -82,14 +82,14 @@ compareMediaBagIO docxFile = do
8282 df <- B.readFile docxFile
8383 let (_, mb) = readDocx def df
8484 bools <- mapM
85− (\(fp, _, _) -> compareMediaPathIO fp mb docxFile)
85+ (\(fp, _, _) -> compareMediaPathIO fp mb docxFile)
8686 (mediaDirectory mb)
8787 return $ and bools
8888
8989testMediaBagIO :: String -> FilePath -> IO Test
9090testMediaBagIO name docxFile = do
9191 outcome <- compareMediaBagIO docxFile
92− return $ testCase name (assertBool
92+ return $ testCase name (assertBool
9393 ("Media didn't match media bag in file " ++ docxFile)
9494 outcome)
9595
@@ -176,7 +176,10 @@ tests = [ testGroup "inlines"
176176 "code block"
177177 "docx.codeblock.docx"
178178 "docx.codeblock.native"
179−
179+ , testCompare
180+ "dropcap paragraphs"
181+ "docx.drop_cap.docx"
182+ "docx.drop_cap.native"
180183 ]
181184 , testGroup "track changes"
182185 [ testCompare
@@ -229,4 +232,3 @@ tests = [ testGroup "inlines"
229232 ]
230233
231234 ]
232−
tests/docx.drop_cap.docxnew file

Binary file not shown.

tests/docx.drop_cap.nativenew file+4
@@ -0,0 +1,4 @@
1+[Para [Str "Drop",Space,Str "cap."]
2+,Para [Str "Next",Space,Str "paragraph."]
3+,Para [Str "Drop",Space,Str "cap",Space,Str "in",Space,Str "margin."]
4+,Para [Str "Drop",Space,Str "cap",Space,Str "(not",Space,Str "really)."]]