-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClassName can be invalid #16
Comments
|
Is the purpose of In that case, yes, |
Yeah, that's about right. A
It uses the Maybe the right place to put escaping is in Maybe it might make sense to rename a few things to clear this up? |
I think The next question I have is related to using
What do you think? |
I realised I made an assumption about how we are using classes that is incorrect. We are not combining classes, just creating unique class names. In other words, we currently create a class once and never update the values of that class. Interestingly, I think the fix for #17 is changing how we handle classes. To explain: Currently we can have multiple classes for each element where those classes are shared among multiple elements. Each class can have multiple attributes and those attributes can clash #17. The fix is either:
|
I spent some more time looking at the blaze-markup source and realised I have a misconception on how to use data ChoiceString
-- | Static data
= Static {-# UNPACK #-} !StaticString
-- | A Haskell String
| String String
-- | A Text value
| Text Text
-- | An encoded bytestring
| ByteString B.ByteString
-- | A pre-escaped string
| PreEscaped ChoiceString
-- | External data in style/script tags, should be checked for validity
| External ChoiceString
-- | Concatenation
| AppendChoiceString ChoiceString ChoiceString
-- | Empty string
| EmptyChoiceString
instance Semigroup ChoiceString where
(<>) = AppendChoiceString
{-# INLINE (<>) #-}
instance IsString ChoiceString where
fromString = String
{-# INLINE fromString #-} The key is their fromChoiceString :: ChoiceString -- ^ String to render
-> Builder -- ^ Resulting builder
fromChoiceString (Static s) = B.copyByteString $ getUtf8ByteString s
fromChoiceString (String s) = B.fromHtmlEscapedString s
fromChoiceString (Text s) = B.fromHtmlEscapedText s
fromChoiceString (ByteString s) = B.fromByteString s
fromChoiceString (PreEscaped x) = case x of
String s -> B.fromString s
Text s -> B.fromText s
s -> fromChoiceString s
fromChoiceString (External x) = case x of
-- Check that the sequence "</" is *not* in the external data.
String s -> if "</" `isInfixOf` s then mempty else B.fromString s
Text s -> if "</" `T.isInfixOf` s then mempty else B.fromText s
ByteString s -> if "</" `S.isInfixOf` s then mempty else B.fromByteString s
s -> fromChoiceString s
fromChoiceString (AppendChoiceString x y) =
fromChoiceString x `mappend` fromChoiceString y
fromChoiceString EmptyChoiceString = mempty
{-# INLINE fromChoiceString #-} When you look at the definition of ByteString's newtype Builder = Builder (forall r. BuildStep r -> BuildStep r) It is a function to combine |
Several of the
ToClassName
instances return non-valid class names by starting with a number:We can fix this by adding a "_" or escaping the number if the class name start with a number and writing the semigroup instance to ensure invalid class names are not created. It is also possible to remove unnecessary escaped characters with the semigroup instance. Valid class names are as follows:
The text was updated successfully, but these errors were encountered: