-
Notifications
You must be signed in to change notification settings - Fork 100
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
issue #8 : case insensitive css attributes, import react's attribute map... #20
Changes from 1 commit
62c970c
75b8565
e5c9f95
ef2f300
123a630
27e2281
eb412c5
9948c76
6c7c8ca
6e63dfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,19 @@ var ELEMENT_ATTRIBUTE_MAPPING = { | |
} | ||
}; | ||
|
||
var HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig'); | ||
|
||
//populate property map with ReactJS's attribute and property mappings | ||
//TODO handle/use .Properties value eg: MUST_USE_PROPERTY is not HTML attr | ||
for (var propname in HTMLDOMPropertyConfig.Properties) { | ||
if (!HTMLDOMPropertyConfig.Properties.hasOwnProperty(propname)) continue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use two spaces rather than tabs for indentation |
||
|
||
var mapFrom = HTMLDOMPropertyConfig.DOMAttributeNames[propname] || propname.toLowerCase(); | ||
|
||
if (!ATTRIBUTE_MAPPING[mapFrom]) | ||
ATTRIBUTE_MAPPING[mapFrom] = propname; | ||
} | ||
|
||
/** | ||
* Repeats a string a certain number of times. | ||
* Also: the future is bright and consists of native string repetition: | ||
|
@@ -471,6 +484,10 @@ StyleParser.prototype = { | |
var key = style.substr(0, firstColon); | ||
var value = style.substr(firstColon + 1).trim(); | ||
if (key !== '') { | ||
//if not vendor specific lowercase name | ||
//TODO better vendor prefix handling | ||
if(key[0] != '-') key = key.toLowerCase(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting:
|
||
|
||
this.styles[key] = value; | ||
} | ||
}, this); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,13 @@ describe('htmltojsx', function() { | |
expect(converter.convert('<div style="font-size: 12pt">Test</div>').trim()) | ||
.toBe('<div style={{fontSize: \'12pt\'}}>Test</div>'); | ||
}); | ||
|
||
|
||
it('should convert uppercase "style" attributes', function() { | ||
var converter = new HTMLtoJSX({ createClass: false }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use two spaces rather than tabs |
||
expect(converter.convert('<div style="TEXT-ALIGN: center">Test</div>').trim()) | ||
.toBe('<div style={{textAlign: \'center\'}}>Test</div>'); | ||
}); | ||
|
||
it('should convert "class" attribute', function() { | ||
var converter = new HTMLtoJSX({ createClass: false }); | ||
expect(converter.convert('<div class="awesome">Test</div>').trim()) | ||
|
@@ -131,7 +137,31 @@ describe('htmltojsx', function() { | |
expect(converter.convert('<label for="potato">Test</label>').trim()) | ||
.toBe('<label htmlFor="potato">Test</label>'); | ||
}); | ||
|
||
|
||
it('should convert "maxlength" attribute to "maxLength"', function() { | ||
var converter = new HTMLtoJSX({ createClass: false }); | ||
expect(converter.convert('<input maxlength=2></input>').trim()) | ||
.toBe('<input maxLength={2} />'); | ||
}); | ||
|
||
it('should convert "http-equiv" attribute to "httpEquiv"', function() { | ||
var converter = new HTMLtoJSX({ createClass: false }); | ||
expect(converter.convert('<meta http-equiv="refresh">').trim()) | ||
.toBe('<meta httpEquiv="refresh" />'); | ||
}); | ||
|
||
it('should convert "accept-charset" attribute to "acceptCharset"', function() { | ||
var converter = new HTMLtoJSX({ createClass: false }); | ||
expect(converter.convert('<form accept-charset="UTF-8">Test</form>').trim()) | ||
.toBe('<form acceptCharset="UTF-8">Test</form>'); | ||
}); | ||
|
||
it('should convert "enctype" attribute to "encType"', function() { | ||
var converter = new HTMLtoJSX({ createClass: false }); | ||
expect(converter.convert('<form method="post" enctype="application/x-www-form-urlencoded">Test</form>').trim()) | ||
.toBe('<form method="post" encType="application/x-www-form-urlencoded">Test</form>'); | ||
}); | ||
|
||
it('should maintain value-less attributes', function() { | ||
var converter = new HTMLtoJSX({ createClass: false }); | ||
expect(converter.convert('<input disabled>').trim()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put a single space after the
//
and capitalise the first word