git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #2992 from tarleb/org-partial-functions
319a56aJohn MacFarlane
src/Text/Pandoc/Readers/Org/Blocks.hs+4−2
@@ -219,7 +219,7 @@ rawBlockContent blockType = try $ do
219 stripIndent strs = map (drop (shortestIndent strs)) strs
219 stripIndent strs = map (drop (shortestIndent strs)) strs
220
220
221 shortestIndent :: [String] -> Int
221 shortestIndent :: [String] -> Int
222− shortestIndent = minimum
222+ shortestIndent = foldr min maxBound
223 . map (length . takeWhile isSpace)
223 . map (length . takeWhile isSpace)
224 . filter (not . null)
224 . filter (not . null)
225
225
@@ -727,7 +727,9 @@ normalizeTable (OrgTable aligns heads rows) = OrgTable aligns' heads rows
727 where
727 where
728 refRow = if heads /= mempty
728 refRow = if heads /= mempty
729 then heads
729 then heads
730− else if rows == mempty then mempty else head rows
730+ else case rows of
731+ (r:_) -> r
732+ _ -> mempty
731 cols = length refRow
733 cols = length refRow
732 fillColumns base padding = take cols $ base ++ repeat padding
734 fillColumns base padding = take cols $ base ++ repeat padding
733 aligns' = fillColumns aligns AlignDefault
735 aligns' = fillColumns aligns AlignDefault
src/Text/Pandoc/Readers/Org/Inlines.hs+17−17
@@ -236,11 +236,15 @@ berkeleyCite = try $ do
236 prefix <- berkeleyCiteCommonPrefix <$> bcl
236 prefix <- berkeleyCiteCommonPrefix <$> bcl
237 suffix <- berkeleyCiteCommonSuffix <$> bcl
237 suffix <- berkeleyCiteCommonSuffix <$> bcl
238 citationList <- berkeleyCiteCitations <$> bcl
238 citationList <- berkeleyCiteCitations <$> bcl
239+ return $
239− if parens
240+ if parens
240− then return . toCite . addToFirstAndLast prefix suffix $ citationList
241+ then toCite
242+ . maybe id (\p -> alterFirst (prependPrefix p)) prefix
243+ . maybe id (\s -> alterLast (appendSuffix s)) suffix
244+ $ citationList
241− else return $ maybe mempty (<> " ") prefix
245+ else maybe mempty (<> " ") prefix
242− <> (toListOfCites $ map toInTextMode citationList)
246+ <> (toListOfCites $ map toInTextMode citationList)
243− <> maybe mempty (", " <>) suffix
247+ <> maybe mempty (", " <>) suffix
244 where
248 where
245 toCite :: [Citation] -> Inlines
249 toCite :: [Citation] -> Inlines
246 toCite cs = B.cite cs mempty
250 toCite cs = B.cite cs mempty
@@ -251,18 +255,14 @@ berkeleyCite = try $ do
251 toInTextMode :: Citation -> Citation
255 toInTextMode :: Citation -> Citation
252 toInTextMode c = c { citationMode = AuthorInText }
256 toInTextMode c = c { citationMode = AuthorInText }
253
257
254− addToFirstAndLast :: Maybe Inlines -> Maybe Inlines -> [Citation] -> [Citation]
258+ alterFirst, alterLast :: (a -> a) -> [a] -> [a]
255− addToFirstAndLast pre suf (c:cs) =
259+ alterFirst _ [] = []
256− let firstCite = maybe c
260+ alterFirst f (c:cs) = (f c):cs
257− (\p -> c { citationPrefix = B.toList p <> citationPrefix c })
261+ alterLast f = reverse . alterFirst f . reverse
258− pre
262+
259− cites = firstCite:cs
263+ prependPrefix, appendSuffix :: Inlines -> Citation -> Citation
260− lc = last cites
264+ prependPrefix pre c = c { citationPrefix = B.toList pre <> citationPrefix c }
261− lastCite = maybe lc
265+ appendSuffix suf c = c { citationSuffix = citationSuffix c <> B.toList suf }
262− (\s -> lc { citationSuffix = B.toList s <> citationSuffix lc })
263− suf
264− in init cites ++ [lastCite]
265− addToFirstAndLast _ _ _ = []
266
266
267data BerkeleyCitationList = BerkeleyCitationList
267data BerkeleyCitationList = BerkeleyCitationList
268 { berkeleyCiteParens :: Bool
268 { berkeleyCiteParens :: Bool