PyDiff2html
is a Python tool designed to compare two text files and generate an HTML report with color-coded differences. This tool supports various types of diffs, making it easy to visualize changes between file versions.
- Compare two files and generate a diff report in HTML format.
- Supports different types of diffs:
all
,changes
,removed
,added
. - Easy to use via command-line arguments.
-
Ensure you have Python 3 installed on your system.
-
Clone the repository or download the script file.
git clone https://github.com/yourusername/PyDiff2html.git cd PyDiff2html
-
(Optional) Set up a virtual environment and install dependencies.
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
To compare two files and generate an HTML diff report, use the following command:
python compare_files.py <file1> <file2> [-o <output_file>] [-t <diff_type>]
<file1>
: Path to the first file.<file2>
: Path to the second file.-o
,--output
(optional): Path to the output HTML file. Default isdiff.html
.-t
,--type
(optional): Type of diff to generate. Options areall
,changes
,removed
,added
. Default isall
.
-
Generate a full diff report:
python compare_files.py file1.txt file2.txt
-
Generate a report highlighting changes:
python compare_files.py file1.txt file2.txt -t changes
-
Generate a report showing removed lines:
python compare_files.py file1.txt file2.txt -t removed
-
Generate a report showing added lines:
python compare_files.py file1.txt file2.txt -t added
- FileNotFoundError: Indicates that one or both files could not be found.
- ValueError: Raised if an invalid diff type is provided.
Feel free to open issues or submit pull requests if you have suggestions or improvements.
For questions or feedback, please contact [email protected]