Skip to content

Commit 41b6cdb

Browse files
authored
Merge pull request mblink#5 from mblink/ks-style-tags-refactor
overhaul style tag handling
2 parents 21f53d4 + 9e923c3 commit 41b6cdb

12 files changed

+477
-314
lines changed

.eslintrc.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ module.exports = {
22
env: {
33
es6: true,
44
node: true,
5+
mocha: true,
56
},
67
extends: [
78
"eslint:recommended",
89
],
10+
globals: {
11+
expect: false,
12+
},
913
parser: "@typescript-eslint/parser",
1014
parserOptions: {
1115
project: [

dist/htmldiff.d.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
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+
*/
128
declare 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;
1442
declare type Match = {
1543
segment: Segment;
1644
length: number;

0 commit comments

Comments
 (0)