From c8b735b8589910d682e92d3bbc758bda526687a4 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 25 Sep 2023 13:40:59 +0200 Subject: [PATCH] Add ToMarkup/ToValue instances for NonEmpty Char (#64) See #63 --- CHANGELOG | 3 +++ src/Text/Blaze.hs | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index d271e5a..7e8af48 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ # Changelog +- unreleased + * Add `ToMarkup` and `ToValue` instances for `NonEmpty Char` + - 0.8.2.8 (2021-03-04) * Bump `base` upper bound to 4.16 * Bump `tasty` upper bound to 1.5 diff --git a/src/Text/Blaze.hs b/src/Text/Blaze.hs index 54ce48b..d975041 100644 --- a/src/Text/Blaze.hs +++ b/src/Text/Blaze.hs @@ -94,6 +94,9 @@ import Data.Word (Word, Word32, Word64) #if MIN_VERSION_base(4,8,0) import Numeric.Natural (Natural) #endif +#if MIN_VERSION_base(4,9,0) +import Data.List.NonEmpty (NonEmpty (..)) +#endif import Data.Text (Text) import qualified Data.Text.Lazy as LT @@ -280,3 +283,13 @@ instance ToValue Word32 where instance ToValue Word64 where toValue = stringValue . show {-# INLINE toValue #-} + +-- Non-empty strings +#if MIN_VERSION_base(4,9,0) +instance ToMarkup (NonEmpty Char) where + toMarkup (x :| xs) = string (x : xs) + preEscapedToMarkup (x :| xs) = preEscapedString (x : xs) + +instance ToValue (NonEmpty Char) where + toValue (x :| xs) = stringValue (x : xs) +#endif