move escId to BuilderQQ

This commit is contained in:
Rhiannon Morris 2020-08-03 19:37:44 +02:00
parent 981319483a
commit d2b2fdf2a5
2 changed files with 10 additions and 8 deletions

View file

@ -2,7 +2,7 @@
module BuilderQQ module BuilderQQ
(b, (b,
Builder, toLazyText, fromText, fromString, fromChar, Builder, toLazyText, fromText, fromString, fromChar,
textMap, ifJust) textMap, ifJust, escId)
where where
import Data.Char (isLower, isSpace, isDigit, isAlphaNum) import Data.Char (isLower, isSpace, isDigit, isAlphaNum)
@ -189,3 +189,12 @@ textMap f = Text.foldl' (\buf c -> buf <> f c) mempty
ifJust :: Monoid b => Maybe a -> (a -> b) -> b ifJust :: Monoid b => Maybe a -> (a -> b) -> b
ifJust x f = maybe mempty f x ifJust x f = maybe mempty f x
escId :: Text -> Builder
escId = foldMap esc1 . Text.unpack where
esc1 c | isSpace c = ""
| latin1Special c = "_"
| otherwise = fromChar c
latin1Special c =
c <= 'ÿ' && not (isAlphaNum c) && c /= '-'

View file

@ -145,13 +145,6 @@ altButton i (Image {label, path, nsfw, warning}) = [b|@4
path' = pageFile path path' = pageFile path
warning' = ifJust warning \w -> [b| data-warning="$*w"|] warning' = ifJust warning \w -> [b| data-warning="$*w"|]
escId :: Strict.Text -> Builder
escId = foldMap esc1 . Strict.unpack where
esc1 c
| Char.isSpace c = ""
| c < 'ÿ' && not (Char.isAlphaNum c || c == '-') = "_"
| otherwise = [b|$'c|]
makeTags :: [Strict.Text] -> Builder makeTags :: [Strict.Text] -> Builder
makeTags tags = makeTags tags =
if null tags then "" else [b|@4 if null tags then "" else [b|@4