From dc431745730aaac244a2e59b25f5554a654abf4c Mon Sep 17 00:00:00 2001 From: leungbk Date: Sun, 27 Jan 2019 04:52:00 +0100 Subject: Org reader: separate filtering logic from conversion function. --- src/Text/Pandoc/Readers/Org/DocumentTree.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/Text/Pandoc/Readers/Org/DocumentTree.hs') diff --git a/src/Text/Pandoc/Readers/Org/DocumentTree.hs b/src/Text/Pandoc/Readers/Org/DocumentTree.hs index 7d55892fe..131408289 100644 --- a/src/Text/Pandoc/Readers/Org/DocumentTree.hs +++ b/src/Text/Pandoc/Readers/Org/DocumentTree.hs @@ -29,6 +29,7 @@ Parsers for org-mode headlines and document subtrees module Text.Pandoc.Readers.Org.DocumentTree ( documentTree , headlineToBlocks + , filterHeadlineTree ) where import Prelude @@ -161,17 +162,18 @@ headlineToBlocks hdln = do let tags = headlineTags hdln let text = headlineText hdln let level = headlineLevel hdln - shouldNotExport <- hasDoNotExportTag tags case () of - _ | shouldNotExport -> return mempty _ | any isArchiveTag tags -> archivedHeadlineToBlocks hdln _ | isCommentTitle text -> return mempty _ | maxLevel <= level -> headlineToHeaderWithList hdln _ | otherwise -> headlineToHeaderWithContents hdln -hasDoNotExportTag :: Monad m => [Tag] -> OrgParser m Bool -hasDoNotExportTag tags = containsExcludedTag . orgStateExcludedTags <$> getState - where containsExcludedTag s = any (`Set.member` s) tags +filterHeadlineTree :: Headline -> OrgParserState -> Headline +filterHeadlineTree hdln st = + hdln { headlineChildren = + [filterHeadlineTree childHdln st | + childHdln <- headlineChildren hdln, + not $ any (`Set.member` orgStateExcludedTags st) (headlineTags childHdln)] } isArchiveTag :: Tag -> Bool isArchiveTag = (== toTag "ARCHIVE") -- cgit v1.2.3