summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-06-22 12:51:37 -0700
committerGitHub <noreply@github.com>2016-06-22 12:51:37 -0700
commit319a56aefcb58bf2b1f702367205f1df0b88ee5e (patch)
tree9a7c540ea6c8eed7124c836822c118a09e59788f /src
parentba7868765acae0071f684797771d83f9cc31b402 (diff)
parent7df656089f960b5c0f329776d6ebc0094b0fef30 (diff)
Merge pull request #2992 from tarleb/org-partial-functions
Org reader: remove partial functions
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Org/Blocks.hs6
-rw-r--r--src/Text/Pandoc/Readers/Org/Inlines.hs34
2 files changed, 21 insertions, 19 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs
index 75e564f2f..f8ff3f928 100644
--- a/src/Text/Pandoc/Readers/Org/Blocks.hs
+++ b/src/Text/Pandoc/Readers/Org/Blocks.hs
@@ -219,7 +219,7 @@ rawBlockContent blockType = try $ do
stripIndent strs = map (drop (shortestIndent strs)) strs
shortestIndent :: [String] -> Int
- shortestIndent = minimum
+ shortestIndent = foldr min maxBound
. map (length . takeWhile isSpace)
. filter (not . null)
@@ -727,7 +727,9 @@ normalizeTable (OrgTable aligns heads rows) = OrgTable aligns' heads rows
where
refRow = if heads /= mempty
then heads
- else if rows == mempty then mempty else head rows
+ else case rows of
+ (r:_) -> r
+ _ -> mempty
cols = length refRow
fillColumns base padding = take cols $ base ++ repeat padding
aligns' = fillColumns aligns AlignDefault
diff --git a/src/Text/Pandoc/Readers/Org/Inlines.hs b/src/Text/Pandoc/Readers/Org/Inlines.hs
index d0e007312..6a8773c3c 100644
--- a/src/Text/Pandoc/Readers/Org/Inlines.hs
+++ b/src/Text/Pandoc/Readers/Org/Inlines.hs
@@ -236,11 +236,15 @@ berkeleyCite = try $ do
prefix <- berkeleyCiteCommonPrefix <$> bcl
suffix <- berkeleyCiteCommonSuffix <$> bcl
citationList <- berkeleyCiteCitations <$> bcl
- if parens
- then return . toCite . addToFirstAndLast prefix suffix $ citationList
- else return $ maybe mempty (<> " ") prefix
- <> (toListOfCites $ map toInTextMode citationList)
- <> maybe mempty (", " <>) suffix
+ return $
+ if parens
+ then toCite
+ . maybe id (\p -> alterFirst (prependPrefix p)) prefix
+ . maybe id (\s -> alterLast (appendSuffix s)) suffix
+ $ citationList
+ else maybe mempty (<> " ") prefix
+ <> (toListOfCites $ map toInTextMode citationList)
+ <> maybe mempty (", " <>) suffix
where
toCite :: [Citation] -> Inlines
toCite cs = B.cite cs mempty
@@ -251,18 +255,14 @@ berkeleyCite = try $ do
toInTextMode :: Citation -> Citation
toInTextMode c = c { citationMode = AuthorInText }
- addToFirstAndLast :: Maybe Inlines -> Maybe Inlines -> [Citation] -> [Citation]
- addToFirstAndLast pre suf (c:cs) =
- let firstCite = maybe c
- (\p -> c { citationPrefix = B.toList p <> citationPrefix c })
- pre
- cites = firstCite:cs
- lc = last cites
- lastCite = maybe lc
- (\s -> lc { citationSuffix = B.toList s <> citationSuffix lc })
- suf
- in init cites ++ [lastCite]
- addToFirstAndLast _ _ _ = []
+ alterFirst, alterLast :: (a -> a) -> [a] -> [a]
+ alterFirst _ [] = []
+ alterFirst f (c:cs) = (f c):cs
+ alterLast f = reverse . alterFirst f . reverse
+
+ prependPrefix, appendSuffix :: Inlines -> Citation -> Citation
+ prependPrefix pre c = c { citationPrefix = B.toList pre <> citationPrefix c }
+ appendSuffix suf c = c { citationSuffix = citationSuffix c <> B.toList suf }
data BerkeleyCitationList = BerkeleyCitationList
{ berkeleyCiteParens :: Bool