git.iko.soy/typeable/pandoc
on master help sign in
Org reader: apply hlint suggestions
d55f01cAlbert Krewinkel
src/Text/Pandoc/Readers/Org/BlockStarts.hs+4−5
@@ -66,7 +66,7 @@ gridTableStart = try $ skipSpaces <* char '+' <* char '-'
66
66
67
67
68latexEnvStart :: Monad m => OrgParser m String
68latexEnvStart :: Monad m => OrgParser m String
69−latexEnvStart = try $ do
69+latexEnvStart = try $
70 skipSpaces *> string "\\begin{"
70 skipSpaces *> string "\\begin{"
71 *> latexEnvName
71 *> latexEnvName
72 <* string "}"
72 <* string "}"
@@ -97,8 +97,7 @@ orderedListStart = genericListStart orderedListMarker
97 where orderedListMarker = mappend <$> many1 digit <*> (pure <$> oneOf ".)")
97 where orderedListMarker = mappend <$> many1 digit <*> (pure <$> oneOf ".)")
98
98
99drawerStart :: Monad m => OrgParser m String
99drawerStart :: Monad m => OrgParser m String
100−drawerStart = try $
101− skipSpaces *> drawerName <* skipSpaces <* newline
100+drawerStart = try $ skipSpaces *> drawerName <* skipSpaces <* newline
102 where drawerName = char ':' *> manyTill nonspaceChar (char ':')
101 where drawerName = char ':' *> manyTill nonspaceChar (char ':')
103
102
104metaLineStart :: Monad m => OrgParser m ()
103metaLineStart :: Monad m => OrgParser m ()
@@ -120,8 +119,8 @@ noteMarker = try $ do
120
119
121-- | Succeeds if the parser is at the end of a block.
120-- | Succeeds if the parser is at the end of a block.
122endOfBlock :: Monad m => OrgParser m ()
121endOfBlock :: Monad m => OrgParser m ()
123−endOfBlock = lookAhead . try $ do
122+endOfBlock = lookAhead . try $
124− void blankline <|> anyBlockStart
123+ void blankline <|> anyBlockStart
125 where
124 where
126 -- Succeeds if there is a new block starting at this position.
125 -- Succeeds if there is a new block starting at this position.
127 anyBlockStart :: Monad m => OrgParser m ()
126 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
17-}
17-}
18{-# LANGUAGE FlexibleContexts #-}
18{-# LANGUAGE FlexibleContexts #-}
19{-# LANGUAGE RecordWildCards #-}
19{-# LANGUAGE RecordWildCards #-}
20−{-# LANGUAGE ViewPatterns #-}
21{- |
20{- |
22 Module : Text.Pandoc.Readers.Org.Blocks
21 Module : Text.Pandoc.Readers.Org.Blocks
23 Copyright : Copyright (C) 2014-2017 Albert Krewinkel
22 Copyright : Copyright (C) 2014-2017 Albert Krewinkel
@@ -52,7 +51,7 @@ import Control.Monad (foldM, guard, mzero, void)
52import Data.Char (isSpace, toLower, toUpper)
51import Data.Char (isSpace, toLower, toUpper)
53import Data.Default (Default)
52import Data.Default (Default)
54import Data.List (foldl', isPrefixOf)
53import Data.List (foldl', isPrefixOf)
55−import Data.Maybe (fromMaybe, isNothing)
54+import Data.Maybe (fromMaybe, isJust, isNothing)
56import Data.Monoid ((<>))
55import Data.Monoid ((<>))
57
56
58--
57--
@@ -113,7 +112,7 @@ data BlockAttributes = BlockAttributes
113
112
114-- | Convert BlockAttributes into pandoc Attr
113-- | Convert BlockAttributes into pandoc Attr
115attrFromBlockAttributes :: BlockAttributes -> Attr
114attrFromBlockAttributes :: BlockAttributes -> Attr
116−attrFromBlockAttributes (BlockAttributes{..}) =
115+attrFromBlockAttributes BlockAttributes{..} =
117 let
116 let
118 ident = fromMaybe mempty $ lookup "id" blockAttrKeyValues
117 ident = fromMaybe mempty $ lookup "id" blockAttrKeyValues
119 classes = case lookup "class" blockAttrKeyValues of
118 classes = case lookup "class" blockAttrKeyValues of
@@ -142,7 +141,7 @@ blockAttributes = try $ do
142 Nothing -> return Nothing
141 Nothing -> return Nothing
143 Just s -> Just <$> parseFromString inlines (s ++ "\n")
142 Just s -> Just <$> parseFromString inlines (s ++ "\n")
144 kvAttrs' <- parseFromString keyValues . (++ "\n") $ fromMaybe mempty kvAttrs
143 kvAttrs' <- parseFromString keyValues . (++ "\n") $ fromMaybe mempty kvAttrs
145− return $ BlockAttributes
144+ return BlockAttributes
146 { blockAttrName = name
145 { blockAttrName = name
147 , blockAttrLabel = label
146 , blockAttrLabel = label
148 , blockAttrCaption = caption'
147 , blockAttrCaption = caption'
@@ -187,7 +186,7 @@ orgBlock = try $ do
187 blockAttrs <- blockAttributes
186 blockAttrs <- blockAttributes
188 blkType <- blockHeaderStart
187 blkType <- blockHeaderStart
189 ($ blkType) $
188 ($ blkType) $
190− case (map toLower blkType) of
189+ case map toLower blkType of
191 "export" -> exportBlock
190 "export" -> exportBlock
192 "comment" -> rawBlockLines (const mempty)
191 "comment" -> rawBlockLines (const mempty)
193 "html" -> rawBlockLines (return . B.rawBlock (lowercase blkType))
192 "html" -> rawBlockLines (return . B.rawBlock (lowercase blkType))
@@ -208,10 +207,10 @@ orgBlock = try $ do
208 lowercase = map toLower
207 lowercase = map toLower
209
208
210rawBlockLines :: Monad m => (String -> F Blocks) -> String -> OrgParser m (F Blocks)
209rawBlockLines :: 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)
212
211
213parseBlockLines :: PandocMonad m => (F Blocks -> F Blocks) -> String -> OrgParser m (F Blocks)
212parseBlockLines :: 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)
215 where
214 where
216 parsedBlockContent :: PandocMonad m => OrgParser m (F Blocks)
215 parsedBlockContent :: PandocMonad m => OrgParser m (F Blocks)
217 parsedBlockContent = try $ do
216 parsedBlockContent = try $ do
@@ -239,8 +238,7 @@ rawBlockContent blockType = try $ do
239 stripIndent strs = map (drop (shortestIndent strs)) strs
238 stripIndent strs = map (drop (shortestIndent strs)) strs
240
239
241 shortestIndent :: [String] -> Int
240 shortestIndent :: [String] -> Int
242− shortestIndent = foldr min maxBound
243− . map (length . takeWhile isSpace)
241+ shortestIndent = foldr (min . length . takeWhile isSpace) maxBound
244 . filter (not . null)
242 . filter (not . null)
245
243
246 tabsToSpaces :: Int -> String -> String
244 tabsToSpaces :: Int -> String -> String
@@ -336,13 +334,13 @@ codeHeaderArgs = try $ do
336 language <- skipSpaces *> orgArgWord
334 language <- skipSpaces *> orgArgWord
337 (switchClasses, switchKv) <- switchesAsAttributes
335 (switchClasses, switchKv) <- switchesAsAttributes
338 parameters <- manyTill blockOption newline
336 parameters <- manyTill blockOption newline
339− return $ ( translateLang language : switchClasses
337+ return ( translateLang language : switchClasses
340− , originalLang language <> switchKv <> parameters
338+ , originalLang language <> switchKv <> parameters
341− )
339+ )
342
340
343switchesAsAttributes :: Monad m => OrgParser m ([String], [(String, String)])
341switchesAsAttributes :: Monad m => OrgParser m ([String], [(String, String)])
344switchesAsAttributes = try $ do
342switchesAsAttributes = try $ do
345− switches <- skipSpaces *> (try $ switch `sepBy` (many1 spaceChar))
343+ switches <- skipSpaces *> try (switch `sepBy` many1 spaceChar)
346 return $ foldr addToAttr ([], []) switches
344 return $ foldr addToAttr ([], []) switches
347 where
345 where
348 addToAttr :: (Char, Maybe String, SwitchPolarity)
346 addToAttr :: (Char, Maybe String, SwitchPolarity)
@@ -350,7 +348,7 @@ switchesAsAttributes = try $ do
350 -> ([String], [(String, String)])
348 -> ([String], [(String, String)])
351 addToAttr ('n', lineNum, pol) (cls, kv) =
349 addToAttr ('n', lineNum, pol) (cls, kv) =
352 let kv' = case lineNum of
350 let kv' = case lineNum of
353− Just num -> (("startFrom", num):kv)
351+ Just num -> ("startFrom", num):kv
354 Nothing -> kv
352 Nothing -> kv
355 cls' = case pol of
353 cls' = case pol of
356 SwitchPlus -> "continuedSourceBlock":cls
354 SwitchPlus -> "continuedSourceBlock":cls
@@ -382,7 +380,7 @@ genericSwitch :: Monad m
382genericSwitch c p = try $ do
380genericSwitch c p = try $ do
383 polarity <- switchPolarity <* char c <* skipSpaces
381 polarity <- switchPolarity <* char c <* skipSpaces
384 arg <- optionMaybe p
382 arg <- optionMaybe p
385− return $ (c, arg, polarity)
383+ return (c, arg, polarity)
386
384
387-- | Reads a line number switch option. The line number switch can be used with
385-- | Reads a line number switch option. The line number switch can be used with
388-- example and source blocks.
386-- example and source blocks.
@@ -402,8 +400,8 @@ orgParamValue = try $
402 *> noneOf "\n\r" `many1Till` endOfValue
400 *> noneOf "\n\r" `many1Till` endOfValue
403 <* skipSpaces
401 <* skipSpaces
404 where
402 where
405− endOfValue = lookAhead $ (try $ skipSpaces <* oneOf "\n\r")
403+ endOfValue = lookAhead $ try (skipSpaces <* oneOf "\n\r")
406− <|> (try $ skipSpaces1 <* orgArgKey)
404+ <|> try (skipSpaces1 <* orgArgKey)
407
405
408
406
409--
407--
@@ -421,7 +419,7 @@ genericDrawer = try $ do
421 -- Include drawer if it is explicitly included in or not explicitly excluded
419 -- Include drawer if it is explicitly included in or not explicitly excluded
422 -- from the list of drawers that should be exported. PROPERTIES drawers are
420 -- from the list of drawers that should be exported. PROPERTIES drawers are
423 -- never exported.
421 -- never exported.
424− case (exportDrawers . orgStateExportSettings $ state) of
422+ case exportDrawers . orgStateExportSettings $ state of
425 _ | name == "PROPERTIES" -> return mempty
423 _ | name == "PROPERTIES" -> return mempty
426 Left names | name `elem` names -> return mempty
424 Left names | name `elem` names -> return mempty
427 Right names | name `notElem` names -> return mempty
425 Right names | name `notElem` names -> return mempty
@@ -455,7 +453,7 @@ figure = try $ do
455 Nothing -> mzero
453 Nothing -> mzero
456 Just imgSrc -> do
454 Just imgSrc -> do
457 guard (isImageFilename imgSrc)
455 guard (isImageFilename imgSrc)
458− let isFigure = not . isNothing $ blockAttrCaption figAttrs
456+ let isFigure = isJust $ blockAttrCaption figAttrs
459 return $ imageBlock isFigure figAttrs imgSrc
457 return $ imageBlock isFigure figAttrs imgSrc
460 where
458 where
461 selfTarget :: PandocMonad m => OrgParser m String
459 selfTarget :: PandocMonad m => OrgParser m String
@@ -490,8 +488,7 @@ endOfParagraph = try $ skipSpaces *> newline *> endOfBlock
490
488
491-- | Example code marked up by a leading colon.
489-- | Example code marked up by a leading colon.
492example :: Monad m => OrgParser m (F Blocks)
490example :: Monad m => OrgParser m (F Blocks)
493−example = try $ do
494− returnF . exampleCode =<< unlines <$> many1 exampleLine
491+example = try $ returnF . exampleCode =<< unlines <$> many1 exampleLine
495 where
492 where
496 exampleLine :: Monad m => OrgParser m String
493 exampleLine :: Monad m => OrgParser m String
497 exampleLine = try $ exampleLineStart *> anyLine
494 exampleLine = try $ exampleLineStart *> anyLine
@@ -514,7 +511,7 @@ include = try $ do
514 filename <- includeTarget
511 filename <- includeTarget
515 blockType <- optionMaybe $ skipSpaces *> many1 alphaNum
512 blockType <- optionMaybe $ skipSpaces *> many1 alphaNum
516 blocksParser <- case blockType of
513 blocksParser <- case blockType of
517− Just "example" -> do
514+ Just "example" ->
518 return $ pure . B.codeBlock <$> parseRaw
515 return $ pure . B.codeBlock <$> parseRaw
519 Just "export" -> do
516 Just "export" -> do
520 format <- skipSpaces *> many (noneOf "\n\r\t ")
517 format <- skipSpaces *> many (noneOf "\n\r\t ")
@@ -580,8 +577,8 @@ orgTable :: PandocMonad m => OrgParser m (F Blocks)
580orgTable = try $ do
577orgTable = try $ do
581 -- don't allow a table on the first line of a list item; org requires that
578 -- don't allow a table on the first line of a list item; org requires that
582 -- tables start at first non-space character on the line
579 -- tables start at first non-space character on the line
583− let isFirstInListItem st = (orgStateParserContext st == ListItemState) &&
580+ let isFirstInListItem st = orgStateParserContext st == ListItemState &&
584− (orgStateLastPreCharPos st == Nothing)
581+ isNothing (orgStateLastPreCharPos st)
585 guard =<< not . isFirstInListItem <$> getState
582 guard =<< not . isFirstInListItem <$> getState
586 blockAttrs <- blockAttributes
583 blockAttrs <- blockAttributes
587 lookAhead tableStart
584 lookAhead tableStart
@@ -594,7 +591,7 @@ orgToPandocTable :: OrgTable
594 -> Inlines
591 -> Inlines
595 -> Blocks
592 -> Blocks
596orgToPandocTable (OrgTable colProps heads lns) caption =
593orgToPandocTable (OrgTable colProps heads lns) caption =
597− let totalWidth = if any (not . isNothing) (map columnRelWidth colProps)
594+ let totalWidth = if any isJust (map columnRelWidth colProps)
598 then Just . sum $ map (fromMaybe 1 . columnRelWidth) colProps
595 then Just . sum $ map (fromMaybe 1 . columnRelWidth) colProps
599 else Nothing
596 else Nothing
600 in B.table caption (map (convertColProp totalWidth) colProps) heads lns
597 in B.table caption (map (convertColProp totalWidth) colProps) heads lns
@@ -604,7 +601,7 @@ orgToPandocTable (OrgTable colProps heads lns) caption =
604 let
601 let
605 align' = fromMaybe AlignDefault $ columnAlignment colProp
602 align' = fromMaybe AlignDefault $ columnAlignment colProp
606 width' = fromMaybe 0 $ (\w t -> (fromIntegral w / fromIntegral t))
603 width' = fromMaybe 0 $ (\w t -> (fromIntegral w / fromIntegral t))
607− <$> (columnRelWidth colProp)
604+ <$> columnRelWidth colProp
608 <*> totalWidth
605 <*> totalWidth
609 in (align', width')
606 in (align', width')
610
607
@@ -630,7 +627,7 @@ tableAlignRow = try $ do
630columnPropertyCell :: Monad m => OrgParser m ColumnProperty
627columnPropertyCell :: Monad m => OrgParser m ColumnProperty
631columnPropertyCell = emptyCell <|> propCell <?> "alignment info"
628columnPropertyCell = emptyCell <|> propCell <?> "alignment info"
632 where
629 where
633− emptyCell = ColumnProperty Nothing Nothing <$ (try $ skipSpaces *> endOfCell)
630+ emptyCell = ColumnProperty Nothing Nothing <$ try (skipSpaces *> endOfCell)
634 propCell = try $ ColumnProperty
631 propCell = try $ ColumnProperty
635 <$> (skipSpaces
632 <$> (skipSpaces
636 *> char '<'
633 *> char '<'
@@ -684,7 +681,7 @@ rowToContent tbl row =
684 where
681 where
685 singleRowPromotedToHeader :: OrgTable
682 singleRowPromotedToHeader :: OrgTable
686 singleRowPromotedToHeader = case tbl of
683 singleRowPromotedToHeader = case tbl of
687− OrgTable{ orgTableHeader = [], orgTableRows = b:[] } ->
684+ OrgTable{ orgTableHeader = [], orgTableRows = [b] } ->
688 tbl{ orgTableHeader = b , orgTableRows = [] }
685 tbl{ orgTableHeader = b , orgTableRows = [] }
689 _ -> tbl
686 _ -> tbl
690
687
@@ -739,7 +736,7 @@ noteBlock = try $ do
739paraOrPlain :: PandocMonad m => OrgParser m (F Blocks)
736paraOrPlain :: PandocMonad m => OrgParser m (F Blocks)
740paraOrPlain = try $ do
737paraOrPlain = try $ do
741 -- Make sure we are not looking at a headline
738 -- Make sure we are not looking at a headline
742− notFollowedBy' (char '*' *> (oneOf " *"))
739+ notFollowedBy' (char '*' *> oneOf " *")
743 ils <- inlines
740 ils <- inlines
744 nl <- option False (newline *> return True)
741 nl <- option False (newline *> return True)
745 -- Read block as paragraph, except if we are in a list context and the block
742 -- Read block as paragraph, except if we are in a list context and the block
@@ -748,7 +745,7 @@ paraOrPlain = try $ do
748 try (guard nl
745 try (guard nl
749 *> notFollowedBy (inList *> (() <$ orderedListStart <|> bulletListStart))
746 *> notFollowedBy (inList *> (() <$ orderedListStart <|> bulletListStart))
750 *> return (B.para <$> ils))
747 *> return (B.para <$> ils))
751− <|> (return (B.plain <$> ils))
748+ <|> return (B.plain <$> ils)
752
749
753
750
754--
751--
@@ -760,16 +757,16 @@ list = choice [ definitionList, bulletList, orderedList ] <?> "list"
760
757
761definitionList :: PandocMonad m => OrgParser m (F Blocks)
758definitionList :: PandocMonad m => OrgParser m (F Blocks)
762definitionList = try $ do n <- lookAhead (bulletListStart' Nothing)
759definitionList = try $ do n <- lookAhead (bulletListStart' Nothing)
763− fmap B.definitionList . fmap compactifyDL . sequence
760+ fmap (B.definitionList . compactifyDL) . sequence
764 <$> many1 (definitionListItem $ bulletListStart' (Just n))
761 <$> many1 (definitionListItem $ bulletListStart' (Just n))
765
762
766bulletList :: PandocMonad m => OrgParser m (F Blocks)
763bulletList :: PandocMonad m => OrgParser m (F Blocks)
767bulletList = try $ do n <- lookAhead (bulletListStart' Nothing)
764bulletList = try $ do n <- lookAhead (bulletListStart' Nothing)
768− fmap B.bulletList . fmap compactify . sequence
765+ fmap (B.bulletList . compactify) . sequence
769 <$> many1 (listItem (bulletListStart' $ Just n))
766 <$> many1 (listItem (bulletListStart' $ Just n))
770
767
771orderedList :: PandocMonad m => OrgParser m (F Blocks)
768orderedList :: PandocMonad m => OrgParser m (F Blocks)
772−orderedList = fmap B.orderedList . fmap compactify . sequence
769+orderedList = fmap (B.orderedList . compactify) . sequence
773 <$> many1 (listItem orderedListStart)
770 <$> many1 (listItem orderedListStart)
774
771
775bulletListStart' :: Monad m => Maybe Int -> OrgParser m Int
772bulletListStart' :: 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
32 , headlineToBlocks
32 , headlineToBlocks
33 ) where
33 ) where
34
34
35+import Control.Arrow ((***))
35import Control.Monad (guard, void)
36import Control.Monad (guard, void)
36import Data.Char (toLower, toUpper)
37import Data.Char (toLower, toUpper)
37import Data.List ( intersperse )
38import Data.List ( intersperse )
38−import Data.Maybe (fromMaybe)
39import Data.Monoid ((<>))
39import Data.Monoid ((<>))
40import Text.Pandoc.Builder (Blocks, Inlines)
40import Text.Pandoc.Builder (Blocks, Inlines)
41import Text.Pandoc.Class (PandocMonad)
41import Text.Pandoc.Class (PandocMonad)
@@ -142,7 +142,7 @@ headline blocks inline lvl = try $ do
142 title' <- title
142 title' <- title
143 contents' <- contents
143 contents' <- contents
144 children' <- sequence children
144 children' <- sequence children
145− return $ Headline
145+ return Headline
146 { headlineLevel = level
146 { headlineLevel = level
147 , headlineTodoMarker = todoKw
147 , headlineTodoMarker = todoKw
148 , headlineText = title'
148 , headlineText = title'
@@ -162,7 +162,7 @@ headline blocks inline lvl = try $ do
162
162
163-- | Convert an Org mode headline (i.e. a document tree) into pandoc's Blocks
163-- | Convert an Org mode headline (i.e. a document tree) into pandoc's Blocks
164headlineToBlocks :: Monad m => Headline -> OrgParser m Blocks
164headlineToBlocks :: Monad m => Headline -> OrgParser m Blocks
165−headlineToBlocks hdln@(Headline {..}) = do
165+headlineToBlocks hdln@Headline {..} = do
166 maxHeadlineLevels <- getExportSetting exportHeadlineLevels
166 maxHeadlineLevels <- getExportSetting exportHeadlineLevels
167 case () of
167 case () of
168 _ | any isNoExportTag headlineTags -> return mempty
168 _ | any isNoExportTag headlineTags -> return mempty
@@ -193,7 +193,7 @@ archivedHeadlineToBlocks hdln = do
193 ArchivedTreesHeadlineOnly -> headlineToHeader hdln
193 ArchivedTreesHeadlineOnly -> headlineToHeader hdln
194
194
195headlineToHeaderWithList :: Monad m => Headline -> OrgParser m Blocks
195headlineToHeaderWithList :: Monad m => Headline -> OrgParser m Blocks
196−headlineToHeaderWithList hdln@(Headline {..}) = do
196+headlineToHeaderWithList hdln@Headline {..} = do
197 maxHeadlineLevels <- getExportSetting exportHeadlineLevels
197 maxHeadlineLevels <- getExportSetting exportHeadlineLevels
198 header <- headlineToHeader hdln
198 header <- headlineToHeader hdln
199 listElements <- mapM headlineToBlocks headlineChildren
199 listElements <- mapM headlineToBlocks headlineChildren
@@ -212,13 +212,13 @@ headlineToHeaderWithList hdln@(Headline {..}) = do
212 _ -> mempty
212 _ -> mempty
213
213
214headlineToHeaderWithContents :: Monad m => Headline -> OrgParser m Blocks
214headlineToHeaderWithContents :: Monad m => Headline -> OrgParser m Blocks
215−headlineToHeaderWithContents hdln@(Headline {..}) = do
215+headlineToHeaderWithContents hdln@Headline {..} = do
216 header <- headlineToHeader hdln
216 header <- headlineToHeader hdln
217 childrenBlocks <- mconcat <$> mapM headlineToBlocks headlineChildren
217 childrenBlocks <- mconcat <$> mapM headlineToBlocks headlineChildren
218 return $ header <> headlineContents <> childrenBlocks
218 return $ header <> headlineContents <> childrenBlocks
219
219
220headlineToHeader :: Monad m => Headline -> OrgParser m Blocks
220headlineToHeader :: Monad m => Headline -> OrgParser m Blocks
221−headlineToHeader (Headline {..}) = do
221+headlineToHeader Headline {..} = do
222 exportTodoKeyword <- getExportSetting exportWithTodoKeywords
222 exportTodoKeyword <- getExportSetting exportWithTodoKeywords
223 exportTags <- getExportSetting exportWithTags
223 exportTags <- getExportSetting exportWithTags
224 let todoText = if exportTodoKeyword
224 let todoText = if exportTodoKeyword
@@ -237,7 +237,7 @@ headlineToHeader (Headline {..}) = do
237todoKeyword :: Monad m => OrgParser m TodoMarker
237todoKeyword :: Monad m => OrgParser m TodoMarker
238todoKeyword = try $ do
238todoKeyword = try $ do
239 taskStates <- activeTodoMarkers <$> getState
239 taskStates <- activeTodoMarkers <$> getState
240− let kwParser tdm = try $ (tdm <$ string (todoMarkerName tdm) <* spaceChar)
240+ let kwParser tdm = try (tdm <$ string (todoMarkerName tdm) <* spaceChar)
241 choice (map kwParser taskStates)
241 choice (map kwParser taskStates)
242
242
243todoKeywordToInlines :: TodoMarker -> Inlines
243todoKeywordToInlines :: TodoMarker -> Inlines
@@ -250,19 +250,19 @@ todoKeywordToInlines tdm =
250propertiesToAttr :: Properties -> Attr
250propertiesToAttr :: Properties -> Attr
251propertiesToAttr properties =
251propertiesToAttr properties =
252 let
252 let
253− toStringPair prop = (fromKey (fst prop), fromValue (snd prop))
253+ toStringPair = fromKey *** fromValue
254 customIdKey = toPropertyKey "custom_id"
254 customIdKey = toPropertyKey "custom_id"
255 classKey = toPropertyKey "class"
255 classKey = toPropertyKey "class"
256 unnumberedKey = toPropertyKey "unnumbered"
256 unnumberedKey = toPropertyKey "unnumbered"
257 specialProperties = [customIdKey, classKey, unnumberedKey]
257 specialProperties = [customIdKey, classKey, unnumberedKey]
258− id' = fromMaybe mempty . fmap fromValue . lookup customIdKey $ properties
258+ id' = maybe mempty fromValue . lookup customIdKey $ properties
259− cls = fromMaybe mempty . fmap fromValue . lookup classKey $ properties
259+ cls = maybe mempty fromValue . lookup classKey $ properties
260 kvs' = map toStringPair . filter ((`notElem` specialProperties) . fst)
260 kvs' = map toStringPair . filter ((`notElem` specialProperties) . fst)
261 $ properties
261 $ properties
262 isUnnumbered =
262 isUnnumbered =
263− fromMaybe False . fmap isNonNil . lookup unnumberedKey $ properties
263+ maybe False isNonNil . lookup unnumberedKey $ properties
264 in
264 in
265− (id', words cls ++ (if isUnnumbered then ["unnumbered"] else []), kvs')
265+ (id', words cls ++ ["unnumbered" | isUnnumbered], kvs')
266
266
267tagsToInlines :: [Tag] -> Inlines
267tagsToInlines :: [Tag] -> Inlines
268tagsToInlines [] = mempty
268tagsToInlines [] = mempty
@@ -302,4 +302,3 @@ propertiesDrawer = try $ do
302 endOfDrawer :: Monad m => OrgParser m String
302 endOfDrawer :: Monad m => OrgParser m String
303 endOfDrawer = try $
303 endOfDrawer = try $
304 skipSpaces *> stringAnyCase ":END:" <* skipSpaces <* newline
304 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)
48import Text.TeXMath (DisplayType (..), readTeX, writePandoc)
48import Text.TeXMath (DisplayType (..), readTeX, writePandoc)
49import qualified Text.TeXMath.Readers.MathML.EntityMap as MathMLEntityMap
49import qualified Text.TeXMath.Readers.MathML.EntityMap as MathMLEntityMap
50
50
51−import Control.Monad (guard, mplus, mzero, void, when)
51+import Control.Monad (guard, mplus, mzero, unless, void, when)
52import Control.Monad.Trans (lift)
52import Control.Monad.Trans (lift)
53import Data.Char (isAlphaNum, isSpace)
53import Data.Char (isAlphaNum, isSpace)
54import Data.List (intersperse)
54import Data.List (intersperse)
@@ -63,7 +63,7 @@ import Prelude hiding (sequence)
63--
63--
64recordAnchorId :: PandocMonad m => String -> OrgParser m ()
64recordAnchorId :: PandocMonad m => String -> OrgParser m ()
65recordAnchorId i = updateState $ \s ->
65recordAnchorId i = updateState $ \s ->
66− s{ orgStateAnchorIds = i : (orgStateAnchorIds s) }
66+ s{ orgStateAnchorIds = i : orgStateAnchorIds s }
67
67
68pushToInlineCharStack :: PandocMonad m => Char -> OrgParser m ()
68pushToInlineCharStack :: PandocMonad m => Char -> OrgParser m ()
69pushToInlineCharStack c = updateState $ \s ->
69pushToInlineCharStack c = updateState $ \s ->
@@ -184,7 +184,7 @@ cite = try $ berkeleyCite <|> do
184 , orgRefCite
184 , orgRefCite
185 , berkeleyTextualCite
185 , berkeleyTextualCite
186 ]
186 ]
187− return $ (flip B.cite (B.text raw)) <$> cs
187+ return $ flip B.cite (B.text raw) <$> cs
188
188
189-- | A citation in Pandoc Org-mode style (@[prefix \@citekey suffix]@).
189-- | A citation in Pandoc Org-mode style (@[prefix \@citekey suffix]@).
190pandocOrgCite :: PandocMonad m => OrgParser m (F [Citation])
190pandocOrgCite :: PandocMonad m => OrgParser m (F [Citation])
@@ -209,7 +209,7 @@ normalOrgRefCite = try $ do
209 orgRefCiteList :: PandocMonad m => CitationMode -> OrgParser m (F Citation)
209 orgRefCiteList :: PandocMonad m => CitationMode -> OrgParser m (F Citation)
210 orgRefCiteList citeMode = try $ do
210 orgRefCiteList citeMode = try $ do
211 key <- orgRefCiteKey
211 key <- orgRefCiteKey
212− returnF $ Citation
212+ returnF Citation
213 { citationId = key
213 { citationId = key
214 , citationPrefix = mempty
214 , citationPrefix = mempty
215 , citationSuffix = mempty
215 , citationSuffix = mempty
@@ -232,11 +232,11 @@ berkeleyCite = try $ do
232 return $
232 return $
233 if parens
233 if parens
234 then toCite
234 then toCite
235− . maybe id (\p -> alterFirst (prependPrefix p)) prefix
235+ . maybe id (alterFirst . prependPrefix) prefix
236− . maybe id (\s -> alterLast (appendSuffix s)) suffix
236+ . maybe id (alterLast . appendSuffix) suffix
237 $ citationList
237 $ citationList
238 else maybe mempty (<> " ") prefix
238 else maybe mempty (<> " ") prefix
239− <> (toListOfCites $ map toInTextMode citationList)
239+ <> toListOfCites (map toInTextMode citationList)
240 <> maybe mempty (", " <>) suffix
240 <> maybe mempty (", " <>) suffix
241 where
241 where
242 toCite :: [Citation] -> Inlines
242 toCite :: [Citation] -> Inlines
@@ -250,7 +250,7 @@ berkeleyCite = try $ do
250
250
251 alterFirst, alterLast :: (a -> a) -> [a] -> [a]
251 alterFirst, alterLast :: (a -> a) -> [a] -> [a]
252 alterFirst _ [] = []
252 alterFirst _ [] = []
253− alterFirst f (c:cs) = (f c):cs
253+ alterFirst f (c:cs) = f c : cs
254 alterLast f = reverse . alterFirst f . reverse
254 alterLast f = reverse . alterFirst f . reverse
255
255
256 prependPrefix, appendSuffix :: Inlines -> Citation -> Citation
256 prependPrefix, appendSuffix :: Inlines -> Citation -> Citation
@@ -271,7 +271,7 @@ berkeleyCitationList = try $ do
271 skipSpaces
271 skipSpaces
272 commonPrefix <- optionMaybe (try $ citationListPart <* char ';')
272 commonPrefix <- optionMaybe (try $ citationListPart <* char ';')
273 citations <- citeList
273 citations <- citeList
274− commonSuffix <- optionMaybe (try $ citationListPart)
274+ commonSuffix <- optionMaybe (try citationListPart)
275 char ']'
275 char ']'
276 return (BerkeleyCitationList parens
276 return (BerkeleyCitationList parens
277 <$> sequence commonPrefix
277 <$> sequence commonPrefix
@@ -344,7 +344,7 @@ orgRefCiteKey =
344 isCiteKeySpecialChar c = c `elem` citeKeySpecialChars
344 isCiteKeySpecialChar c = c `elem` citeKeySpecialChars
345 isCiteKeyChar c = isAlphaNum c || isCiteKeySpecialChar c
345 isCiteKeyChar c = isAlphaNum c || isCiteKeySpecialChar c
346
346
347− in try $ many1Till (satisfy $ isCiteKeyChar)
347+ in try $ many1Till (satisfy isCiteKeyChar)
348 $ try . lookAhead $ do
348 $ try . lookAhead $ do
349 many . satisfy $ isCiteKeySpecialChar
349 many . satisfy $ isCiteKeySpecialChar
350 satisfy $ not . isCiteKeyChar
350 satisfy $ not . isCiteKeyChar
@@ -374,15 +374,16 @@ citation = try $ do
374 return $ do
374 return $ do
375 x <- pref
375 x <- pref
376 y <- suff
376 y <- suff
377− return $ Citation{ citationId = key
377+ return Citation
378+ { citationId = key
378− , citationPrefix = B.toList x
379+ , citationPrefix = B.toList x
379− , citationSuffix = B.toList y
380+ , citationSuffix = B.toList y
380− , citationMode = if suppress_author
381+ , citationMode = if suppress_author
381− then SuppressAuthor
382+ then SuppressAuthor
382− else NormalCitation
383+ else NormalCitation
383− , citationNoteNum = 0
384+ , citationNoteNum = 0
384− , citationHash = 0
385+ , citationHash = 0
385− }
386+ }
386 where
387 where
387 prefix = trimInlinesF . mconcat <$>
388 prefix = trimInlinesF . mconcat <$>
388 manyTill inline (char ']' <|> (']' <$ lookAhead citeKey))
389 manyTill inline (char ']' <|> (']' <$ lookAhead citeKey))
@@ -404,7 +405,7 @@ inlineNote = try $ do
404 ref <- many alphaNum
405 ref <- many alphaNum
405 char ':'
406 char ':'
406 note <- fmap B.para . trimInlinesF . mconcat <$> many1Till inline (char ']')
407 note <- fmap B.para . trimInlinesF . mconcat <$> many1Till inline (char ']')
407− when (not $ null ref) $
408+ unless (null ref) $
408 addToNotesTable ("fn:" ++ ref, note)
409 addToNotesTable ("fn:" ++ ref, note)
409 return $ B.note <$> note
410 return $ B.note <$> note
410
411
@@ -780,7 +781,7 @@ notAfterForbiddenBorderChar = do
780-- | Read a sub- or superscript expression
781-- | Read a sub- or superscript expression
781subOrSuperExpr :: PandocMonad m => OrgParser m (F Inlines)
782subOrSuperExpr :: PandocMonad m => OrgParser m (F Inlines)
782subOrSuperExpr = try $
783subOrSuperExpr = try $
783− choice [ id <$> charsInBalanced '{' '}' (noneOf "\n\r")
784+ choice [ charsInBalanced '{' '}' (noneOf "\n\r")
784 , enclosing ('(', ')') <$> charsInBalanced '(' ')' (noneOf "\n\r")
785 , enclosing ('(', ')') <$> charsInBalanced '(' ')' (noneOf "\n\r")
785 , simpleSubOrSuperString
786 , simpleSubOrSuperString
786 ] >>= parseFromString (mconcat <$> many inline)
787 ] >>= parseFromString (mconcat <$> many inline)
@@ -818,7 +819,7 @@ inlineLaTeX = try $ do
818 enableExtension Ext_raw_tex (readerExtensions def) } }
819 enableExtension Ext_raw_tex (readerExtensions def) } }
819
820
820 texMathToPandoc :: String -> Maybe [Inline]
821 texMathToPandoc :: String -> Maybe [Inline]
821− texMathToPandoc cs = (maybeRight $ readTeX cs) >>= writePandoc DisplayInline
822+ texMathToPandoc cs = maybeRight (readTeX cs) >>= writePandoc DisplayInline
822
823
823maybeRight :: Either a b -> Maybe b
824maybeRight :: Either a b -> Maybe b
824maybeRight = either (const Nothing) Just
825maybeRight = either (const Nothing) Just
@@ -869,21 +870,19 @@ macro = try $ do
869 eoa = string ")}}}"
870 eoa = string ")}}}"
870
871
871smart :: PandocMonad m => OrgParser m (F Inlines)
872smart :: 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]
875 where
874 where
876 orgDash = do
875 orgDash = do
877 guardOrSmartEnabled =<< getExportSetting exportSpecialStrings
876 guardOrSmartEnabled =<< getExportSetting exportSpecialStrings
878− dash <* updatePositions '-'
877+ pure <$> dash <* updatePositions '-'
879 orgEllipses = do
878 orgEllipses = do
880 guardOrSmartEnabled =<< getExportSetting exportSpecialStrings
879 guardOrSmartEnabled =<< getExportSetting exportSpecialStrings
881− ellipses <* updatePositions '.'
880+ pure <$> ellipses <* updatePositions '.'
882 orgApostrophe = do
881 orgApostrophe = do
883 guardEnabled Ext_smart
882 guardEnabled Ext_smart
884 (char '\'' <|> char '\8217') <* updateLastPreCharPos
883 (char '\'' <|> char '\8217') <* updateLastPreCharPos
885 <* updateLastForbiddenCharPos
884 <* updateLastForbiddenCharPos
886− return (B.str "\x2019")
885+ returnF (B.str "\x2019")
887
886
888guardOrSmartEnabled :: PandocMonad m => Bool -> OrgParser m ()
887guardOrSmartEnabled :: PandocMonad m => Bool -> OrgParser m ()
889guardOrSmartEnabled b = do
888guardOrSmartEnabled b = do
@@ -908,6 +907,9 @@ doubleQuoted = try $ do
908 doubleQuoteStart
907 doubleQuoteStart
909 updatePositions '"'
908 updatePositions '"'
910 contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
909 contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
910+ let doubleQuotedContent = withQuoteContext InDoubleQuote $ do
911+ doubleQuoteEnd
911− (withQuoteContext InDoubleQuote $ (doubleQuoteEnd <* updateLastForbiddenCharPos) >> return
912+ updateLastForbiddenCharPos
912− (fmap B.doubleQuoted . trimInlinesF $ contents))
913+ return . fmap B.doubleQuoted . trimInlinesF $ contents
913− <|> (return $ return (B.str "\8220") <> 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")
84 <* char ':'
84 <* char ':'
85 <* skipSpaces
85 <* skipSpaces
86
86
87−metaValue :: PandocMonad m => String -> OrgParser m (String, (F MetaValue))
87+metaValue :: PandocMonad m => String -> OrgParser m (String, F MetaValue)
88metaValue key =
88metaValue key =
89 let inclKey = "header-includes"
89 let inclKey = "header-includes"
90 in case key of
90 in case key of
@@ -111,7 +111,7 @@ metaInlines = fmap (MetaInlines . B.toList) <$> inlinesTillNewline
111
111
112metaInlinesCommaSeparated :: PandocMonad m => OrgParser m (F MetaValue)
112metaInlinesCommaSeparated :: PandocMonad m => OrgParser m (F MetaValue)
113metaInlinesCommaSeparated = do
113metaInlinesCommaSeparated = do
114− itemStrs <- (many1 (noneOf ",\n")) `sepBy1` (char ',')
114+ itemStrs <- many1 (noneOf ",\n") `sepBy1` char ','
115 newline
115 newline
116 items <- mapM (parseFromString inlinesTillNewline . (++ "\n")) itemStrs
116 items <- mapM (parseFromString inlinesTillNewline . (++ "\n")) itemStrs
117 let toMetaInlines = MetaInlines . B.toList
117 let toMetaInlines = MetaInlines . B.toList
@@ -163,7 +163,7 @@ addLinkFormat key formatter = updateState $ \s ->
163 let fs = orgStateLinkFormatters s
163 let fs = orgStateLinkFormatters s
164 in s{ orgStateLinkFormatters = M.insert key formatter fs }
164 in s{ orgStateLinkFormatters = M.insert key formatter fs }
165
165
166−parseLinkFormat :: Monad m => OrgParser m ((String, String -> String))
166+parseLinkFormat :: Monad m => OrgParser m (String, String -> String)
167parseLinkFormat = try $ do
167parseLinkFormat = try $ do
168 linkType <- (:) <$> letter <*> many (alphaNum <|> oneOf "-_") <* skipSpaces
168 linkType <- (:) <$> letter <*> many (alphaNum <|> oneOf "-_") <* skipSpaces
169 linkSubst <- parseFormat
169 linkSubst <- parseFormat
@@ -172,8 +172,7 @@ parseLinkFormat = try $ do
172-- | An ad-hoc, single-argument-only implementation of a printf-style format
172-- | An ad-hoc, single-argument-only implementation of a printf-style format
173-- parser.
173-- parser.
174parseFormat :: Monad m => OrgParser m (String -> String)
174parseFormat :: Monad m => OrgParser m (String -> String)
175−parseFormat = try $ do
176− replacePlain <|> replaceUrl <|> justAppend
175+parseFormat = try $ replacePlain <|> replaceUrl <|> justAppend
177 where
176 where
178 -- inefficient, but who cares
177 -- inefficient, but who cares
179 replacePlain = try $ (\x -> concat . flip intersperse x)
178 replacePlain = try $ (\x -> concat . flip intersperse x)
src/Text/Pandoc/Readers/Org/ParserState.hs−1
@@ -1,5 +1,4 @@
1{-# LANGUAGE FlexibleInstances #-}
1{-# LANGUAGE FlexibleInstances #-}
2−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE MultiParamTypeClasses #-}
2{-# LANGUAGE MultiParamTypeClasses #-}
4{-
3{-
5Copyright (C) 2014-2017 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
4Copyright (C) 2014-2017 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
src/Text/Pandoc/Readers/Org/Shared.hs+1−1
@@ -56,7 +56,7 @@ cleanLinkString s =
56 '.':'/':_ -> Just s -- relative path
56 '.':'/':_ -> Just s -- relative path
57 '.':'.':'/':_ -> Just s -- relative path
57 '.':'.':'/':_ -> Just s -- relative path
58 -- Relative path or URL (file schema)
58 -- 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'
60 _ | isUrl s -> Just s -- URL
60 _ | isUrl s -> Just s -- URL
61 _ -> Nothing
61 _ -> Nothing
62 where
62 where