git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1522 from jkr/dropCap
4c88e64John MacFarlane
pandoc.cabal+1
@@ -177,6 +177,7 @@ Extra-Source-Files:
177 tests/docx.codeblock.docx,
177 tests/docx.codeblock.docx,
178 tests/docx.deep_normalize.docx,
178 tests/docx.deep_normalize.docx,
179 tests/docx.definition_list.docx,
179 tests/docx.definition_list.docx,
180+ tests/docx.drop_cap.docx,
180 tests/docx.hanging_indent.docx,
181 tests/docx.hanging_indent.docx,
181 tests/docx.headers.docx,
182 tests/docx.headers.docx,
182 tests/docx.image.docx,
183 tests/docx.image.docx,
src/Text/Pandoc/Readers/Docx.hs+17−9
@@ -105,11 +105,15 @@ readDocx opts bytes =
105 Left _ -> error $ "couldn't parse docx file"
105 Left _ -> error $ "couldn't parse docx file"
106
106
107data DState = DState { docxAnchorMap :: M.Map String String
107data DState = DState { docxAnchorMap :: M.Map String String
108− , docxMediaBag :: MediaBag }
108+ , docxMediaBag :: MediaBag
109+ , docxDropCap :: [Inline]
110+ }
109
111
110instance Default DState where
112instance Default DState where
111 def = DState { docxAnchorMap = M.empty
113 def = DState { docxAnchorMap = M.empty
112− , docxMediaBag = mempty }
114+ , docxMediaBag = mempty
115+ , docxDropCap = []
116+ }
113
117
114data DEnv = DEnv { docxOptions :: ReaderOptions
118data DEnv = DEnv { docxOptions :: ReaderOptions
115 , docxInHeaderBlock :: Bool }
119 , docxInHeaderBlock :: Bool }
@@ -457,13 +461,17 @@ bodyPartToBlocks (Paragraph pPr parparts)
457 return [hdr]
461 return [hdr]
458bodyPartToBlocks (Paragraph pPr parparts) = do
462bodyPartToBlocks (Paragraph pPr parparts) = do
459 ils <- parPartsToInlines parparts >>= (return . normalizeSpaces)
463 ils <- parPartsToInlines parparts >>= (return . normalizeSpaces)
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 = [] }
460− case ils of
470+ return $ case ils' of
461− [] -> return []
471+ [] -> []
462− _ -> do
463− return $
464− rebuild
472+ _ -> rebuild
465− (parStyleToContainers pPr)
473+ (parStyleToContainers pPr)
466− [Para ils]
474+ [Para $ ils']
467bodyPartToBlocks (ListItem pPr numId lvl levelInfo parparts) = do
475bodyPartToBlocks (ListItem pPr numId lvl levelInfo parparts) = do
468 let
476 let
469 kvs = case levelInfo of
477 kvs = case levelInfo of
src/Text/Pandoc/Readers/Docx/Parse.hs+12−2
@@ -146,12 +146,14 @@ data ParIndentation = ParIndentation { leftParIndent :: Maybe Integer
146
146
147data ParagraphStyle = ParagraphStyle { pStyle :: [String]
147data ParagraphStyle = ParagraphStyle { pStyle :: [String]
148 , indentation :: Maybe ParIndentation
148 , indentation :: Maybe ParIndentation
149+ , dropCap :: Bool
149 }
150 }
150 deriving Show
151 deriving Show
151
152
152defaultParagraphStyle :: ParagraphStyle
153defaultParagraphStyle :: ParagraphStyle
153defaultParagraphStyle = ParagraphStyle { pStyle = []
154defaultParagraphStyle = ParagraphStyle { pStyle = []
154 , indentation = Nothing
155 , indentation = Nothing
156+ , dropCap = False
155 }
157 }
156
158
157
159
@@ -637,8 +639,16 @@ elemToParagraphStyle ns element
637 (findAttr (elemName ns "w" "val"))
639 (findAttr (elemName ns "w" "val"))
638 (findChildren (elemName ns "w" "pStyle") pPr)
640 (findChildren (elemName ns "w" "pStyle") pPr)
639 , indentation =
641 , indentation =
640− findChild (elemName ns "w" "ind") pPr >>=
642+ findChild (elemName ns "w" "ind") pPr >>=
641− elemToParIndentation ns
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
642 }
652 }
643elemToParagraphStyle _ _ = defaultParagraphStyle
653elemToParagraphStyle _ _ = defaultParagraphStyle
644
654
tests/Tests/Readers/Docx.hs+6−4
@@ -82,14 +82,14 @@ compareMediaBagIO docxFile = do
82 df <- B.readFile docxFile
82 df <- B.readFile docxFile
83 let (_, mb) = readDocx def df
83 let (_, mb) = readDocx def df
84 bools <- mapM
84 bools <- mapM
85− (\(fp, _, _) -> compareMediaPathIO fp mb docxFile)
85+ (\(fp, _, _) -> compareMediaPathIO fp mb docxFile)
86 (mediaDirectory mb)
86 (mediaDirectory mb)
87 return $ and bools
87 return $ and bools
88
88
89testMediaBagIO :: String -> FilePath -> IO Test
89testMediaBagIO :: String -> FilePath -> IO Test
90testMediaBagIO name docxFile = do
90testMediaBagIO name docxFile = do
91 outcome <- compareMediaBagIO docxFile
91 outcome <- compareMediaBagIO docxFile
92− return $ testCase name (assertBool
92+ return $ testCase name (assertBool
93 ("Media didn't match media bag in file " ++ docxFile)
93 ("Media didn't match media bag in file " ++ docxFile)
94 outcome)
94 outcome)
95
95
@@ -176,7 +176,10 @@ tests = [ testGroup "inlines"
176 "code block"
176 "code block"
177 "docx.codeblock.docx"
177 "docx.codeblock.docx"
178 "docx.codeblock.native"
178 "docx.codeblock.native"
179−
179+ , testCompare
180+ "dropcap paragraphs"
181+ "docx.drop_cap.docx"
182+ "docx.drop_cap.native"
180 ]
183 ]
181 , testGroup "track changes"
184 , testGroup "track changes"
182 [ testCompare
185 [ testCompare
@@ -229,4 +232,3 @@ tests = [ testGroup "inlines"
229 ]
232 ]
230
233
231 ]
234 ]
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)."]]