@@ -17,7 +17,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1717-}
1818{-# LANGUAGE FlexibleContexts #-}
1919{-# LANGUAGE RecordWildCards #-}
20−{-# LANGUAGE ViewPatterns #-}
2120{- |
2221 Module : Text.Pandoc.Readers.Org.Blocks
2322 Copyright : Copyright (C) 2014-2017 Albert Krewinkel
@@ -52,7 +51,7 @@ import Control.Monad (foldM, guard, mzero, void)
5251import Data.Char (isSpace, toLower, toUpper)
5352import Data.Default (Default)
5453import Data.List (foldl', isPrefixOf)
55−import Data.Maybe (fromMaybe, isNothing)
54+import Data.Maybe (fromMaybe, isJust, isNothing)
5655import Data.Monoid ((<>))
5756
5857--
@@ -113,7 +112,7 @@ data BlockAttributes = BlockAttributes
113112
114113-- | Convert BlockAttributes into pandoc Attr
115114attrFromBlockAttributes :: BlockAttributes -> Attr
116−attrFromBlockAttributes (BlockAttributes{..}) =
115+attrFromBlockAttributes BlockAttributes{..} =
117116 let
118117 ident = fromMaybe mempty $ lookup "id" blockAttrKeyValues
119118 classes = case lookup "class" blockAttrKeyValues of
@@ -142,7 +141,7 @@ blockAttributes = try $ do
142141 Nothing -> return Nothing
143142 Just s -> Just <$> parseFromString inlines (s ++ "\n")
144143 kvAttrs' <- parseFromString keyValues . (++ "\n") $ fromMaybe mempty kvAttrs
145− return $ BlockAttributes
144+ return BlockAttributes
146145 { blockAttrName = name
147146 , blockAttrLabel = label
148147 , blockAttrCaption = caption'
@@ -187,7 +186,7 @@ orgBlock = try $ do
187186 blockAttrs <- blockAttributes
188187 blkType <- blockHeaderStart
189188 ($ blkType) $
190− case (map toLower blkType) of
189+ case map toLower blkType of
191190 "export" -> exportBlock
192191 "comment" -> rawBlockLines (const mempty)
193192 "html" -> rawBlockLines (return . B.rawBlock (lowercase blkType))
@@ -208,10 +207,10 @@ orgBlock = try $ do
208207 lowercase = map toLower
209208
210209rawBlockLines :: Monad m => (String -> F Blocks) -> String -> OrgParser m (F Blocks)
211−rawBlockLines f blockType = (ignHeaders *> (f <$> rawBlockContent blockType))
210+rawBlockLines f blockType = ignHeaders *> (f <$> rawBlockContent blockType)
212211
213212parseBlockLines :: PandocMonad m => (F Blocks -> F Blocks) -> String -> OrgParser m (F Blocks)
214−parseBlockLines f blockType = (ignHeaders *> (f <$> parsedBlockContent))
213+parseBlockLines f blockType = ignHeaders *> (f <$> parsedBlockContent)
215214 where
216215 parsedBlockContent :: PandocMonad m => OrgParser m (F Blocks)
217216 parsedBlockContent = try $ do
@@ -239,8 +238,7 @@ rawBlockContent blockType = try $ do
239238 stripIndent strs = map (drop (shortestIndent strs)) strs
240239
241240 shortestIndent :: [String] -> Int
242− shortestIndent = foldr min maxBound
243− . map (length . takeWhile isSpace)
241+ shortestIndent = foldr (min . length . takeWhile isSpace) maxBound
244242 . filter (not . null)
245243
246244 tabsToSpaces :: Int -> String -> String
@@ -336,13 +334,13 @@ codeHeaderArgs = try $ do
336334 language <- skipSpaces *> orgArgWord
337335 (switchClasses, switchKv) <- switchesAsAttributes
338336 parameters <- manyTill blockOption newline
339− return $ ( translateLang language : switchClasses
340− , originalLang language <> switchKv <> parameters
341− )
337+ return ( translateLang language : switchClasses
338+ , originalLang language <> switchKv <> parameters
339+ )
342340
343341switchesAsAttributes :: Monad m => OrgParser m ([String], [(String, String)])
344342switchesAsAttributes = try $ do
345− switches <- skipSpaces *> (try $ switch `sepBy` (many1 spaceChar))
343+ switches <- skipSpaces *> try (switch `sepBy` many1 spaceChar)
346344 return $ foldr addToAttr ([], []) switches
347345 where
348346 addToAttr :: (Char, Maybe String, SwitchPolarity)
@@ -350,7 +348,7 @@ switchesAsAttributes = try $ do
350348 -> ([String], [(String, String)])
351349 addToAttr ('n', lineNum, pol) (cls, kv) =
352350 let kv' = case lineNum of
353− Just num -> (("startFrom", num):kv)
351+ Just num -> ("startFrom", num):kv
354352 Nothing -> kv
355353 cls' = case pol of
356354 SwitchPlus -> "continuedSourceBlock":cls
@@ -382,7 +380,7 @@ genericSwitch :: Monad m
382380genericSwitch c p = try $ do
383381 polarity <- switchPolarity <* char c <* skipSpaces
384382 arg <- optionMaybe p
385− return $ (c, arg, polarity)
383+ return (c, arg, polarity)
386384
387385-- | Reads a line number switch option. The line number switch can be used with
388386-- example and source blocks.
@@ -402,8 +400,8 @@ orgParamValue = try $
402400 *> noneOf "\n\r" `many1Till` endOfValue
403401 <* skipSpaces
404402 where
405− endOfValue = lookAhead $ (try $ skipSpaces <* oneOf "\n\r")
406− <|> (try $ skipSpaces1 <* orgArgKey)
403+ endOfValue = lookAhead $ try (skipSpaces <* oneOf "\n\r")
404+ <|> try (skipSpaces1 <* orgArgKey)
407405
408406
409407--
@@ -421,7 +419,7 @@ genericDrawer = try $ do
421419 -- Include drawer if it is explicitly included in or not explicitly excluded
422420 -- from the list of drawers that should be exported. PROPERTIES drawers are
423421 -- never exported.
424− case (exportDrawers . orgStateExportSettings $ state) of
422+ case exportDrawers . orgStateExportSettings $ state of
425423 _ | name == "PROPERTIES" -> return mempty
426424 Left names | name `elem` names -> return mempty
427425 Right names | name `notElem` names -> return mempty
@@ -455,7 +453,7 @@ figure = try $ do
455453 Nothing -> mzero
456454 Just imgSrc -> do
457455 guard (isImageFilename imgSrc)
458− let isFigure = not . isNothing $ blockAttrCaption figAttrs
456+ let isFigure = isJust $ blockAttrCaption figAttrs
459457 return $ imageBlock isFigure figAttrs imgSrc
460458 where
461459 selfTarget :: PandocMonad m => OrgParser m String
@@ -490,8 +488,7 @@ endOfParagraph = try $ skipSpaces *> newline *> endOfBlock
490488
491489-- | Example code marked up by a leading colon.
492490example :: Monad m => OrgParser m (F Blocks)
493−example = try $ do
494− returnF . exampleCode =<< unlines <$> many1 exampleLine
491+example = try $ returnF . exampleCode =<< unlines <$> many1 exampleLine
495492 where
496493 exampleLine :: Monad m => OrgParser m String
497494 exampleLine = try $ exampleLineStart *> anyLine
@@ -514,7 +511,7 @@ include = try $ do
514511 filename <- includeTarget
515512 blockType <- optionMaybe $ skipSpaces *> many1 alphaNum
516513 blocksParser <- case blockType of
517− Just "example" -> do
514+ Just "example" ->
518515 return $ pure . B.codeBlock <$> parseRaw
519516 Just "export" -> do
520517 format <- skipSpaces *> many (noneOf "\n\r\t ")
@@ -580,8 +577,8 @@ orgTable :: PandocMonad m => OrgParser m (F Blocks)
580577orgTable = try $ do
581578 -- don't allow a table on the first line of a list item; org requires that
582579 -- tables start at first non-space character on the line
583− let isFirstInListItem st = (orgStateParserContext st == ListItemState) &&
584− (orgStateLastPreCharPos st == Nothing)
580+ let isFirstInListItem st = orgStateParserContext st == ListItemState &&
581+ isNothing (orgStateLastPreCharPos st)
585582 guard =<< not . isFirstInListItem <$> getState
586583 blockAttrs <- blockAttributes
587584 lookAhead tableStart
@@ -594,7 +591,7 @@ orgToPandocTable :: OrgTable
594591 -> Inlines
595592 -> Blocks
596593orgToPandocTable (OrgTable colProps heads lns) caption =
597− let totalWidth = if any (not . isNothing) (map columnRelWidth colProps)
594+ let totalWidth = if any isJust (map columnRelWidth colProps)
598595 then Just . sum $ map (fromMaybe 1 . columnRelWidth) colProps
599596 else Nothing
600597 in B.table caption (map (convertColProp totalWidth) colProps) heads lns
@@ -604,7 +601,7 @@ orgToPandocTable (OrgTable colProps heads lns) caption =
604601 let
605602 align' = fromMaybe AlignDefault $ columnAlignment colProp
606603 width' = fromMaybe 0 $ (\w t -> (fromIntegral w / fromIntegral t))
607− <$> (columnRelWidth colProp)
604+ <$> columnRelWidth colProp
608605 <*> totalWidth
609606 in (align', width')
610607
@@ -630,7 +627,7 @@ tableAlignRow = try $ do
630627columnPropertyCell :: Monad m => OrgParser m ColumnProperty
631628columnPropertyCell = emptyCell <|> propCell <?> "alignment info"
632629 where
633− emptyCell = ColumnProperty Nothing Nothing <$ (try $ skipSpaces *> endOfCell)
630+ emptyCell = ColumnProperty Nothing Nothing <$ try (skipSpaces *> endOfCell)
634631 propCell = try $ ColumnProperty
635632 <$> (skipSpaces
636633 *> char '<'
@@ -684,7 +681,7 @@ rowToContent tbl row =
684681 where
685682 singleRowPromotedToHeader :: OrgTable
686683 singleRowPromotedToHeader = case tbl of
687− OrgTable{ orgTableHeader = [], orgTableRows = b:[] } ->
684+ OrgTable{ orgTableHeader = [], orgTableRows = [b] } ->
688685 tbl{ orgTableHeader = b , orgTableRows = [] }
689686 _ -> tbl
690687
@@ -739,7 +736,7 @@ noteBlock = try $ do
739736paraOrPlain :: PandocMonad m => OrgParser m (F Blocks)
740737paraOrPlain = try $ do
741738 -- Make sure we are not looking at a headline
742− notFollowedBy' (char '*' *> (oneOf " *"))
739+ notFollowedBy' (char '*' *> oneOf " *")
743740 ils <- inlines
744741 nl <- option False (newline *> return True)
745742 -- Read block as paragraph, except if we are in a list context and the block
@@ -748,7 +745,7 @@ paraOrPlain = try $ do
748745 try (guard nl
749746 *> notFollowedBy (inList *> (() <$ orderedListStart <|> bulletListStart))
750747 *> return (B.para <$> ils))
751− <|> (return (B.plain <$> ils))
748+ <|> return (B.plain <$> ils)
752749
753750
754751--
@@ -760,16 +757,16 @@ list = choice [ definitionList, bulletList, orderedList ] <?> "list"
760757
761758definitionList :: PandocMonad m => OrgParser m (F Blocks)
762759definitionList = try $ do n <- lookAhead (bulletListStart' Nothing)
763− fmap B.definitionList . fmap compactifyDL . sequence
760+ fmap (B.definitionList . compactifyDL) . sequence
764761 <$> many1 (definitionListItem $ bulletListStart' (Just n))
765762
766763bulletList :: PandocMonad m => OrgParser m (F Blocks)
767764bulletList = try $ do n <- lookAhead (bulletListStart' Nothing)
768− fmap B.bulletList . fmap compactify . sequence
765+ fmap (B.bulletList . compactify) . sequence
769766 <$> many1 (listItem (bulletListStart' $ Just n))
770767
771768orderedList :: PandocMonad m => OrgParser m (F Blocks)
772−orderedList = fmap B.orderedList . fmap compactify . sequence
769+orderedList = fmap (B.orderedList . compactify) . sequence
773770 <$> many1 (listItem orderedListStart)
774771
775772bulletListStart' :: Monad m => Maybe Int -> OrgParser m Int