git.iko.soy/typeable/pandoc
on master help sign in
Org reader: separate filtering logic from conversion function.
commitdc431745730aaac244a2e59b25f5554a654abf4c authorleungbk <bkleung89@gmail.com> dateSun 27 Jan 2019, 04:52 (8 years ago) parentc9454a4
2 files changed+11−8
src/Text/Pandoc/Readers/Org/Blocks.hs+4−3 src/Text/Pandoc/Readers/Org/DocumentTree.hs+7−5
src/Text/Pandoc/Readers/Org/Blocks.hs+4−3
@@ -34,7 +34,7 @@ module Text.Pandoc.Readers.Org.Blocks
3434
3535import Prelude
3636import Text.Pandoc.Readers.Org.BlockStarts
37−import Text.Pandoc.Readers.Org.DocumentTree (documentTree, headlineToBlocks)
37+import Text.Pandoc.Readers.Org.DocumentTree (documentTree, headlineToBlocks, filterHeadlineTree)
3838import Text.Pandoc.Readers.Org.Inlines
3939import Text.Pandoc.Readers.Org.Meta (metaExport, metaKey, metaLine)
4040import Text.Pandoc.Readers.Org.ParserState
@@ -64,9 +64,10 @@ import qualified Text.Pandoc.Walk as Walk
6464-- | Get a list of blocks.
6565blockList :: PandocMonad m => OrgParser m [Block]
6666blockList = do
67− headlines <- documentTree blocks inline
67+ fHeadlineTree <- documentTree blocks inline
6868 st <- getState
69− headlineBlocks <- headlineToBlocks $ runF headlines st
69+ let headlineTree = runF fHeadlineTree st
70+ headlineBlocks <- headlineToBlocks $ filterHeadlineTree headlineTree st
7071 -- ignore first headline, it's the document's title
7172 return . drop 1 . B.toList $ headlineBlocks
7273
src/Text/Pandoc/Readers/Org/DocumentTree.hs+7−5
@@ -29,6 +29,7 @@ Parsers for org-mode headlines and document subtrees
2929module Text.Pandoc.Readers.Org.DocumentTree
3030 ( documentTree
3131 , headlineToBlocks
32+ , filterHeadlineTree
3233 ) where
3334
3435import Prelude
@@ -161,17 +162,18 @@ headlineToBlocks hdln = do
161162 let tags = headlineTags hdln
162163 let text = headlineText hdln
163164 let level = headlineLevel hdln
164− shouldNotExport <- hasDoNotExportTag tags
165165 case () of
166− _ | shouldNotExport -> return mempty
167166 _ | any isArchiveTag tags -> archivedHeadlineToBlocks hdln
168167 _ | isCommentTitle text -> return mempty
169168 _ | maxLevel <= level -> headlineToHeaderWithList hdln
170169 _ | otherwise -> headlineToHeaderWithContents hdln
171170
172−hasDoNotExportTag :: Monad m => [Tag] -> OrgParser m Bool
173−hasDoNotExportTag tags = containsExcludedTag . orgStateExcludedTags <$> getState
174− where containsExcludedTag s = any (`Set.member` s) tags
171+filterHeadlineTree :: Headline -> OrgParserState -> Headline
172+filterHeadlineTree hdln st =
173+ hdln { headlineChildren =
174+ [filterHeadlineTree childHdln st |
175+ childHdln <- headlineChildren hdln,
176+ not $ any (`Set.member` orgStateExcludedTags st) (headlineTags childHdln)] }
175177
176178isArchiveTag :: Tag -> Bool
177179isArchiveTag = (== toTag "ARCHIVE")