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 83ffca7..1e8fa44 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