@@ -40,7 +40,7 @@ equals to
4040## Install
4141
4242``` bash
43- $ npm install html-differ
43+ $ npm install html-differ -g
4444```
4545
4646## Usage
@@ -52,69 +52,84 @@ $ npm install html-differ
5252** html-differ.diffHtml** <br >
5353** @param ** * String* - the 1-st ``` html-code ``` <br >
5454** @param ** * String* - the 2-nd ``` html-code ``` <br >
55- ** @param ** * {Object}* - options:
56- * sets what respective attributes are always considered to be equal<br >
57- (for example, ``` ignoreHtmlAttrs: ['id', 'for'] ``` , optional parameter)
58- * sets what respective attributes' content will be compared as ``` JSONs ``` , not as ``` strings ``` <br >
59- (for example, ``` compareHtmlAttrsAsJSON: ['data-bem'] ``` , optional parameter)
60-
61- ** @returns ** * {Object}* - see [ here] ( https://github.com/kpdecker/jsdiff#examples ) .
55+ ** @returns ** * {Array of objects}* - see [ here] ( https://github.com/kpdecker/jsdiff#examples )
6256
6357** html-differ.isEqual** <br >
6458This method has the same parameters as the previous one, but returns ``` Boolean ``` .
6559
6660####diff-logger####
6761
68- ** diff-logger.log** <br >
69- Pretty logging of diffs. Red text should be removed from the first html relative to the second one, green text should be added.<br >
62+ ** diff-logger.getDiffText** <br >
7063** @param ** * {Object}* - the result of the work of the method ``` html-differ.diffHtml ``` <br >
7164** @param ** * {Object}* - options:<br >
72- * the number of characters, which will be logged before the diff and after it<br >
73- (for example, ``` showCharacters: 20 ``` , default - ``` 20 ``` , optional parameter)
74-
75- ####For BEM####
65+ * the number of characters before the diff and after it<br >
66+ (for example, ``` charsAroundDiff: 20 ``` , default - ``` 20 ``` , optional parameter)<br >
7667
77- ** html-differ.bemDiff** <br >
78- This method does ``` diff + log ``` .<br >
79- The options are predefined:
80- * ``` ignoreHtmlAttrs: ['id', 'for'] ``` <br >
81- * ``` compareHtmlAttrsAsJSON: ['data-bem'] ``` <br >
82- * ``` showCharacters: 20 ```
68+ ** @returns ** * {String}* - diffs
8369
84- ** @param ** * String* - the 1-st ``` html-code ``` <br >
85- ** @param ** * String* - the 2-nd ``` html-code ```
70+ ** diff-logger.log** <br >
71+ Pretty logging of diffs. Red text should be removed from the first html relative to the second one, green text should be added.<br >
72+ This method has the same parameters as the previous one.
8673
8774####Example####
8875
8976``` js
9077var fs = require (' fs' ),
91- htmlDiffer = require (' html-differ' ),
78+ HtmlDiffer = require (' html-differ' ). HtmlDiffer ,
9279 diffLogger = require (' html-differ/lib/diff-logger' );
9380
9481var html1 = fs .readFileSync (' 1.html' , ' utf-8' ),
9582 html2 = fs .readFileSync (' 2.html' , ' utf-8' );
9683
97- var res = htmlDiffer .isEqual (html1, html2, { ignoreHtmlAttrs: [' id' , ' for' ] } );
84+ var options = {
85+ ignoreHtmlAttrs: [],
86+ compareHtmlAttrsAsJSON: [],
87+ verbose: true ,
88+ ignoreWhitespace: true ,
89+ bem: false
90+ }
9891
99- // common case
100- diffLogger .log (htmlDiffer .diffHtml (html1, html2, { ignoreHtmlAttrs: [' id' , ' for' ], compareHtmlAttrsAsJSON: [' data-bem' ] }), { showCharacters: 20 });
92+ var htmlDiffer = new HtmlDiffer (options);
10193
102- // for BEM (you can not set options)
103- htmlDiffer .bemDiff (html1, html2);
104- ```
94+ var diff = htmlDiffer .diffHtml (html1, html2);
10595
106- ###As a program###
96+ var isEqual = htmlDiffer . isEqual (html1, html2);
10797
108- Go to the root folder:
98+ var res = diffLogger . getDiffText (diff, { charsAroundDiff : 20 });
10999
110- ``` bash
111- $ cd html-differ
100+ diffLogger .log (diff, { charsAroundDiff: 20 });
112101```
113102
114- To run as a program use ``` bin/html-differ ``` .
103+ where ``` options ``` is the ``` Object ``` :
104+
105+ * ``` ignoreHtmlAttrs: [ Array ] ``` - sets what respective attributes are always considered to be equal
106+
107+ * ``` compareHtmlAttrsAsJSON: [ Array ] ``` - sets what respective attributes' content will be compared as ``` JSONs ``` , not as ``` Strings ```
108+
109+ * ``` verbose: Boolean ``` - see [ here] ( https://github.com/tautologistics/node-htmlparser#option-verbose )
110+
111+ * ``` ignoreWhitespace: Boolean ``` - see [ here] ( https://github.com/tautologistics/node-htmlparser#option-ignorewhitespace )
112+
113+ * ``` bem: Boolean ``` - predefined options for BEM
114+
115+
116+ ####For BEM####
117+ Options for BEM are predefined:
118+ * ``` ignoreHtmlAttrs: ['id', 'for'] ```
119+
120+ * ``` compareHtmlAttrsAsJSON: ['data-bem', 'onclick', 'ondblclick'] ```
121+
122+ * ``` verbose: true ```
123+
124+ * ``` ignoreWhitespace: true ```
125+
126+ * ``` charsAroundDiff: 20 ```
127+
128+
129+ ###As a program###
115130
116131``` bash
117- $ bin/ html-differ --help
132+ $ html-differ --help
118133Compares two html-files
119134Red text should be removed from the first html relative to the second one, green text should be added
120135
@@ -125,6 +140,7 @@ Options:
125140 -h, --help : Help
126141 -v, --version : Shows the version number
127142 --config=CONFIG : Path to configuration JSON-file
143+ --chars-around-diff=CHARSAROUNDDIFF : The number of characters around diff
128144
129145Arguments:
130146 PATH1 : Path to the 1-st html-file (required)
@@ -136,7 +152,7 @@ Arguments:
136152``` bash
137153$ bin/html-differ path/to/html1 path/to/html2
138154
139- $ bin/html-differ --config=path/to/config path/to/html1 path/to/html2
155+ $ bin/html-differ --config=path/to/config path/to/html1 path/to/html2 --chars-around-diff=20
140156```
141157
142158####Configuration file###
@@ -145,18 +161,14 @@ Study the following ```config.json```:
145161
146162``` js
147163{
148- " ignoreHtmlAttrs" : [" id" , " for" ],
149- " compareHtmlAttrsAsJSON" : [" data-bem" ],
150- " showCharacters" : 20
164+ " ignoreHtmlAttrs" : [],
165+ " compareHtmlAttrsAsJSON" : [],
166+ " verbose" : true ,
167+ " ignoreWhitespace" : true ,
168+ " bem" : false
151169}
152170```
153171
154- * ``` ignoreHtmlAttrs: [ Array ] ``` - sets what respective attributes are always considered to be equal
155-
156- * ``` compareHtmlAttrsAsJSON: [ Array ] ``` - sets what respective attributes' content will be compared as ``` JSONs ``` , not as ``` strings ```
157-
158- * ``` showCharacters: Number ``` - the number of characters, which will be logged before the diff and after it
159-
160172## License
161173
162174[ MIT License] ( http://en.wikipedia.org/wiki/MIT_License )
0 commit comments