git.iko.soy/typeable/pandoc
on master help sign in
Org reader: drop trees with a :noexport: tag

Trees having a `:noexport:` tag set are not exported. This mirrors default Emacs Org-Mode behavior.

commit385dcf5b99331d392422062586d936af87ee0e46 authorAlbert Krewinkel <albert@zeitkraut.de> dateSat 23 May 2015, 14:20 (11 years ago) parentd8e4a8b
2 files changed+19−4
src/Text/Pandoc/Readers/Org.hs+12−4 tests/Tests/Readers/Org.hs+7
src/Text/Pandoc/Readers/Org.hs+12−4
@@ -84,13 +84,21 @@ dropCommentTrees [] = []
8484dropCommentTrees blks@(b:bs) =
8585 maybe blks (flip dropUntilHeaderAboveLevel bs) $ commentHeaderLevel b
8686
87−-- | Return the level of a header starting a comment tree and Nothing
88−-- otherwise.
87+-- | Return the level of a header starting a comment or :noexport: tree and
88+-- Nothing otherwise.
8989commentHeaderLevel :: Block -> Maybe Int
9090commentHeaderLevel blk =
9191 case blk of
92− (Header level _ ((Str "COMMENT"):_)) -> Just level
93− _ -> Nothing
92+ (Header level _ ((Str "COMMENT"):_)) -> Just level
93+ (Header level _ title) | hasNoExportTag title -> Just level
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
94102
95103-- | Drop blocks until a header on or above the given level is seen
96104dropUntilHeaderAboveLevel :: Int -> [Block] -> [Block]
tests/Tests/Readers/Org.hs+7
@@ -524,6 +524,13 @@ tests =
524524 "* COMMENT Test" =?>
525525 (mempty::Blocks)
526526
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+
527534 , "Paragraph starting with an asterisk" =:
528535 "*five" =?>
529536 para "*five"