git.iko.soy/typeable/pandoc
on master help sign in
Org reader: drop trees with a :noexport: tag
385dcf5Albert Krewinkel
src/Text/Pandoc/Readers/Org.hs+12−4
@@ -84,13 +84,21 @@ dropCommentTrees [] = []
84dropCommentTrees blks@(b:bs) =
84dropCommentTrees blks@(b:bs) =
85 maybe blks (flip dropUntilHeaderAboveLevel bs) $ commentHeaderLevel b
85 maybe blks (flip dropUntilHeaderAboveLevel bs) $ commentHeaderLevel b
86
86
87−-- | Return the level of a header starting a comment tree and Nothing
87+-- | Return the level of a header starting a comment or :noexport: tree and
88−-- otherwise.
88+-- Nothing otherwise.
89commentHeaderLevel :: Block -> Maybe Int
89commentHeaderLevel :: Block -> Maybe Int
90commentHeaderLevel blk =
90commentHeaderLevel blk =
91 case blk of
91 case blk of
92− (Header level _ ((Str "COMMENT"):_)) -> Just level
92+ (Header level _ ((Str "COMMENT"):_)) -> Just level
93+ (Header level _ title) | hasNoExportTag title -> Just level
93− _ -> Nothing
94+ _ -> Nothing
95+ where
96+ hasNoExportTag :: [Inline] -> Bool
97+ hasNoExportTag = any isNoExportTag
98+
99+ isNoExportTag :: Inline -> Bool
100+ isNoExportTag (Span ("", ["tag"], [("data-tag-name", "noexport")]) []) = True
101+ isNoExportTag _ = False
94
102
95-- | Drop blocks until a header on or above the given level is seen
103-- | Drop blocks until a header on or above the given level is seen
96dropUntilHeaderAboveLevel :: Int -> [Block] -> [Block]
104dropUntilHeaderAboveLevel :: Int -> [Block] -> [Block]
tests/Tests/Readers/Org.hs+7
@@ -524,6 +524,13 @@ tests =
524 "* COMMENT Test" =?>
524 "* COMMENT Test" =?>
525 (mempty::Blocks)
525 (mempty::Blocks)
526
526
527+ , "Tree with :noexport:" =:
528+ unlines [ "* Should be ignored :archive:noexport:old:"
529+ , "** Old stuff"
530+ , " This is not going to be exported"
531+ ] =?>
532+ (mempty::Blocks)
533+
527 , "Paragraph starting with an asterisk" =:
534 , "Paragraph starting with an asterisk" =:
528 "*five" =?>
535 "*five" =?>
529 para "*five"
536 para "*five"