@@ -152,6 +152,7 @@ static void wrapInTag(List<String> sequence, int startPosition,
152152private final Function <String ,String >lineNormalizer ;
153153
154154private final boolean showInlineDiffs ;
155+ private final boolean rawValues ;
155156
156157private DiffRowGenerator (Builder builder ) {
157158showInlineDiffs =builder .showInlineDiffs ;
@@ -164,6 +165,7 @@ private DiffRowGenerator(Builder builder) {
164165equalizer =ignoreWhiteSpaces ?IGNORE_WHITESPACE_EQUALIZER :DEFAULT_EQUALIZER ;
165166reportLinesUnchanged =builder .reportLinesUnchanged ;
166167lineNormalizer =builder .lineNormalizer ;
168+ rawValues =builder .rawValues ;
167169
168170Objects .requireNonNull (inlineDiffSplitter );
169171Objects .requireNonNull (lineNormalizer );
@@ -198,14 +200,14 @@ public List<DiffRow> generateDiffRows(final List<String> original, Patch<String>
198200Chunk <String >rev =delta .getTarget ();
199201
200202for (String line :original .subList (endPos ,orig .getPosition ())) {
201- diffRows .add (buildDiffRow (Tag .EQUAL ,line ,line ));
203+ diffRows .add (buildDiffRow (Tag .EQUAL ,line ,line , line , line ));
202204 }
203205
204206// Inserted DiffRow
205207if (delta instanceof InsertDelta ) {
206208endPos =orig .last () +1 ;
207209for (String line :rev .getLines ()) {
208- diffRows .add (buildDiffRow (Tag .INSERT ,"" ,line ));
210+ diffRows .add (buildDiffRow (Tag .INSERT ,"" ,line , "" , line ));
209211 }
210212continue ;
211213 }
@@ -214,7 +216,7 @@ public List<DiffRow> generateDiffRows(final List<String> original, Patch<String>
214216if (delta instanceof DeleteDelta ) {
215217endPos =orig .last () +1 ;
216218for (String line :orig .getLines ()) {
217- diffRows .add (buildDiffRow (Tag .DELETE ,line ,"" ));
219+ diffRows .add (buildDiffRow (Tag .DELETE ,line ,"" , line , "" ));
218220 }
219221continue ;
220222 }
@@ -225,22 +227,26 @@ public List<DiffRow> generateDiffRows(final List<String> original, Patch<String>
225227for (int j =0 ;j <Math .max (orig .size (),rev .size ());j ++) {
226228diffRows .add (buildDiffRow (Tag .CHANGE ,
227229orig .getLines ().size () >j ?orig .getLines ().get (j ) :"" ,
228- rev .getLines ().size () >j ?rev .getLines ().get (j ) :"" ));
230+ rev .getLines ().size () >j ?rev .getLines ().get (j ) :"" ,
231+ orig .getLines ().size () >j ?delta .getSource ().getLines ().get (j ) :"" ,
232+ rev .getLines ().size () >j ?delta .getTarget ().getLines ().get (j ) :"" ));
229233 }
230234 }
231235endPos =orig .last () +1 ;
232236 }
233237
234238// Copy the final matching chunk if any.
235239for (String line :original .subList (endPos ,original .size ())) {
236- diffRows .add (buildDiffRow (Tag .EQUAL ,line ,line ));
240+ diffRows .add (buildDiffRow (Tag .EQUAL ,line ,line , line , line ));
237241 }
238242return diffRows ;
239243 }
240244
241- private DiffRow buildDiffRow (Tag type ,String orgline ,String newline ) {
245+ private DiffRow buildDiffRow (Tag type ,String orgline ,String newline , String raworgline , String rawnewline ) {
242246if (reportLinesUnchanged ) {
243- return new DiffRow (type ,orgline ,newline );
247+ return rawValues
248+ ?new DiffRow (type ,orgline ,newline ,raworgline ,rawnewline )
249+ :new DiffRow (type ,orgline ,newline );
244250 }else {
245251String wrapOrg =preprocessLine (orgline );
246252if (Tag .DELETE ==type ) {
@@ -256,14 +262,22 @@ private DiffRow buildDiffRow(Tag type, String orgline, String newline) {
256262wrapNew =newTag .apply (true ) +wrapNew +newTag .apply (false );
257263 }
258264 }
259- return new DiffRow (type ,wrapOrg ,wrapNew );
265+ return rawValues
266+ ?new DiffRow (type ,wrapOrg ,wrapNew ,raworgline ,rawnewline )
267+ :new DiffRow (type ,wrapOrg ,wrapNew );
260268 }
261269 }
262270
263- private DiffRow buildDiffRowWithoutNormalizing (Tag type ,String orgline ,String newline ) {
264- return new DiffRow (type ,
265- StringUtils .wrapText (orgline ,columnWidth ),
266- StringUtils .wrapText (newline ,columnWidth ));
271+ private DiffRow buildDiffRowWithoutNormalizing (Tag type ,String orgline ,String newline ,String raworgline ,String rawnewline ) {
272+ return rawValues
273+ ?new DiffRow (type ,
274+ StringUtils .wrapText (orgline ,columnWidth ),
275+ StringUtils .wrapText (newline ,columnWidth ),
276+ raworgline ,
277+ rawnewline )
278+ :new DiffRow (type ,
279+ StringUtils .wrapText (orgline ,columnWidth ),
280+ StringUtils .wrapText (newline ,columnWidth ));
267281 }
268282
269283List <String >normalizeLines (List <String >list ) {
@@ -343,7 +357,9 @@ private List<DiffRow> generateInlineDiffs(AbstractDelta<String> delta) throws Di
343357diffRows .
344358add (buildDiffRowWithoutNormalizing (Tag .CHANGE ,
345359original .size () >j ?original .get (j ) :"" ,
346- revised .size () >j ?revised .get (j ) :"" ));
360+ revised .size () >j ?revised .get (j ) :"" ,
361+ original .size () >j ?delta .getSource ().getLines ().get (j ) :"" ,
362+ revised .size () >j ?delta .getTarget ().getLines ().get (j ) :"" ));
347363 }
348364return diffRows ;
349365 }
@@ -375,6 +391,8 @@ public static class Builder {
375391private boolean reportLinesUnchanged =false ;
376392private Function <String ,List <String >>inlineDiffSplitter =SPLITTER_BY_CHARACTER ;
377393private Function <String ,String >lineNormalizer =LINE_NORMALIZER_FOR_HTML ;
394+
395+ private boolean rawValues =false ;
378396
379397private Builder () {
380398 }
@@ -505,5 +523,18 @@ public Builder lineNormalizer(Function<String, String> lineNormalizer) {
505523this .lineNormalizer =lineNormalizer ;
506524return this ;
507525 }
526+
527+ /**
528+ * In some cases the original values of the diffed text are needed as well as the formatted values.
529+ * This option can be set to allow {@link DiffRow.getRawOldLine} and {@link DiffRow.getRawNewLine}
530+ * to access the original text of the old and new lines.
531+ *
532+ * @param rawValues
533+ * @return
534+ */
535+ public Builder rawValues (boolean rawValues ) {
536+ this .rawValues =rawValues ;
537+ return this ;
538+ }
508539 }
509540}