summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Org/DocumentTree.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Readers/Org/DocumentTree.hs')
-rw-r--r--src/Text/Pandoc/Readers/Org/DocumentTree.hs25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Readers/Org/DocumentTree.hs b/src/Text/Pandoc/Readers/Org/DocumentTree.hs
index 4abbe7be8..cee740e30 100644
--- a/src/Text/Pandoc/Readers/Org/DocumentTree.hs
+++ b/src/Text/Pandoc/Readers/Org/DocumentTree.hs
@@ -32,10 +32,10 @@ module Text.Pandoc.Readers.Org.DocumentTree
, headlineToBlocks
) where
+import Control.Arrow ((***))
import Control.Monad (guard, void)
import Data.Char (toLower, toUpper)
import Data.List ( intersperse )
-import Data.Maybe (fromMaybe)
import Data.Monoid ((<>))
import Text.Pandoc.Builder (Blocks, Inlines)
import Text.Pandoc.Class (PandocMonad)
@@ -142,7 +142,7 @@ headline blocks inline lvl = try $ do
title' <- title
contents' <- contents
children' <- sequence children
- return $ Headline
+ return Headline
{ headlineLevel = level
, headlineTodoMarker = todoKw
, headlineText = title'
@@ -162,7 +162,7 @@ headline blocks inline lvl = try $ do
-- | Convert an Org mode headline (i.e. a document tree) into pandoc's Blocks
headlineToBlocks :: Monad m => Headline -> OrgParser m Blocks
-headlineToBlocks hdln@(Headline {..}) = do
+headlineToBlocks hdln@Headline {..} = do
maxHeadlineLevels <- getExportSetting exportHeadlineLevels
case () of
_ | any isNoExportTag headlineTags -> return mempty
@@ -193,7 +193,7 @@ archivedHeadlineToBlocks hdln = do
ArchivedTreesHeadlineOnly -> headlineToHeader hdln
headlineToHeaderWithList :: Monad m => Headline -> OrgParser m Blocks
-headlineToHeaderWithList hdln@(Headline {..}) = do
+headlineToHeaderWithList hdln@Headline {..} = do
maxHeadlineLevels <- getExportSetting exportHeadlineLevels
header <- headlineToHeader hdln
listElements <- mapM headlineToBlocks headlineChildren
@@ -212,13 +212,13 @@ headlineToHeaderWithList hdln@(Headline {..}) = do
_ -> mempty
headlineToHeaderWithContents :: Monad m => Headline -> OrgParser m Blocks
-headlineToHeaderWithContents hdln@(Headline {..}) = do
+headlineToHeaderWithContents hdln@Headline {..} = do
header <- headlineToHeader hdln
childrenBlocks <- mconcat <$> mapM headlineToBlocks headlineChildren
return $ header <> headlineContents <> childrenBlocks
headlineToHeader :: Monad m => Headline -> OrgParser m Blocks
-headlineToHeader (Headline {..}) = do
+headlineToHeader Headline {..} = do
exportTodoKeyword <- getExportSetting exportWithTodoKeywords
exportTags <- getExportSetting exportWithTags
let todoText = if exportTodoKeyword
@@ -237,7 +237,7 @@ headlineToHeader (Headline {..}) = do
todoKeyword :: Monad m => OrgParser m TodoMarker
todoKeyword = try $ do
taskStates <- activeTodoMarkers <$> getState
- let kwParser tdm = try $ (tdm <$ string (todoMarkerName tdm) <* spaceChar)
+ let kwParser tdm = try (tdm <$ string (todoMarkerName tdm) <* spaceChar)
choice (map kwParser taskStates)
todoKeywordToInlines :: TodoMarker -> Inlines
@@ -250,19 +250,19 @@ todoKeywordToInlines tdm =
propertiesToAttr :: Properties -> Attr
propertiesToAttr properties =
let
- toStringPair prop = (fromKey (fst prop), fromValue (snd prop))
+ toStringPair = fromKey *** fromValue
customIdKey = toPropertyKey "custom_id"
classKey = toPropertyKey "class"
unnumberedKey = toPropertyKey "unnumbered"
specialProperties = [customIdKey, classKey, unnumberedKey]
- id' = fromMaybe mempty . fmap fromValue . lookup customIdKey $ properties
- cls = fromMaybe mempty . fmap fromValue . lookup classKey $ properties
+ id' = maybe mempty fromValue . lookup customIdKey $ properties
+ cls = maybe mempty fromValue . lookup classKey $ properties
kvs' = map toStringPair . filter ((`notElem` specialProperties) . fst)
$ properties
isUnnumbered =
- fromMaybe False . fmap isNonNil . lookup unnumberedKey $ properties
+ maybe False isNonNil . lookup unnumberedKey $ properties
in
- (id', words cls ++ (if isUnnumbered then ["unnumbered"] else []), kvs')
+ (id', words cls ++ ["unnumbered" | isUnnumbered], kvs')
tagsToInlines :: [Tag] -> Inlines
tagsToInlines [] = mempty
@@ -302,4 +302,3 @@ propertiesDrawer = try $ do
endOfDrawer :: Monad m => OrgParser m String
endOfDrawer = try $
skipSpaces *> stringAnyCase ":END:" <* skipSpaces <* newline
-