From f0675acff032a2558d0d7b303c0b8199fd17c162 Mon Sep 17 00:00:00 2001
From: Alexander Foremny <aforemny@posteo.de>
Date: Thu, 9 Nov 2023 15:35:32 +0100
Subject: fix extracting tags from code

---
 app/Issue/Tag.hs | 35 ++++++++++++++++++++++-------------
 app/Main.hs      |  9 ---------
 2 files changed, 22 insertions(+), 22 deletions(-)

(limited to 'app')

diff --git a/app/Issue/Tag.hs b/app/Issue/Tag.hs
index 2f584b3..29c69d9 100644
--- a/app/Issue/Tag.hs
+++ b/app/Issue/Tag.hs
@@ -8,6 +8,7 @@ module Issue.Tag
   )
 where
 
+import CMark qualified as D
 import Data.Binary (Binary)
 import Data.Maybe (catMaybes, mapMaybe)
 import Data.Text (Text, pack)
@@ -34,19 +35,27 @@ tagValuesOf key =
     )
 
 extractTags :: Text -> [Tag]
-extractTags =
-  catMaybes
-    . map
-      ( ( \case
-            ((T.uncons -> Just ('@', k)) : v) ->
-              case T.strip (T.unwords v) of
-                "" -> Just (Tag k Nothing)
-                v' -> Just (Tag k (Just v'))
-            _ -> Nothing
-        )
-          . T.words
-      )
-    . T.lines
+extractTags = collect . D.commonmarkToNode []
+  where
+    collect (D.Node _ (D.CODE _) _) = []
+    collect (D.Node _ (D.CODE_BLOCK _ _) _) = []
+    collect (D.Node _ (D.TEXT s) ns) = extract s ++ concatMap collect ns
+    collect (D.Node _ _ []) = []
+    collect (D.Node _ _ ns) = concatMap collect ns
+
+    extract =
+      catMaybes
+        . map
+          ( ( \case
+                ((T.uncons -> Just ('@', k)) : v) ->
+                  case T.strip (T.unwords v) of
+                    "" -> Just (Tag k Nothing)
+                    v' -> Just (Tag k (Just v'))
+                _ -> Nothing
+            )
+              . T.words
+          )
+        . T.lines
 
 internalTags :: Text -> Maybe Provenance -> [T.Text] -> [Tag]
 internalTags title provenance' markers =
diff --git a/app/Main.hs b/app/Main.hs
index 1aff48b..e1ae560 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -38,7 +38,6 @@
 -- I am neither for nor against replacing `mdcat` with our own markdown
 -- rendering.
 --
--- @supersedes exclude-tags-in-code-blocks
 -- @supersedes make-show-page-able
 -- @supersedes only-separate-generated-tags-with-a-blank-line-when-description-does-not-end-with-tags
 --
@@ -175,14 +174,6 @@
 -- @should-automatically-generated-ids-be-random, as long as they are an
 -- additional mechanisam (so that we can ditch them, should they not work out).
 
--- FIXME Exclude tags in code blocks
---
--- Tags which appear in markdown code blocks should not be considered
--- tags.
---
--- @topic tags
--- @topic markdown
-
 -- TODO Only separate generated tags with a blank line when description does not end with tags
 --
 -- An issue like
-- 
cgit v1.2.3