Skip to content

Commit

Permalink
Change attribute order
Browse files Browse the repository at this point in the history
To me, it makes most sense if

    img ! src "foo.png" alt "bar"

is rendered as

    <img src="foo.png" alt="bar" />

and not

    <img alt="bar" src="foo.png" />

so I changed this accordingly.
  • Loading branch information
jaspervdj committed Jul 2, 2010
1 parent f8571ad commit 410f1d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Text/Blaze/Renderer/Utf8.hs
Expand Up @@ -49,9 +49,10 @@ renderBuilder = go mempty
`mappend` attrs
`mappend` B.copyByteString (getUtf8ByteString end)
go attrs (AddAttribute key value h) =
go (attrs `mappend` B.copyByteString (getUtf8ByteString key)
go (B.copyByteString (getUtf8ByteString key)
`mappend` fromChoiceString value
`mappend` B.fromChar '"') h
`mappend` B.fromChar '"'
`mappend` attrs) h
go _ (Content content) = fromChoiceString content
go attrs (Append h1 h2) = go attrs h1 `mappend` go attrs h2
go _ (Empty _) = mempty
Expand Down
21 changes: 21 additions & 0 deletions tests/Text/Blaze/Tests.hs
Expand Up @@ -20,6 +20,7 @@ import Test.Framework.Providers.HUnit
import Test.HUnit hiding (Test)

import Text.Blaze.Html5 hiding (map)
import qualified Text.Blaze.Html5 as H
import Text.Blaze.Html5.Attributes
import Text.Blaze.Renderer.Utf8 (renderHtml)

Expand All @@ -31,6 +32,8 @@ tests = [ testProperty "left identity Monoid law" monoidLeftIdentity
, testCase "escaping case 1" escaping1
, testCase "escaping case 2" escaping2
, testProperty "post escaping characters" postEscapingCharacters
, testCase "template case 1" template1
, testCase "template case 2" template2
]

-- | The left identity Monoid law.
Expand Down Expand Up @@ -71,6 +74,24 @@ postEscapingCharacters str =
where
forbidden = map (fromIntegral . ord) "\"'<>"

-- | Simple template test case
--
template1 :: Assertion
template1 = expected @=? renderHtml template
where
expected = "<div id=\"foo\"><p>banana</p><span>banana</span></div>"
template = div ! id "foo" $ do
p "banana"
H.span "banana"

-- | Simple template test case
--
template2 :: Assertion
template2 = expected @=? renderHtml template
where
expected = "<img src=\"foo.png\" alt=\"bar\" />"
template = img ! src "foo.png" ! alt "bar"

-- Show instance for the HTML type, so we can debug.
--
instance Show Html where
Expand Down

0 comments on commit 410f1d9

Please sign in to comment.