git.iko.soy/typeable/pandoc
on master help sign in
Org reader: fix behavior for successive calls of `#+EXCLUDE_TAGS`. (#4951)

Calling `#+EXCLUDE_TAGS` multiple times should preserve the status of the previously declared tags.

commite257b54124f69682c237a5c9a5f99c5c72406c88 authorBrian Leung <bkleung89@gmail.com> dateFri 5 Oct 2018, 22:21 (8 years ago) parent6207bde
3 files changed+24−8
src/Text/Pandoc/Readers/Org/Meta.hs+11−8 src/Text/Pandoc/Readers/Org/ParserState.hs+2 test/command/4284.md+11
src/Text/Pandoc/Readers/Org/Meta.hs+11−8
@@ -159,7 +159,7 @@ optionLine = try $ do
159159 "seq_todo" -> todoSequence >>= updateState . registerTodoSequence
160160 "typ_todo" -> todoSequence >>= updateState . registerTodoSequence
161161 "macro" -> macroDefinition >>= updateState . registerMacro
162− "exclude_tags" -> excludedTagSet >>= updateState . setExcludedTags
162+ "exclude_tags" -> excludedTagList >>= updateState . setExcludedTags
163163 "pandoc-emphasis-pre" -> emphChars >>= updateState . setEmphasisPreChar
164164 "pandoc-emphasis-post" -> emphChars >>= updateState . setEmphasisPostChar
165165 _ -> mzero
@@ -192,14 +192,17 @@ parseFormat = try $ replacePlain <|> replaceUrl <|> justAppend
192192 rest = manyTill anyChar (eof <|> () <$ oneOf "\n\r")
193193 tillSpecifier c = manyTill (noneOf "\n\r") (try $ string ('%':c:""))
194194
195−excludedTagSet :: Monad m => OrgParser m (Set.Set Tag)
196−excludedTagSet = do
195+excludedTagList :: Monad m => OrgParser m [Tag]
196+excludedTagList = do
197197 skipSpaces
198− Set.fromList . map Tag <$>
199− many (orgTagWord <* skipSpaces) <* newline
200−
201−setExcludedTags :: Set.Set Tag -> OrgParserState -> OrgParserState
202−setExcludedTags tagSet st = st { orgStateExcludedTags = tagSet }
198+ map Tag <$> many (orgTagWord <* skipSpaces) <* newline
199+
200+setExcludedTags :: [Tag] -> OrgParserState -> OrgParserState
201+setExcludedTags tagList st =
202+ let finalSet = if orgStateExcludedTagsChanged st
203+ then foldr Set.insert (orgStateExcludedTags st) tagList
204+ else Set.fromList tagList
205+ in st { orgStateExcludedTags = finalSet, orgStateExcludedTagsChanged = True}
203206
204207setEmphasisPreChar :: Maybe [Char] -> OrgParserState -> OrgParserState
205208setEmphasisPreChar csMb st =
src/Text/Pandoc/Readers/Org/ParserState.hs+2
@@ -118,6 +118,7 @@ data OrgParserState = OrgParserState
118118 , orgStateEmphasisPostChars :: [Char] -- ^ Chars allowed at after emphasis
119119 , orgStateEmphasisNewlines :: Maybe Int
120120 , orgStateExcludedTags :: Set.Set Tag
121+ , orgStateExcludedTagsChanged :: Bool
121122 , orgStateExportSettings :: ExportSettings
122123 , orgStateHeaderMap :: M.Map Inlines String
123124 , orgStateIdentifiers :: Set.Set String
@@ -189,6 +190,7 @@ defaultOrgParserState = OrgParserState
189190 , orgStateEmphasisNewlines = Nothing
190191 , orgStateExportSettings = def
191192 , orgStateExcludedTags = Set.singleton $ Tag "noexport"
193+ , orgStateExcludedTagsChanged = False
192194 , orgStateHeaderMap = M.empty
193195 , orgStateIdentifiers = Set.empty
194196 , orgStateIncludeFiles = []
test/command/4284.md+11
@@ -20,6 +20,17 @@
2020[Header 1 ("this-should-appear",[],[]) [Str "This",Space,Str "should",Space,Str "appear",Space,Span ("",["tag"],[("tag-name","fawn")]) [SmallCaps [Str "fawn"]]]]
2121```
2222
23+```
24+% pandoc -f org -t native
25+#+EXCLUDE_TAGS: giraffe
26+#+EXCLUDE_TAGS: hippo
27+* This should not appear :giraffe:
28+* This should not appear :hippo:
29+* This should appear :noexport:
30+^D
31+[Header 1 ("this-should-appear",[],[]) [Str "This",Space,Str "should",Space,Str "appear",Space,Span ("",["tag"],[("tag-name","noexport")]) [SmallCaps [Str "noexport"]]]]
32+```
33+
2334```
2435% pandoc -f org -t native
2536#+EXCLUDE_TAGS: