@@ -1,4 +1,3 @@
1−{-# LANGUAGE NoImplicitPrelude #-}
21{-
32Copyright (C) 2014-2018 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
43
@@ -17,8 +16,7 @@ along with this program; if not, write to the Free Software
1716Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1817-}
1918{-# LANGUAGE FlexibleContexts #-}
20−{-# LANGUAGE RecordWildCards #-}
21−{-# LANGUAGE ViewPatterns #-}
19+{-# LANGUAGE NoImplicitPrelude #-}
2220{- |
2321 Module : Text.Pandoc.Readers.Org.DocumentTree
2422 Copyright : Copyright (C) 2014-2018 Albert Krewinkel
@@ -167,14 +165,17 @@ headline blocks inline lvl = try $ do
167165
168166-- | Convert an Org mode headline (i.e. a document tree) into pandoc's Blocks
169167headlineToBlocks :: Monad m => Headline -> OrgParser m Blocks
170−headlineToBlocks hdln@Headline {..} = do
171− maxHeadlineLevels <- getExportSetting exportHeadlineLevels
168+headlineToBlocks hdln = do
169+ maxLevel <- getExportSetting exportHeadlineLevels
170+ let tags = headlineTags hdln
171+ let text = headlineText hdln
172+ let level = headlineLevel hdln
172173 case () of
173− _ | any isNoExportTag headlineTags -> return mempty
174− _ | any isArchiveTag headlineTags -> archivedHeadlineToBlocks hdln
175− _ | isCommentTitle headlineText -> return mempty
176− _ | headlineLevel >= maxHeadlineLevels -> headlineToHeaderWithList hdln
177− _ | otherwise -> headlineToHeaderWithContents hdln
174+ _ | any isNoExportTag tags -> return mempty
175+ _ | any isArchiveTag tags -> archivedHeadlineToBlocks hdln
176+ _ | isCommentTitle text -> return mempty
177+ _ | maxLevel <= level -> headlineToHeaderWithList hdln
178+ _ | otherwise -> headlineToHeaderWithContents hdln
178179
179180isNoExportTag :: Tag -> Bool
180181isNoExportTag = (== toTag "noexport")
@@ -186,8 +187,9 @@ isArchiveTag = (== toTag "ARCHIVE")
186187-- FIXME: This accesses builder internals not intended for use in situations
187188-- like these. Replace once keyword parsing is supported.
188189isCommentTitle :: Inlines -> Bool
189−isCommentTitle (B.toList -> (Str "COMMENT":_)) = True
190−isCommentTitle _ = False
190+isCommentTitle inlns = case B.toList inlns of
191+ (Str "COMMENT":_) -> True
192+ _ -> False
191193
192194archivedHeadlineToBlocks :: Monad m => Headline -> OrgParser m Blocks
193195archivedHeadlineToBlocks hdln = do
@@ -198,17 +200,21 @@ archivedHeadlineToBlocks hdln = do
198200 ArchivedTreesHeadlineOnly -> headlineToHeader hdln
199201
200202headlineToHeaderWithList :: Monad m => Headline -> OrgParser m Blocks
201−headlineToHeaderWithList hdln@Headline {..} = do
203+headlineToHeaderWithList hdln = do
202204 maxHeadlineLevels <- getExportSetting exportHeadlineLevels
203205 header <- headlineToHeader hdln
204− listElements <- mapM headlineToBlocks headlineChildren
206+ listElements <- mapM headlineToBlocks (headlineChildren hdln)
205207 let listBlock = if null listElements
206208 then mempty
207209 else B.orderedList listElements
208− let headerText = if maxHeadlineLevels == headlineLevel
210+ let headerText = if maxHeadlineLevels == headlineLevel hdln
209211 then header
210212 else flattenHeader header
211− return $ headerText <> headlineContents <> listBlock
213+ return . mconcat $
214+ [ headerText
215+ , headlineContents hdln
216+ , listBlock
217+ ]
212218 where
213219 flattenHeader :: Blocks -> Blocks
214220 flattenHeader blks =
@@ -217,27 +223,27 @@ headlineToHeaderWithList hdln@Headline {..} = do
217223 _ -> mempty
218224
219225headlineToHeaderWithContents :: Monad m => Headline -> OrgParser m Blocks
220−headlineToHeaderWithContents hdln@Headline {..} = do
226+headlineToHeaderWithContents hdln = do
221227 header <- headlineToHeader hdln
222− childrenBlocks <- mconcat <$> mapM headlineToBlocks headlineChildren
223− return $ header <> headlineContents <> childrenBlocks
228+ childrenBlocks <- mconcat <$> mapM headlineToBlocks (headlineChildren hdln)
229+ return $ header <> headlineContents hdln <> childrenBlocks
224230
225231headlineToHeader :: Monad m => Headline -> OrgParser m Blocks
226−headlineToHeader Headline {..} = do
232+headlineToHeader hdln = do
227233 exportTodoKeyword <- getExportSetting exportWithTodoKeywords
228234 exportTags <- getExportSetting exportWithTags
229235 let todoText = if exportTodoKeyword
230− then case headlineTodoMarker of
236+ then case headlineTodoMarker hdln of
231237 Just kw -> todoKeywordToInlines kw <> B.space
232238 Nothing -> mempty
233239 else mempty
234− let text = todoText <> headlineText <>
240+ let text = todoText <> headlineText hdln <>
235241 if exportTags
236− then tagsToInlines headlineTags
242+ then tagsToInlines (headlineTags hdln)
237243 else mempty
238− let propAttr = propertiesToAttr headlineProperties
239− attr <- registerHeader propAttr headlineText
240− return $ B.headerWith attr headlineLevel text
244+ let propAttr = propertiesToAttr (headlineProperties hdln)
245+ attr <- registerHeader propAttr (headlineText hdln)
246+ return $ B.headerWith attr (headlineLevel hdln) text
241247
242248todoKeyword :: Monad m => OrgParser m TodoMarker
243249todoKeyword = try $ do