difflib.HtmlDiff

class difflib.HtmlDiff(tabsize=8, wrapcolumn=None, linejunk=None, charjunk=<function IS_CHARACTER_JUNK>)[source]

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.

Methods

__format__ default object formatter
__init__([tabsize, wrapcolumn, linejunk, ...]) HtmlDiff instance initializer
__new__((S, ...)
__reduce__ helper for pickle
__reduce_ex__ helper for pickle
__sizeof__(() -> int) size of object in memory, in bytes
__subclasshook__ Abstract classes can override this to customize issubclass().
_collect_lines(diffs) Collects mdiff output into separate lists
_convert_flags(fromlist, tolist, flaglist, ...) Makes list of “next” links
_format_line(side, flag, linenum, text) Returns HTML markup of “from” / “to” text lines
_line_wrapper(diffs) Returns iterator that splits (wraps) mdiff text lines
_make_prefix() Create unique anchor prefixes
_split_line(data_list, line_num, text) Builds list of text lines by splitting text lines at wrap point
_tab_newline_replace(fromlines, tolines) Returns from/to line lists with tabs expanded and newlines removed.
make_file(fromlines, tolines[, fromdesc, ...]) Returns HTML file of side by side comparison with change highlights
make_table(fromlines, tolines[, fromdesc, ...]) Returns HTML table of side by side comparison with change highlights