Text inside of tags is HTML escaped.

This commit is contained in:
Danny Greg & Nathan Sobo
2012-01-19 16:36:32 -08:00
parent ba2ed50e87
commit 660beb9f65
2 changed files with 11 additions and 1 deletions

View File

@@ -30,6 +30,10 @@ describe "Builder", ->
builder.tag 'div', 22
expect(builder.toHtml()).toBe "<div>22</div>"
it "HTML escapes tag text", ->
builder.tag('div', "<br/>")
expect(builder.toHtml()).toBe "<div>&lt;br/&gt;</div>"
it "can generate tags with attributes", ->
builder.tag 'div', id: 'foo', class: 'bar'
fragment = builder.toFragment()

View File

@@ -2,5 +2,11 @@ module.exports =
class Text
constructor: (@string) ->
toHtml: -> @string
toHtml: ->
@string
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')