@@ -57,9 +57,9 @@ use constant SEQ_A_IDX => 0;
5757use constant SEQ_B_IDX => 1;
5858
5959my %code_map = (
60- ' +' => ' ins' ,
61- ' -' => ' del' ,
62- ' ' => ' ctx' ,
60+ ' +' => [ ' ins' => ' ins ' ] ,
61+ ' -' => [ ' del' => ' del ' ] ,
62+ ' ' => [ ' span class=" ctx" ' => ' span ' ]
6363);
6464
6565sub hunk {
@@ -70,25 +70,25 @@ sub hunk {
7070
7171 # Start the span element for the first opcode.
7272 my $last = $ops -> [0][ OPCODE ];
73- my $hunk = qq{ <span class=" $code_map { $last }" >} ;
73+ my $hunk = qq{ <$code_map { $last }->[0] >} ;
7474
7575 # Output each line of the hunk.
7676 while (my $op = shift @$ops ) {
7777 my $opcode = $op -> [OPCODE];
78- my $class = $code_map { $opcode } or next ;
78+ my $elem = $code_map { $opcode } or next ;
7979
8080 # Close the last span and start a new one for a new opcode.
8181 if ($opcode ne $last ) {
82+ $hunk .= " </$code_map { $last }->[1]><$elem ->[0]>" ;
8283 $last = $opcode ;
83- $hunk .= qq{ </span><span class="$class ">} ;
8484 }
8585
8686 # Output the appropriate line.
8787 my $idx = $opcode ne ' +' ? SEQ_A_IDX : SEQ_B_IDX;
8888 $hunk .= encode_entities(" $opcode $seqs ->[$idx ][$op ->[$idx ]]" );
8989 }
9090
91- return $hunk . ' </span> ' ;
91+ return $hunk . " </ $code_map { $last }->[1]> " ;
9292}
9393
94941;
@@ -133,8 +133,8 @@ In the XHTML formatted by this module, the contents of the diff returned by
133133C<diff() > are wrapped in a C<< <div> >> element, as is each hunk of the diff.
134134Within each hunk, all content is properly HTML encoded using
135135L<HTML::Entities|HTML::Entities> , and the various sections of the diff are
136- marked up with C<< <span> >> elements. Each C<< <div> >> and C<< <span> >>
137- element has a class, defined as follows:
136+ marked up with the appropriate XHTML elements. The elements used are as
137+ follows:
138138
139139=over
140140
@@ -174,13 +174,13 @@ This element immediately follows the opening "hunk" C<< <div> >> element.
174174Context around the important part of a C<diff > hunk. These are contents that
175175have I<not > changed between the files being C<diff > ed.
176176
177- =item * C<< <span class=" ins" > >>
177+ =item * C<< <ins> >>
178178
179- An insertion line, starting with C<+ > .
179+ Inserted content, each line starting with C<+ > .
180180
181- =item * C<< <span class=" del" > >>
181+ =item * C<< <del> >>
182182
183- A deletion line, starting with C<- > .
183+ Deleted content, each line starting with C<- > .
184184
185185=item * C<< <span class="hunkfooter"> >>
186186
@@ -196,10 +196,10 @@ The footer section of a file; contains no contents.
196196
197197=back
198198
199- You may do whatever you like with these classes; I highly recommend that you
200- style them using CSS. You'll find an example CSS file in the F<eg> directory
201- in the Text-Diff-HTML distribution. You will also likely want to wrap the
202- output of your diff a C<< <pre> >> element.
199+ You may do whatever you like with these elements and classes; I highly
200+ recommend that you style them using CSS. You'll find an example CSS file in
201+ the F<eg> directory in the Text-Diff-HTML distribution. You will also likely
202+ want to wrap the output of your diff a C<< <pre> >> element.
203203
204204=head1 See Also
205205
0 commit comments