git.iko.soy/typeable/pandoc
on master help sign in
Org reader internals: disable some GHC extensions
aac3d75Albert Krewinkel
src/Text/Pandoc/Readers/Org/DocumentTree.hs+32−26
@@ -1,4 +1,3 @@
1−{-# LANGUAGE NoImplicitPrelude #-}
2{-
1{-
3Copyright (C) 2014-2018 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
2Copyright (C) 2014-2018 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
4
3
@@ -17,8 +16,7 @@ along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18-}
17-}
19{-# LANGUAGE FlexibleContexts #-}
18{-# LANGUAGE FlexibleContexts #-}
20−{-# LANGUAGE RecordWildCards #-}
19+{-# LANGUAGE NoImplicitPrelude #-}
21−{-# LANGUAGE ViewPatterns #-}
22{- |
20{- |
23 Module : Text.Pandoc.Readers.Org.DocumentTree
21 Module : Text.Pandoc.Readers.Org.DocumentTree
24 Copyright : Copyright (C) 2014-2018 Albert Krewinkel
22 Copyright : Copyright (C) 2014-2018 Albert Krewinkel
@@ -167,14 +165,17 @@ headline blocks inline lvl = try $ do
167
165
168-- | Convert an Org mode headline (i.e. a document tree) into pandoc's Blocks
166-- | Convert an Org mode headline (i.e. a document tree) into pandoc's Blocks
169headlineToBlocks :: Monad m => Headline -> OrgParser m Blocks
167headlineToBlocks :: Monad m => Headline -> OrgParser m Blocks
170−headlineToBlocks hdln@Headline {..} = do
168+headlineToBlocks hdln = do
171− maxHeadlineLevels <- getExportSetting exportHeadlineLevels
169+ maxLevel <- getExportSetting exportHeadlineLevels
170+ let tags = headlineTags hdln
171+ let text = headlineText hdln
172+ let level = headlineLevel hdln
172 case () of
173 case () of
173− _ | any isNoExportTag headlineTags -> return mempty
174+ _ | any isNoExportTag tags -> return mempty
174− _ | any isArchiveTag headlineTags -> archivedHeadlineToBlocks hdln
175+ _ | any isArchiveTag tags -> archivedHeadlineToBlocks hdln
175− _ | isCommentTitle headlineText -> return mempty
176+ _ | isCommentTitle text -> return mempty
176− _ | headlineLevel >= maxHeadlineLevels -> headlineToHeaderWithList hdln
177+ _ | maxLevel <= level -> headlineToHeaderWithList hdln
177− _ | otherwise -> headlineToHeaderWithContents hdln
178+ _ | otherwise -> headlineToHeaderWithContents hdln
178
179
179isNoExportTag :: Tag -> Bool
180isNoExportTag :: Tag -> Bool
180isNoExportTag = (== toTag "noexport")
181isNoExportTag = (== toTag "noexport")
@@ -186,8 +187,9 @@ isArchiveTag = (== toTag "ARCHIVE")
186-- FIXME: This accesses builder internals not intended for use in situations
187-- FIXME: This accesses builder internals not intended for use in situations
187-- like these. Replace once keyword parsing is supported.
188-- like these. Replace once keyword parsing is supported.
188isCommentTitle :: Inlines -> Bool
189isCommentTitle :: Inlines -> Bool
190+isCommentTitle inlns = case B.toList inlns of
189−isCommentTitle (B.toList -> (Str "COMMENT":_)) = True
191+ (Str "COMMENT":_) -> True
190−isCommentTitle _ = False
192+ _ -> False
191
193
192archivedHeadlineToBlocks :: Monad m => Headline -> OrgParser m Blocks
194archivedHeadlineToBlocks :: Monad m => Headline -> OrgParser m Blocks
193archivedHeadlineToBlocks hdln = do
195archivedHeadlineToBlocks hdln = do
@@ -198,17 +200,21 @@ archivedHeadlineToBlocks hdln = do
198 ArchivedTreesHeadlineOnly -> headlineToHeader hdln
200 ArchivedTreesHeadlineOnly -> headlineToHeader hdln
199
201
200headlineToHeaderWithList :: Monad m => Headline -> OrgParser m Blocks
202headlineToHeaderWithList :: Monad m => Headline -> OrgParser m Blocks
201−headlineToHeaderWithList hdln@Headline {..} = do
203+headlineToHeaderWithList hdln = do
202 maxHeadlineLevels <- getExportSetting exportHeadlineLevels
204 maxHeadlineLevels <- getExportSetting exportHeadlineLevels
203 header <- headlineToHeader hdln
205 header <- headlineToHeader hdln
204− listElements <- mapM headlineToBlocks headlineChildren
206+ listElements <- mapM headlineToBlocks (headlineChildren hdln)
205 let listBlock = if null listElements
207 let listBlock = if null listElements
206 then mempty
208 then mempty
207 else B.orderedList listElements
209 else B.orderedList listElements
208− let headerText = if maxHeadlineLevels == headlineLevel
210+ let headerText = if maxHeadlineLevels == headlineLevel hdln
209 then header
211 then header
210 else flattenHeader header
212 else flattenHeader header
213+ return . mconcat $
214+ [ headerText
211− return $ headerText <> headlineContents <> listBlock
215+ , headlineContents hdln
216+ , listBlock
217+ ]
212 where
218 where
213 flattenHeader :: Blocks -> Blocks
219 flattenHeader :: Blocks -> Blocks
214 flattenHeader blks =
220 flattenHeader blks =
@@ -217,27 +223,27 @@ headlineToHeaderWithList hdln@Headline {..} = do
217 _ -> mempty
223 _ -> mempty
218
224
219headlineToHeaderWithContents :: Monad m => Headline -> OrgParser m Blocks
225headlineToHeaderWithContents :: Monad m => Headline -> OrgParser m Blocks
220−headlineToHeaderWithContents hdln@Headline {..} = do
226+headlineToHeaderWithContents hdln = do
221 header <- headlineToHeader hdln
227 header <- headlineToHeader hdln
222− childrenBlocks <- mconcat <$> mapM headlineToBlocks headlineChildren
228+ childrenBlocks <- mconcat <$> mapM headlineToBlocks (headlineChildren hdln)
223− return $ header <> headlineContents <> childrenBlocks
229+ return $ header <> headlineContents hdln <> childrenBlocks
224
230
225headlineToHeader :: Monad m => Headline -> OrgParser m Blocks
231headlineToHeader :: Monad m => Headline -> OrgParser m Blocks
226−headlineToHeader Headline {..} = do
232+headlineToHeader hdln = do
227 exportTodoKeyword <- getExportSetting exportWithTodoKeywords
233 exportTodoKeyword <- getExportSetting exportWithTodoKeywords
228 exportTags <- getExportSetting exportWithTags
234 exportTags <- getExportSetting exportWithTags
229 let todoText = if exportTodoKeyword
235 let todoText = if exportTodoKeyword
230− then case headlineTodoMarker of
236+ then case headlineTodoMarker hdln of
231 Just kw -> todoKeywordToInlines kw <> B.space
237 Just kw -> todoKeywordToInlines kw <> B.space
232 Nothing -> mempty
238 Nothing -> mempty
233 else mempty
239 else mempty
234− let text = todoText <> headlineText <>
240+ let text = todoText <> headlineText hdln <>
235 if exportTags
241 if exportTags
236− then tagsToInlines headlineTags
242+ then tagsToInlines (headlineTags hdln)
237 else mempty
243 else mempty
238− let propAttr = propertiesToAttr headlineProperties
244+ let propAttr = propertiesToAttr (headlineProperties hdln)
239− attr <- registerHeader propAttr headlineText
245+ attr <- registerHeader propAttr (headlineText hdln)
240− return $ B.headerWith attr headlineLevel text
246+ return $ B.headerWith attr (headlineLevel hdln) text
241
247
242todoKeyword :: Monad m => OrgParser m TodoMarker
248todoKeyword :: Monad m => OrgParser m TodoMarker
243todoKeyword = try $ do
249todoKeyword = try $ do