Skip to content

Commit 999113a

Browse files
Merge pull request #38 from HenrikJoreteg/modernize
Modernize
2 parents 41355a6 + 5b97224 commit 999113a

21 files changed

+4842
-6244
lines changed

.circleci/config.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
dist

.jshintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.jshintrc

Lines changed: 0 additions & 11 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.zuul.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
# html-parse-stringify
22

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.
44

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.
66

77
"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 ?!?!"
88

99
Why yes, yes I have :)
1010

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?
1212

13-
Yes.
13+
Yes.
1414

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.
1616

1717
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.
1818

1919
Cool idea, right?!
2020

21-
## So why this?
21+
## So why this?
2222

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.
2424

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.
2626

2727
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).
2828

2929
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).
3030

31-
This lib does exactly that.
31+
This lib does exactly that.
3232

3333
It has two methods:
3434

@@ -51,13 +51,12 @@ See comments in the following example:
5151
var HTML = require('html-parse-stringify')
5252

5353
// this html:
54-
var html = '<div class="oh"><p>hi</p></div>';
54+
var html = '<div class="oh"><p>hi</p></div>'
5555

5656
// becomes this AST:
57-
var ast = HTML.parse(html);
57+
var ast = HTML.parse(html)
5858

59-
60-
console.log(ast);
59+
console.log(ast)
6160
/*
6261
{
6362
// can be `tag`, `text` or `component`
@@ -134,10 +133,14 @@ properties:
134133
- `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).
135134
- `children` - it will still have a `children` array, but it will always be empty.
136135

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.
137140

138141
## credits
139142

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.
141144

142145
## license
143146

html-parse-stringify.d.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
declare var htmlParseStringify: htmlParseStringify.htmlParseStringify;
1+
declare var htmlParseStringify: htmlParseStringify.htmlParseStringify
22

33
declare module htmlParseStringify {
4-
export interface htmlParseStringify {
5-
new (): htmlParseStringify;
6-
parse_tag(tag: string): IDoc;
7-
parse(html: string, options: IOptions): Array<any>;
8-
stringify(doc: IDoc): string;
9-
}
4+
export interface htmlParseStringify {
5+
new (): htmlParseStringify
6+
parse_tag(tag: string): IDoc
7+
parse(html: string, options: IOptions): Array<any>
8+
stringify(doc: IDoc): string
9+
}
1010

11-
export interface IDoc {
12-
type: string;
13-
content?: string;
14-
voidElement: boolean;
15-
name: string;
16-
attrs: {};
17-
children: IDoc[];
18-
}
11+
export interface IDoc {
12+
type: string
13+
content?: string
14+
voidElement: boolean
15+
name: string
16+
attrs: {}
17+
children: IDoc[]
18+
}
1919

20-
export interface IOptions {
21-
components: string[];
22-
}
20+
export interface IOptions {
21+
components: string[]
22+
}
2323
}
2424

25-
declare module "html-parse-stringify" {
26-
export = htmlParseStringify;
25+
declare module 'html-parse-stringify' {
26+
export = htmlParseStringify
2727
}

index.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/parse-tag.js

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)