From d94dc973940350c798502ddfdc80a60191032044 Mon Sep 17 00:00:00 2001
From: h7x4 <h7x4@nani.wtf>
Date: Tue, 29 Nov 2022 17:34:56 +0100
Subject: [PATCH] xmldoc2txt: fix case where multiple `<para>` are present

---
 internals/xmldoc2txt/xmldoc2txt.hs | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/internals/xmldoc2txt/xmldoc2txt.hs b/internals/xmldoc2txt/xmldoc2txt.hs
index 76679bd..d3fcddb 100644
--- a/internals/xmldoc2txt/xmldoc2txt.hs
+++ b/internals/xmldoc2txt/xmldoc2txt.hs
@@ -21,6 +21,10 @@ data PotentiallyColorizedString = PCS
 removeParagraphTags :: [TS.TagTree String] -> [TS.TagTree String]
 removeParagraphTags (TS.TagLeaf (TS.TagClose "para") : TS.TagLeaf (TS.TagOpen "para" []) : rest) =
   TS.TagLeaf (TS.TagText "\n") : removeParagraphTags rest
+  -- In this case, it will be directly followed by a <para> branch
+removeParagraphTags (TS.TagLeaf (TS.TagClose "para") : rest) = removeParagraphTags rest
+  -- In this case, it is directly behind by a <para> branch
+removeParagraphTags (TS.TagLeaf (TS.TagOpen "para" _) : rest) = removeParagraphTags rest
 removeParagraphTags (x : y : rest) = x : removeParagraphTags (y : rest)
 removeParagraphTags x = x
 
@@ -46,6 +50,11 @@ replaceTagColor (TS.TagLeaf (TS.TagText s)) =
     { colorized = putStr s,
       nonColorized = s
     }
+replaceTagColor (TS.TagBranch "para" _ inner) =
+  PCS
+    { colorized = mapM_ (colorized . replaceTagColor) inner,
+      nonColorized = concat $ map (nonColorized . replaceTagColor) inner
+    }
 replaceTagColor (TS.TagBranch "code" _ [TS.TagLeaf (TS.TagText content)]) =
   PCS
     { colorized = wrapSGR bold $ concat ["`", content, "`"],