1+ /**
2+ * htmldiff.js is a library that compares HTML content. It creates a diff between two
3+ * HTML documents by combining the two documents and wrapping the differences with
4+ * <ins> and <del> tags. Here is a high-level overview of how the diff works.
5+ *
6+ * 1. Tokenize the before and after HTML with htmlToTokens.
7+ * 2. Generate a list of operations that convert the before list of tokens to the after
8+ * list of tokens with calculateOperations, which does the following:
9+ * a. Find all the matching blocks of tokens between the before and after lists of
10+ * tokens with findMatchingBlocks. This is done by finding the single longest
11+ * matching block with findMatch, then iteratively finding the next longest
12+ * matching blocks that precede and follow the longest matching block.
13+ * b. Determine insertions, deletions, and replacements from the matching blocks.
14+ * This is done in calculateOperations.
15+ * 3. Render the list of operations by wrapping tokens with <ins> and <del> tags where
16+ * appropriate with renderOperations.
17+ *
18+ * Example usage:
19+ *
20+ * var htmldiff = require('htmldiff.js');
21+ *
22+ * htmldiff('<p>this is some text</p>', '<p>this is some more text</p>')
23+ * == '<p>this is some <ins>more </ins>text</p>'
24+ *
25+ * htmldiff('<p>this is some text</p>', '<p>this is some more text</p>', 'diff-class')
26+ * == '<p>this is some <ins class="diff-class">more </ins>text</p>'
27+ */
128declare type Token = {
229 str : string ;
330 key : string ;
31+ styles : string [ ] ;
432} ;
533/**
634 * Creates a token that holds a string and key representation. The key is used for diffing
@@ -10,7 +38,7 @@ declare type Token = {
1038 *
1139 * @return {Object } A token object with a string and key property.
1240 */
13- export declare function createToken ( currentWord : string ) : Token ;
41+ export declare function createToken ( currentWord : string , currentStyleTags : string [ ] ) : Token ;
1442declare type Match = {
1543 segment : Segment ;
1644 length : number ;
0 commit comments