type HtmlDiff
object --+
|
HtmlDiff
For producing HTML side by side comparison with change highlights.
This class can be used to create an HTML table (or a complete HTML
file containing the table) showing a side by side, line by line
comparison of text with inter-line and intra-line change highlights. The
table can be generated in either full or contextual difference mode.
The following methods are provided for HTML generation:
make_table -- generates HTML for a single side by side table make_file
-- generates complete HTML file with a single side by side table
See tools/scripts/diff.py for an example usage of this class.
|
__init__(self,
tabsize=8,
wrapcolumn=None,
linejunk=None,
charjunk=<function IS_CHARACTER_JUNK at 0x406751ec>)
HtmlDiff instance initializer |
|
|
|
make_file(self,
fromlines,
tolines,
fromdesc='
' ,
todesc='
' ,
context=False,
numlines=5)
Returns HTML file of side by side comparison with change highlights |
|
|
|
_tab_newline_replace(self,
fromlines,
tolines)
Returns from/to line lists with tabs expanded and newlines removed. |
|
|
|
_split_line(self,
data_list,
line_num,
text)
Builds list of text lines by splitting text lines at wrap point |
|
|
|
_line_wrapper(self,
diffs)
Returns iterator that splits (wraps) mdiff text lines |
|
|
|
|
|
_format_line(self,
side,
flag,
linenum,
text)
Returns HTML markup of "from" / "to" text lines |
|
|
|
_make_prefix(self)
Create unique anchor prefixes |
|
|
|
_convert_flags(self,
fromlist,
tolist,
flaglist,
context,
numlines)
Makes list of "next" links |
|
|
|
make_table(self,
fromlines,
tolines,
fromdesc='
' ,
todesc='
' ,
context=False,
numlines=5)
Returns HTML table of side by side comparison with change highlights |
|
|
|
_file_template = ' \n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...
|
|
_styles = ' \n table.diff {font-family:Courier; border:m ...
|
|
_table_template = ' \n <table class="diff" id="difflib_chg_% ...
|
|
_legend = ' \n <table class="diff" summary="Legends">\n ...
|
|
_default_prefix = 0
|
__init__(self,
tabsize=8,
wrapcolumn=None,
linejunk=None,
charjunk=<function IS_CHARACTER_JUNK at 0x406751ec>)
(Constructor)
|
|
HtmlDiff instance initializer
Arguments:
tabsize -- tab stop spacing, defaults to 8.
wrapcolumn -- column number where lines are broken and wrapped,
defaults to None where lines are not wrapped.
linejunk,charjunk -- keyword arguments passed into ndiff() (used to by
HtmlDiff() to generate the side by side HTML differences). See
ndiff() documentation for argument default values and descriptions.
- Overrides:
object.__init__
|
make_file(self,
fromlines,
tolines,
fromdesc='
' ,
todesc='
' ,
context=False,
numlines=5)
|
|
Returns HTML file of side by side comparison with change highlights
Arguments:
fromlines -- list of "from" lines
tolines -- list of "to" lines
fromdesc -- "from" file column header string
todesc -- "to" file column header string
context -- set to True for contextual differences (defaults to False
which shows full differences).
numlines -- number of context lines. When context is set True,
controls number of lines displayed before and after the change.
When context is False, controls the number of lines to place
the "next" link anchors before the next change (so click of
"next" link jumps to just before the change).
|
_tab_newline_replace(self,
fromlines,
tolines)
|
|
Returns from/to line lists with tabs expanded and newlines
removed.
Instead of tab characters being replaced by the number of spaces
needed to fill in to the next tab stop, this function will fill the space
with tab characters. This is done so that the difference algorithms can
identify changes in a file when tabs are replaced by spaces and vice
versa. At the end of the HTML generation, the tab characters will be
replaced with a nonbreakable space.
|
_split_line(self,
data_list,
line_num,
text)
|
|
Builds list of text lines by splitting text lines at wrap point
This function will determine if the input text line needs to be
wrapped (split) into separate lines. If so, the first wrap point will be
determined and the first line appended to the output text line list.
This function is used recursively to handle the second part of the split
line to further split it.
|
_collect_lines(self,
diffs)
|
|
Collects mdiff output into separate lists
Before storing the mdiff from/to data into a list, it is converted
into a single line of text with HTML markup.
|
_format_line(self,
side,
flag,
linenum,
text)
|
|
Returns HTML markup of "from" / "to" text
lines
side -- 0 or 1 indicating "from" or "to" text flag
-- indicates if difference on line linenum -- line number (used for line
number column) text -- line text to be marked up
|
make_table(self,
fromlines,
tolines,
fromdesc='
' ,
todesc='
' ,
context=False,
numlines=5)
|
|
Returns HTML table of side by side comparison with change highlights
Arguments:
fromlines -- list of "from" lines
tolines -- list of "to" lines
fromdesc -- "from" file column header string
todesc -- "to" file column header string
context -- set to True for contextual differences (defaults to False
which shows full differences).
numlines -- number of context lines. When context is set True,
controls number of lines displayed before and after the change.
When context is False, controls the number of lines to place
the "next" link anchors before the next change (so click of
"next" link jumps to just before the change).
|
_file_template
- Value:
'''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
...
|
|
_styles
- Value:
'''
table.diff {font-family:Courier; border:medium;}
.diff_header {background-color:#e0e0e0}
td.diff_header {text-align:right}
.diff_next {background-color:#c0c0c0}
.diff_add {background-color:#aaffaa}
.diff_chg {background-color:#ffff77}
.diff_sub {background-color:#ffaaaa} '''
|
|
_table_template
- Value:
'''
<table class="diff" id="difflib_chg_%(prefix)s_top"
cellspacing="0" cellpadding="0" rules="groups" >
<colgroup></colgroup> <colgroup></colgroup> <colgroup></colgro
up>
<colgroup></colgroup> <colgroup></colgroup> <colgroup></colgro
up>
%(header_row)s
...
|
|
_legend
- Value:
'''
<table class="diff" summary="Legends">
<tr> <th colspan="2"> Legends </th> </tr>
<tr> <td> <table border="" summary="Colors">
<tr><th> Colors </th> </tr>
<tr><td class="diff_add"> Added </td><
/tr>
<tr><td class="diff_chg">Changed</td> </tr>
...
|
|