git.iko.soy/typeable/pandoc
on master help sign in
Org reader: apply hlint suggestions
commitd55f01c65f0a149b0951d4350293622385cceae9 authorAlbert Krewinkel <albert@zeitkraut.de> dateFri 2 Jun 2017, 23:54 (9 years ago) parentb61a51e
7 files changed+84−89
src/Text/Pandoc/Readers/Org/BlockStarts.hs+4−5 src/Text/Pandoc/Readers/Org/Blocks.hs+30−33 src/Text/Pandoc/Readers/Org/DocumentTree.hs+12−13 src/Text/Pandoc/Readers/Org/Inlines.hs+33−31 src/Text/Pandoc/Readers/Org/Meta.hs+4−5 src/Text/Pandoc/Readers/Org/ParserState.hs−1 src/Text/Pandoc/Readers/Org/Shared.hs+1−1
src/Text/Pandoc/Readers/Org/BlockStarts.hs+4−5
@@ -66,7 +66,7 @@ gridTableStart = try $ skipSpaces <* char '+' <* char '-'
6666
6767
6868latexEnvStart :: Monad m => OrgParser m String
69−latexEnvStart = try $ do
69+latexEnvStart = try $
7070 skipSpaces *> string "\\begin{"
7171 *> latexEnvName
7272 <* string "}"
@@ -97,8 +97,7 @@ orderedListStart = genericListStart orderedListMarker
9797 where orderedListMarker = mappend <$> many1 digit <*> (pure <$> oneOf ".)")
9898
9999drawerStart :: Monad m => OrgParser m String
100−drawerStart = try $
101− skipSpaces *> drawerName <* skipSpaces <* newline
100+drawerStart = try $ skipSpaces *> drawerName <* skipSpaces <* newline
102101 where drawerName = char ':' *> manyTill nonspaceChar (char ':')
103102
104103metaLineStart :: Monad m => OrgParser m ()
@@ -120,8 +119,8 @@ noteMarker = try $ do
120119
121120-- | Succeeds if the parser is at the end of a block.
122121endOfBlock :: Monad m => OrgParser m ()
123−endOfBlock = lookAhead . try $ do
124− void blankline <|> anyBlockStart
122+endOfBlock = lookAhead . try $
123+ void blankline <|> anyBlockStart
125124 where
126125 -- Succeeds if there is a new block starting at this position.
127126 anyBlockStart :: Monad m => OrgParser m ()
src/Text/Pandoc/Readers/Org/Blocks.hs+30−33
@@ -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
src/Text/Pandoc/Readers/Org/DocumentTree.hs+12−13
@@ -32,10 +32,10 @@ module Text.Pandoc.Readers.Org.DocumentTree
3232 , headlineToBlocks
3333 ) where
3434
35+import Control.Arrow ((***))
3536import Control.Monad (guard, void)
3637import Data.Char (toLower, toUpper)
3738import Data.List ( intersperse )
38−import Data.Maybe (fromMaybe)
3939import Data.Monoid ((<>))
4040import Text.Pandoc.Builder (Blocks, Inlines)
4141import Text.Pandoc.Class (PandocMonad)
@@ -142,7 +142,7 @@ headline blocks inline lvl = try $ do
142142 title' <- title
143143 contents' <- contents
144144 children' <- sequence children
145− return $ Headline
145+ return Headline
146146 { headlineLevel = level
147147 , headlineTodoMarker = todoKw
148148 , headlineText = title'
@@ -162,7 +162,7 @@ headline blocks inline lvl = try $ do
162162
163163-- | Convert an Org mode headline (i.e. a document tree) into pandoc's Blocks
164164headlineToBlocks :: Monad m => Headline -> OrgParser m Blocks
165−headlineToBlocks hdln@(Headline {..}) = do
165+headlineToBlocks hdln@Headline {..} = do
166166 maxHeadlineLevels <- getExportSetting exportHeadlineLevels
167167 case () of
168168 _ | any isNoExportTag headlineTags -> return mempty
@@ -193,7 +193,7 @@ archivedHeadlineToBlocks hdln = do
193193 ArchivedTreesHeadlineOnly -> headlineToHeader hdln
194194
195195headlineToHeaderWithList :: Monad m => Headline -> OrgParser m Blocks
196−headlineToHeaderWithList hdln@(Headline {..}) = do
196+headlineToHeaderWithList hdln@Headline {..} = do
197197 maxHeadlineLevels <- getExportSetting exportHeadlineLevels
198198 header <- headlineToHeader hdln
199199 listElements <- mapM headlineToBlocks headlineChildren
@@ -212,13 +212,13 @@ headlineToHeaderWithList hdln@(Headline {..}) = do
212212 _ -> mempty
213213
214214headlineToHeaderWithContents :: Monad m => Headline -> OrgParser m Blocks
215−headlineToHeaderWithContents hdln@(Headline {..}) = do
215+headlineToHeaderWithContents hdln@Headline {..} = do
216216 header <- headlineToHeader hdln
217217 childrenBlocks <- mconcat <$> mapM headlineToBlocks headlineChildren
218218 return $ header <> headlineContents <> childrenBlocks
219219
220220headlineToHeader :: Monad m => Headline -> OrgParser m Blocks
221−headlineToHeader (Headline {..}) = do
221+headlineToHeader Headline {..} = do
222222 exportTodoKeyword <- getExportSetting exportWithTodoKeywords
223223 exportTags <- getExportSetting exportWithTags
224224 let todoText = if exportTodoKeyword
@@ -237,7 +237,7 @@ headlineToHeader (Headline {..}) = do
237237todoKeyword :: Monad m => OrgParser m TodoMarker
238238todoKeyword = try $ do
239239 taskStates <- activeTodoMarkers <$> getState
240− let kwParser tdm = try $ (tdm <$ string (todoMarkerName tdm) <* spaceChar)
240+ let kwParser tdm = try (tdm <$ string (todoMarkerName tdm) <* spaceChar)
241241 choice (map kwParser taskStates)
242242
243243todoKeywordToInlines :: TodoMarker -> Inlines
@@ -250,19 +250,19 @@ todoKeywordToInlines tdm =
250250propertiesToAttr :: Properties -> Attr
251251propertiesToAttr properties =
252252 let
253− toStringPair prop = (fromKey (fst prop), fromValue (snd prop))
253+ toStringPair = fromKey *** fromValue
254254 customIdKey = toPropertyKey "custom_id"
255255 classKey = toPropertyKey "class"
256256 unnumberedKey = toPropertyKey "unnumbered"
257257 specialProperties = [customIdKey, classKey, unnumberedKey]
258− id' = fromMaybe mempty . fmap fromValue . lookup customIdKey $ properties
259− cls = fromMaybe mempty . fmap fromValue . lookup classKey $ properties
258+ id' = maybe mempty fromValue . lookup customIdKey $ properties
259+ cls = maybe mempty fromValue . lookup classKey $ properties
260260 kvs' = map toStringPair . filter ((`notElem` specialProperties) . fst)
261261 $ properties
262262 isUnnumbered =
263− fromMaybe False . fmap isNonNil . lookup unnumberedKey $ properties
263+ maybe False isNonNil . lookup unnumberedKey $ properties
264264 in
265− (id', words cls ++ (if isUnnumbered then ["unnumbered"] else []), kvs')
265+ (id', words cls ++ ["unnumbered" | isUnnumbered], kvs')
266266
267267tagsToInlines :: [Tag] -> Inlines
268268tagsToInlines [] = mempty
@@ -302,4 +302,3 @@ propertiesDrawer = try $ do
302302 endOfDrawer :: Monad m => OrgParser m String
303303 endOfDrawer = try $
304304 skipSpaces *> stringAnyCase ":END:" <* skipSpaces <* newline
305−
src/Text/Pandoc/Readers/Org/Inlines.hs+33−31
@@ -48,7 +48,7 @@ import Text.Pandoc.Readers.LaTeX (inlineCommand, rawLaTeXInline)
4848import Text.TeXMath (DisplayType (..), readTeX, writePandoc)
4949import qualified Text.TeXMath.Readers.MathML.EntityMap as MathMLEntityMap
5050
51−import Control.Monad (guard, mplus, mzero, void, when)
51+import Control.Monad (guard, mplus, mzero, unless, void, when)
5252import Control.Monad.Trans (lift)
5353import Data.Char (isAlphaNum, isSpace)
5454import Data.List (intersperse)
@@ -63,7 +63,7 @@ import Prelude hiding (sequence)
6363--
6464recordAnchorId :: PandocMonad m => String -> OrgParser m ()
6565recordAnchorId i = updateState $ \s ->
66− s{ orgStateAnchorIds = i : (orgStateAnchorIds s) }
66+ s{ orgStateAnchorIds = i : orgStateAnchorIds s }
6767
6868pushToInlineCharStack :: PandocMonad m => Char -> OrgParser m ()
6969pushToInlineCharStack c = updateState $ \s ->
@@ -184,7 +184,7 @@ cite = try $ berkeleyCite <|> do
184184 , orgRefCite
185185 , berkeleyTextualCite
186186 ]
187− return $ (flip B.cite (B.text raw)) <$> cs
187+ return $ flip B.cite (B.text raw) <$> cs
188188
189189-- | A citation in Pandoc Org-mode style (@[prefix \@citekey suffix]@).
190190pandocOrgCite :: PandocMonad m => OrgParser m (F [Citation])
@@ -209,7 +209,7 @@ normalOrgRefCite = try $ do
209209 orgRefCiteList :: PandocMonad m => CitationMode -> OrgParser m (F Citation)
210210 orgRefCiteList citeMode = try $ do
211211 key <- orgRefCiteKey
212− returnF $ Citation
212+ returnF Citation
213213 { citationId = key
214214 , citationPrefix = mempty
215215 , citationSuffix = mempty
@@ -232,11 +232,11 @@ berkeleyCite = try $ do
232232 return $
233233 if parens
234234 then toCite
235− . maybe id (\p -> alterFirst (prependPrefix p)) prefix
236− . maybe id (\s -> alterLast (appendSuffix s)) suffix
235+ . maybe id (alterFirst . prependPrefix) prefix
236+ . maybe id (alterLast . appendSuffix) suffix
237237 $ citationList
238238 else maybe mempty (<> " ") prefix
239− <> (toListOfCites $ map toInTextMode citationList)
239+ <> toListOfCites (map toInTextMode citationList)
240240 <> maybe mempty (", " <>) suffix
241241 where
242242 toCite :: [Citation] -> Inlines
@@ -250,7 +250,7 @@ berkeleyCite = try $ do
250250
251251 alterFirst, alterLast :: (a -> a) -> [a] -> [a]
252252 alterFirst _ [] = []
253− alterFirst f (c:cs) = (f c):cs
253+ alterFirst f (c:cs) = f c : cs
254254 alterLast f = reverse . alterFirst f . reverse
255255
256256 prependPrefix, appendSuffix :: Inlines -> Citation -> Citation
@@ -271,7 +271,7 @@ berkeleyCitationList = try $ do
271271 skipSpaces
272272 commonPrefix <- optionMaybe (try $ citationListPart <* char ';')
273273 citations <- citeList
274− commonSuffix <- optionMaybe (try $ citationListPart)
274+ commonSuffix <- optionMaybe (try citationListPart)
275275 char ']'
276276 return (BerkeleyCitationList parens
277277 <$> sequence commonPrefix
@@ -344,7 +344,7 @@ orgRefCiteKey =
344344 isCiteKeySpecialChar c = c `elem` citeKeySpecialChars
345345 isCiteKeyChar c = isAlphaNum c || isCiteKeySpecialChar c
346346
347− in try $ many1Till (satisfy $ isCiteKeyChar)
347+ in try $ many1Till (satisfy isCiteKeyChar)
348348 $ try . lookAhead $ do
349349 many . satisfy $ isCiteKeySpecialChar
350350 satisfy $ not . isCiteKeyChar
@@ -374,15 +374,16 @@ citation = try $ do
374374 return $ do
375375 x <- pref
376376 y <- suff
377− return $ Citation{ citationId = key
378− , citationPrefix = B.toList x
379− , citationSuffix = B.toList y
380− , citationMode = if suppress_author
381− then SuppressAuthor
382− else NormalCitation
383− , citationNoteNum = 0
384− , citationHash = 0
385− }
377+ return Citation
378+ { citationId = key
379+ , citationPrefix = B.toList x
380+ , citationSuffix = B.toList y
381+ , citationMode = if suppress_author
382+ then SuppressAuthor
383+ else NormalCitation
384+ , citationNoteNum = 0
385+ , citationHash = 0
386+ }
386387 where
387388 prefix = trimInlinesF . mconcat <$>
388389 manyTill inline (char ']' <|> (']' <$ lookAhead citeKey))
@@ -404,7 +405,7 @@ inlineNote = try $ do
404405 ref <- many alphaNum
405406 char ':'
406407 note <- fmap B.para . trimInlinesF . mconcat <$> many1Till inline (char ']')
407− when (not $ null ref) $
408+ unless (null ref) $
408409 addToNotesTable ("fn:" ++ ref, note)
409410 return $ B.note <$> note
410411
@@ -780,7 +781,7 @@ notAfterForbiddenBorderChar = do
780781-- | Read a sub- or superscript expression
781782subOrSuperExpr :: PandocMonad m => OrgParser m (F Inlines)
782783subOrSuperExpr = try $
783− choice [ id <$> charsInBalanced '{' '}' (noneOf "\n\r")
784+ choice [ charsInBalanced '{' '}' (noneOf "\n\r")
784785 , enclosing ('(', ')') <$> charsInBalanced '(' ')' (noneOf "\n\r")
785786 , simpleSubOrSuperString
786787 ] >>= parseFromString (mconcat <$> many inline)
@@ -818,7 +819,7 @@ inlineLaTeX = try $ do
818819 enableExtension Ext_raw_tex (readerExtensions def) } }
819820
820821 texMathToPandoc :: String -> Maybe [Inline]
821− texMathToPandoc cs = (maybeRight $ readTeX cs) >>= writePandoc DisplayInline
822+ texMathToPandoc cs = maybeRight (readTeX cs) >>= writePandoc DisplayInline
822823
823824maybeRight :: Either a b -> Maybe b
824825maybeRight = either (const Nothing) Just
@@ -869,21 +870,19 @@ macro = try $ do
869870 eoa = string ")}}}"
870871
871872smart :: PandocMonad m => OrgParser m (F Inlines)
872−smart = do
873− doubleQuoted <|> singleQuoted <|>
874− choice (map (return <$>) [orgApostrophe, orgDash, orgEllipses])
873+smart = choice [doubleQuoted, singleQuoted, orgApostrophe, orgDash, orgEllipses]
875874 where
876875 orgDash = do
877876 guardOrSmartEnabled =<< getExportSetting exportSpecialStrings
878− dash <* updatePositions '-'
877+ pure <$> dash <* updatePositions '-'
879878 orgEllipses = do
880879 guardOrSmartEnabled =<< getExportSetting exportSpecialStrings
881− ellipses <* updatePositions '.'
880+ pure <$> ellipses <* updatePositions '.'
882881 orgApostrophe = do
883882 guardEnabled Ext_smart
884883 (char '\'' <|> char '\8217') <* updateLastPreCharPos
885884 <* updateLastForbiddenCharPos
886− return (B.str "\x2019")
885+ returnF (B.str "\x2019")
887886
888887guardOrSmartEnabled :: PandocMonad m => Bool -> OrgParser m ()
889888guardOrSmartEnabled b = do
@@ -908,6 +907,9 @@ doubleQuoted = try $ do
908907 doubleQuoteStart
909908 updatePositions '"'
910909 contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
911− (withQuoteContext InDoubleQuote $ (doubleQuoteEnd <* updateLastForbiddenCharPos) >> return
912− (fmap B.doubleQuoted . trimInlinesF $ contents))
913− <|> (return $ return (B.str "\8220") <> contents)
910+ let doubleQuotedContent = withQuoteContext InDoubleQuote $ do
911+ doubleQuoteEnd
912+ updateLastForbiddenCharPos
913+ return . fmap B.doubleQuoted . trimInlinesF $ contents
914+ let leftQuoteAndContent = return $ pure (B.str "\8220") <> contents
915+ doubleQuotedContent <|> leftQuoteAndContent
src/Text/Pandoc/Readers/Org/Meta.hs+4−5
@@ -84,7 +84,7 @@ metaKey = map toLower <$> many1 (noneOf ": \n\r")
8484 <* char ':'
8585 <* skipSpaces
8686
87−metaValue :: PandocMonad m => String -> OrgParser m (String, (F MetaValue))
87+metaValue :: PandocMonad m => String -> OrgParser m (String, F MetaValue)
8888metaValue key =
8989 let inclKey = "header-includes"
9090 in case key of
@@ -111,7 +111,7 @@ metaInlines = fmap (MetaInlines . B.toList) <$> inlinesTillNewline
111111
112112metaInlinesCommaSeparated :: PandocMonad m => OrgParser m (F MetaValue)
113113metaInlinesCommaSeparated = do
114− itemStrs <- (many1 (noneOf ",\n")) `sepBy1` (char ',')
114+ itemStrs <- many1 (noneOf ",\n") `sepBy1` char ','
115115 newline
116116 items <- mapM (parseFromString inlinesTillNewline . (++ "\n")) itemStrs
117117 let toMetaInlines = MetaInlines . B.toList
@@ -163,7 +163,7 @@ addLinkFormat key formatter = updateState $ \s ->
163163 let fs = orgStateLinkFormatters s
164164 in s{ orgStateLinkFormatters = M.insert key formatter fs }
165165
166−parseLinkFormat :: Monad m => OrgParser m ((String, String -> String))
166+parseLinkFormat :: Monad m => OrgParser m (String, String -> String)
167167parseLinkFormat = try $ do
168168 linkType <- (:) <$> letter <*> many (alphaNum <|> oneOf "-_") <* skipSpaces
169169 linkSubst <- parseFormat
@@ -172,8 +172,7 @@ parseLinkFormat = try $ do
172172-- | An ad-hoc, single-argument-only implementation of a printf-style format
173173-- parser.
174174parseFormat :: Monad m => OrgParser m (String -> String)
175−parseFormat = try $ do
176− replacePlain <|> replaceUrl <|> justAppend
175+parseFormat = try $ replacePlain <|> replaceUrl <|> justAppend
177176 where
178177 -- inefficient, but who cares
179178 replacePlain = try $ (\x -> concat . flip intersperse x)
src/Text/Pandoc/Readers/Org/ParserState.hs−1
@@ -1,5 +1,4 @@
11{-# LANGUAGE FlexibleInstances #-}
2−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
32{-# LANGUAGE MultiParamTypeClasses #-}
43{-
54Copyright (C) 2014-2017 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
src/Text/Pandoc/Readers/Org/Shared.hs+1−1
@@ -56,7 +56,7 @@ cleanLinkString s =
5656 '.':'/':_ -> Just s -- relative path
5757 '.':'.':'/':_ -> Just s -- relative path
5858 -- Relative path or URL (file schema)
59− 'f':'i':'l':'e':':':s' -> Just $ if ("//" `isPrefixOf` s') then s else s'
59+ 'f':'i':'l':'e':':':s' -> Just $ if "//" `isPrefixOf` s' then s else s'
6060 _ | isUrl s -> Just s -- URL
6161 _ -> Nothing
6262 where