@@ -34,8 +34,6 @@ If you are using Symfony, you can use the [caxy/HtmlDiffBundle][htmldiffbundle]
3434
3535## Usage
3636
37- (WIP)
38-
3937``` php
4038use Caxy\HtmlDiff\HtmlDiff;
4139
@@ -45,7 +43,116 @@ $content = $htmlDiff->build();
4543
4644## Configuration
4745
48- WIP
46+ The configuration for HtmlDiff is contained in the ` Caxy\HtmlDiff\HtmlDiffConfig ` class.
47+
48+ There are two ways to set the configuration:
49+ 1 . [ Configure an Existing HtmlDiff Object] ( #configure-an-existing-htmldiff-object )
50+ 2 . [ Create and Use an HtmlDiffConfig Object] ( #create-and-use-an-htmldiffconfig-object )
51+
52+ #### Configure an Existing HtmlDiff Object
53+
54+ When a new ` HtmlDiff ` object is created, it creates a ` HtmlDiffConfig ` object with the default configuration.
55+ You can change the configuration using setters on the object:
56+
57+ ``` php
58+ use Caxy\HtmlDiff\HtmlDiff;
59+
60+ // ...
61+
62+ $htmlDiff = new HtmlDiff($oldHtml, $newHtml);
63+
64+ // Set some of the configuration options.
65+ $htmlDiff->getConfig()
66+ ->setMatchThreshold(80)
67+ ->setInsertSpaceInReplace(true)
68+ ;
69+
70+ // Calculate the differences using the configuration and get the html diff.
71+ $content = $htmlDiff->build();
72+
73+ // ...
74+
75+ ```
76+
77+ #### Create and Use an HtmlDiffConfig Object
78+
79+ You can also set the configuration by creating an instance of
80+ ` Caxy\HtmlDiff\HtmlDiffConfig ` and using it when creating a new ` HtmlDiff `
81+ object using ` HtmlDiff::create ` .
82+
83+ This is useful when creating more than one instance of ` HtmlDiff ` :
84+
85+ ``` php
86+ use Caxy\HtmlDiff\HtmlDiff;
87+ use Caxy\HtmlDiff\HtmlDiffConfig;
88+
89+ // ...
90+
91+ $config = new HtmlDiffConfig();
92+ $config
93+ ->setMatchThreshold(95)
94+ ->setInsertSpaceInReplace(true)
95+ ;
96+
97+ // Create an HtmlDiff object with the custom configuration.
98+ $firstHtmlDiff = HtmlDiff::create($oldHtml, $newHtml, $config);
99+ $firstContent = $firstHtmlDiff->build();
100+
101+ $secondHtmlDiff = HtmlDiff::create($oldHtml2, $newHtml2, $config);
102+ $secondHtmlDiff->getConfig()->setMatchThreshold(50);
103+
104+ $secondContent = $secondHtmlDiff->build();
105+
106+ // ...
107+ ```
108+
109+ #### Full Configuration with Defaults:
110+
111+ ``` php
112+
113+ $config = new HtmlDiffConfig();
114+ $config
115+ // Percentage required for list items to be considered a match.
116+ ->setMatchThreshold(80)
117+
118+ // Set the encoding of the text to be diffed.
119+ ->setEncoding('UTF-8')
120+
121+ // If true, a space will be added between the <del > and <ins > tags of text that was replaced.
122+ ->setInsertSpaceInReplace(false)
123+
124+ // Option to disable the new Table Diffing feature and treat tables as regular text.
125+ ->setUseTableDiffing(true)
126+
127+ // Pass an instance of \Doctrine\Common\Cache\Cache to cache the calculated diffs.
128+ ->setCacheProvider(null)
129+
130+ // Group consecutive deletions and insertions instead of showing a deletion and insertion for each word individually.
131+ ->setGroupDiffs(true)
132+
133+ // List of characters to consider part of a single word when in the middle of text.
134+ ->setSpecialCaseChars(array('.', ',', '(', ')', '\''))
135+
136+ // List of tags to treat as special case tags.
137+ ->setSpecialCaseTags(array('strong', 'b', 'i', 'big', 'small', 'u', 'sub', 'sup', 'strike', 's', 'p'))
138+
139+ // List of tags (and their replacement strings) to be diffed in isolation.
140+ ->setIsolatedDiffTags(array(
141+ 'ol' => '[[REPLACE_ORDERED_LIST]]',
142+ 'ul' => '[[REPLACE_UNORDERED_LIST]]',
143+ 'sub' => '[[REPLACE_SUB_SCRIPT]]',
144+ 'sup' => '[[REPLACE_SUPER_SCRIPT]]',
145+ 'dl' => '[[REPLACE_DEFINITION_LIST]]',
146+ 'table' => '[[REPLACE_TABLE]]',
147+ 'strong' => '[[REPLACE_STRONG]]',
148+ 'b' => '[[REPLACE_B]]',
149+ 'em' => '[[REPLACE_EM]]',
150+ 'i' => '[[REPLACE_I]]',
151+ 'a' => '[[REPLACE_A]]',
152+ ))
153+ ;
154+
155+ ```
49156
50157## Contributing
51158
0 commit comments