git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #2992 from tarleb/org-partial-functions

Org reader: remove partial functions

commit319a56aefcb58bf2b1f702367205f1df0b88ee5e authorJohn MacFarlane <jgm@berkeley.edu> dateWed 22 Jun 2016, 12:51 (10 years ago) parentba786877df6560
2 files changed+21−19
src/Text/Pandoc/Readers/Org/Blocks.hs+4−2 src/Text/Pandoc/Readers/Org/Inlines.hs+17−17
src/Text/Pandoc/Readers/Org/Blocks.hs+4−2
@@ -219,7 +219,7 @@ rawBlockContent blockType = try $ do
219219 stripIndent strs = map (drop (shortestIndent strs)) strs
220220
221221 shortestIndent :: [String] -> Int
222− shortestIndent = minimum
222+ shortestIndent = foldr min maxBound
223223 . map (length . takeWhile isSpace)
224224 . filter (not . null)
225225
@@ -727,7 +727,9 @@ normalizeTable (OrgTable aligns heads rows) = OrgTable aligns' heads rows
727727 where
728728 refRow = if heads /= mempty
729729 then heads
730− else if rows == mempty then mempty else head rows
730+ else case rows of
731+ (r:_) -> r
732+ _ -> mempty
731733 cols = length refRow
732734 fillColumns base padding = take cols $ base ++ repeat padding
733735 aligns' = fillColumns aligns AlignDefault
src/Text/Pandoc/Readers/Org/Inlines.hs+17−17
@@ -236,11 +236,15 @@ berkeleyCite = try $ do
236236 prefix <- berkeleyCiteCommonPrefix <$> bcl
237237 suffix <- berkeleyCiteCommonSuffix <$> bcl
238238 citationList <- berkeleyCiteCitations <$> bcl
239− if parens
240− then return . toCite . addToFirstAndLast prefix suffix $ citationList
241− else return $ maybe mempty (<> " ") prefix
242− <> (toListOfCites $ map toInTextMode citationList)
243− <> maybe mempty (", " <>) suffix
239+ return $
240+ if parens
241+ then toCite
242+ . maybe id (\p -> alterFirst (prependPrefix p)) prefix
243+ . maybe id (\s -> alterLast (appendSuffix s)) suffix
244+ $ citationList
245+ else maybe mempty (<> " ") prefix
246+ <> (toListOfCites $ map toInTextMode citationList)
247+ <> maybe mempty (", " <>) suffix
244248 where
245249 toCite :: [Citation] -> Inlines
246250 toCite cs = B.cite cs mempty
@@ -251,18 +255,14 @@ berkeleyCite = try $ do
251255 toInTextMode :: Citation -> Citation
252256 toInTextMode c = c { citationMode = AuthorInText }
253257
254− addToFirstAndLast :: Maybe Inlines -> Maybe Inlines -> [Citation] -> [Citation]
255− addToFirstAndLast pre suf (c:cs) =
256− let firstCite = maybe c
257− (\p -> c { citationPrefix = B.toList p <> citationPrefix c })
258− pre
259− cites = firstCite:cs
260− lc = last cites
261− lastCite = maybe lc
262− (\s -> lc { citationSuffix = B.toList s <> citationSuffix lc })
263− suf
264− in init cites ++ [lastCite]
265− addToFirstAndLast _ _ _ = []
258+ alterFirst, alterLast :: (a -> a) -> [a] -> [a]
259+ alterFirst _ [] = []
260+ alterFirst f (c:cs) = (f c):cs
261+ alterLast f = reverse . alterFirst f . reverse
262+
263+ prependPrefix, appendSuffix :: Inlines -> Citation -> Citation
264+ prependPrefix pre c = c { citationPrefix = B.toList pre <> citationPrefix c }
265+ appendSuffix suf c = c { citationSuffix = citationSuffix c <> B.toList suf }
266266
267267data BerkeleyCitationList = BerkeleyCitationList
268268 { berkeleyCiteParens :: Bool