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
+21-9Lines changed: 21 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,16 @@
1
-
# html-parse-stringify
1
+
# html-parse-stringify2
2
+
3
+
## Quick note
4
+
5
+
This is a fork of [html-parse-stringify](https://github.com/HenrikJoreteg/html-parse-stringify) that I made because I wanted to get some important fixes into the repo and available as an NPM package and I'm not sure whether the old repo is still being maintained. Hence this. This could be temporary - I'll gladly drop this if activity picks back up on the original repo. But for now we've got a new npm package `html-parse-stringify2`. Install with:
6
+
7
+
```
8
+
npm install --save html-parse-stringify2
9
+
```
10
+
11
+
Use as documented below...
12
+
13
+
### OK, on to the original README...
2
14
3
15
This is an *experimental lightweight approach* to enable quickly parsing HTML into an AST and stringify'ing it back to the original string.
4
16
@@ -10,25 +22,25 @@ Why yes, yes I have :)
10
22
11
23
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
24
13
-
Yes.
25
+
Yes.
14
26
15
27
React.js essentially pioneered the approach. With Reach 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
28
17
29
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
30
19
31
Cool idea, right?!
20
32
21
-
## So why this?
33
+
## So why this?
22
34
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.
35
+
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
36
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.
37
+
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
38
27
39
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
40
29
41
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
42
31
-
This lib does exactly that.
43
+
This lib does exactly that.
32
44
33
45
It has two methods:
34
46
@@ -48,7 +60,7 @@ Takes an AST and turns it back into a string of HTML.
48
60
See comments in the following example:
49
61
50
62
```js
51
-
varHTML=require('html-parse-stringify')
63
+
varHTML=require('html-parse-stringify2')
52
64
53
65
// this html:
54
66
var html ='<div class="oh"><p>hi</p></div>';
@@ -65,7 +77,7 @@ console.log(ast);
65
77
66
78
// name of tag if relevant
67
79
name: 'div',
68
-
80
+
69
81
// parsed attribute object
70
82
attrs: {
71
83
class: 'oh'
@@ -137,7 +149,7 @@ properties:
137
149
138
150
## credits
139
151
140
-
If this sounds interesting you should probably follow [@HenrikJoreteg](http://twitter.com/henrikjoreteg) and [@Philip_Roberts](twitter.com/philip_roberts) on twitter to see how this all turns out.
152
+
If this sounds interesting you should probably follow [@HenrikJoreteg](http://twitter.com/henrikjoreteg) and [@Philip_Roberts](twitter.com/philip_roberts) on twitter to see how this all turns out.
0 commit comments