You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-14Lines changed: 17 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,34 +1,34 @@
1
1
# html-parse-stringify
2
2
3
-
This is an *experimental lightweight approach* to enable quickly parsing HTML into an AST and stringify'ing it back to the original string.
3
+
This is an _experimental lightweight approach_ to enable quickly parsing HTML into an AST and stringify'ing it back to the original string.
4
4
5
-
As it turns out, if you can make a the simplifying assumptions about HTML that all tags must be closed or self-closing. Which is OK for *this* particular application. You can write a super light/fast parser in JS with regex.
5
+
As it turns out, if you can make a the simplifying assumptions about HTML that all tags must be closed or self-closing. Which is OK for _this_ particular application. You can write a super light/fast parser in JS with regex.
6
6
7
7
"Why on earth would you do this?! Haven't you read: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags ?!?!"
8
8
9
9
Why yes, yes I have :)
10
10
11
-
But the truth is. If you *could* do this in a whopping grand total of ~600 bytes (min+gzip) as this repo shows. It potentially enables DOM diffing based on a HTML strings to be super light and fast in a browser. What is that you say? DOM-diffing?
11
+
But the truth is. If you _could_ do this in a whopping grand total of ~600 bytes (min+gzip) as this repo shows. It potentially enables DOM diffing based on a HTML strings to be super light and fast in a browser. What is that you say? DOM-diffing?
12
12
13
-
Yes.
13
+
Yes.
14
14
15
-
React.js essentially pioneered the approach. With React you render to a "virtual DOM" whenever you want to, and the virtual DOM can then diff against the real DOM (or the last virtual DOM) and then turn that diff into whatever transformations are necessary to get the *real* DOM to match what you rendered as efficiently as possible.
15
+
React.js essentially pioneered the approach. With React you render to a "virtual DOM" whenever you want to, and the virtual DOM can then diff against the real DOM (or the last virtual DOM) and then turn that diff into whatever transformations are necessary to get the _real_ DOM to match what you rendered as efficiently as possible.
16
16
17
17
As a result, when you're building a single page app, you don't have to worry so much about bindings. Instead, you simple re-render to the virtual DOM whenever you know something's changed. All of a sudden being able to have `change` events for individual properties becomes less important, instead you can just reference those values in your template whenever you think something changed.
18
18
19
19
Cool idea, right?!
20
20
21
-
## So why this?
21
+
## So why this?
22
22
23
-
Well, there are other things React expects me to do if I use it that I don't like. Such as the custom templating and syntax you have to use.
23
+
Well, there are other things React expects me to do if I use it that I don't like. Such as the custom templating and syntax you have to use.
24
24
25
-
If, hypothetically, you could instead diff an HTML string (generated by *whatever* templating language of your choice) against the DOM, then you'd get the same benefit, sans React's impositions.
25
+
If, hypothetically, you could instead diff an HTML string (generated by _whatever_ templating language of your choice) against the DOM, then you'd get the same benefit, sans React's impositions.
26
26
27
27
This may all turn out to be a bad idea altogether, but initial results seem promising when paired with [virtual-dom](https://github.com/Matt-Esch/virtual-dom).
28
28
29
29
But you can't just diff HTML strings, as simple strings, very easily, in order to diff two HTML node trees you have to first turn that string into a tree structure of some sort. Typically, the thing you generate from parsing something like this is called an AST (abstract syntax tree).
30
30
31
-
This lib does exactly that.
31
+
This lib does exactly that.
32
32
33
33
It has two methods:
34
34
@@ -51,13 +51,12 @@ See comments in the following example:
51
51
varHTML=require('html-parse-stringify')
52
52
53
53
// this html:
54
-
var html ='<div class="oh"><p>hi</p></div>';
54
+
var html ='<div class="oh"><p>hi</p></div>'
55
55
56
56
// becomes this AST:
57
-
var ast =HTML.parse(html);
57
+
var ast =HTML.parse(html)
58
58
59
-
60
-
console.log(ast);
59
+
console.log(ast)
61
60
/*
62
61
{
63
62
// can be `tag`, `text` or `component`
@@ -134,10 +133,14 @@ properties:
134
133
-`voidElement` - `true` or `false`. Whether this tag is a known void element as defined by [spec](http://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements).
135
134
-`children` - it will still have a `children` array, but it will always be empty.
136
135
136
+
## changelog
137
+
138
+
-`2.0.0` updated to more modern dependencies/build system. Switched to prettier, etc. No big feature differences, just new build system/project structure.
139
+
-`1.0.0 - 1.0.3` no big changes, bug fixes and speed improvements.
137
140
138
141
## credits
139
142
140
-
If this sounds interesting you should probably follow [@HenrikJoreteg](https://twitter.com/henrikjoreteg) and [@Philip_Roberts](https://twitter.com/philip_roberts) on twitter to see how this all turns out.
143
+
If this sounds interesting you should probably follow [@HenrikJoreteg](https://twitter.com/henrikjoreteg) and [@Philip_Roberts](https://twitter.com/philip_roberts) on twitter to see how this all turns out.
0 commit comments