xmldoc2txt: fix case where multiple `<para>` are present

This commit is contained in:
Oystein Kristoffer Tveit 2022-11-29 17:34:56 +01:00
parent 067f44413f
commit d94dc97394
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
1 changed files with 9 additions and 0 deletions

View File

@ -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, "`"],