Permalink
Browse files

allow trailing/leading spaces for text node

  • Loading branch information...
deepak1556 committed Jan 30, 2014
1 parent c2ec779 commit 40ec9a5a10d7ece33e6f9c99939e669980da2342
Showing with 12 additions and 5 deletions.
  1. +2 −2 Readme.md
  2. +4 −3 index.js
  3. +6 −0 test/domify.js
View
@@ -11,9 +11,9 @@ domify('<p>Hello <em>there</em></p>')
## Running tests
```
-$ npm i -g component-test2
+$ npm i -g component-test
$ make
-$ component test browser
+$ component-test browser
```
## License
View
@@ -47,12 +47,13 @@ map.rect = [1, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">','</svg>'
function parse(html) {
if ('string' != typeof html) throw new TypeError('String expected');
-
- html = html.replace(/^\s+|\s+$/g, ''); // Remove leading/trailing whitespace
-
+
// tag name
var m = /<([\w:]+)/.exec(html);
if (!m) return document.createTextNode(html);
+
+ html = html.replace(/^\s+|\s+$/g, ''); // Remove leading/trailing whitespace
+
var tag = m[1];
// body support
View
@@ -101,6 +101,12 @@ describe('domify(html)', function(){
assert('#text' == el.nodeName);
})
+ it('should preserve trailing/leading spaces for textElement', function(){
+ var el = domify(' text goes here ');
+ assert('#text' == el.nodeName);
+ assert(' text goes here ' == el.textContent);
+ })
+
describe('svg', function(){
it('path', function(){
assert(domify('<path></path>') instanceof SVGPathElement);

0 comments on commit 40ec9a5

Please sign in to comment.