Skip to content
Snippets Groups Projects
Verified Commit 6c04d58a authored by Legy (Beini)'s avatar Legy (Beini)
Browse files

Improve compatibility with some pango parsers by always escaping complex chars

parent e2969310
No related branches found
No related tags found
1 merge request!9Ags ready
......@@ -45,6 +45,7 @@ import QBar.Prelude
import Control.Lens
import Data.Aeson
import Data.Char
import Data.Int (Int64)
import Data.Text.Lazy qualified as T
import GHC.Generics
......@@ -209,8 +210,31 @@ printedLength (BlockText b) = sum . map segmentLength $ b
mkText :: Bool -> Importance -> T.Text -> BlockText
mkText active importance segmentText = BlockText [BlockTextSegment { segmentText = pangoFriendly segmentText, active, importance }]
where
toHex :: Int -> T.Text
toHex 1 = "1"
toHex 2 = "2"
toHex 3 = "3"
toHex 4 = "4"
toHex 5 = "5"
toHex 6 = "6"
toHex 7 = "7"
toHex 8 = "8"
toHex 9 = "9"
toHex 10 = "A"
toHex 11 = "B"
toHex 12 = "C"
toHex 13 = "D"
toHex 14 = "E"
toHex 15 = "F"
toHex x
| x <= 0 = "0"
| otherwise = toHex (div x 16) <> toHex (mod x 16)
pangoFriendlyIcon :: Char -> T.Text
pangoFriendlyIcon x
| isAlphaNum x || isAscii x = T.singleton x
| otherwise = "&#x" <> toHex (ord x) <> ";"
pangoFriendly :: T.Text -> T.Text
pangoFriendly = T.replace "<" "&lt;" . T.replace ">" "&gt;" . T.replace "&" "&amp;"
pangoFriendly = T.concatMap pangoFriendlyIcon . T.replace "<" "&lt;" . T.replace ">" "&gt;" . T.replace "&" "&amp;"
activeImportantText :: Importance -> T.Text -> BlockText
activeImportantText = mkText True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment