Compare text, and produce human-readable differences or deltas which look like track changes in Microsoft Word.
Project description
Redlines
Redlines
produces a text showing the differences between two strings/text. The changes are represented with
strike-throughs and underlines, which looks similar to Microsoft Word's track changes. This method of showing changes is
more familiar to lawyers and is more compact for long series of characters.
Redlines uses SequenceMatcher
to find differences between words used.
The output can be in HTML, Markdown, or rich
format.
Example
Given an original string:
The quick brown fox jumps over the lazy dog.
And the string to be tested with:
The quick brown fox walks past the lazy dog.
The library gives a result of:
The quick brown fox <del>jumps over </del><ins>walks past </ins>the lazy dog.
Which is rendered like this:
The quick brown fox
jumps overwalks past the lazy dog.
The library can also output the results in Markdown, HTML or rich
format, and
for a variety of environments like Streamlit, Jupyter Notebooks, Google Colab and the terminal.
Install
pip install redlines
Usage
The library contains one class: Redlines
, which is used to compare text.
from redlines import Redlines
test = Redlines(
"The quick brown fox jumps over the lazy dog.",
"The quick brown fox walks past the lazy dog.", markdown_style="none",
)
assert (
test.output_markdown
== "The quick brown fox <del>jumps over </del><ins>walks past </ins>the lazy dog."
)
Alternatively, you can create Redline with the text to be tested, and compare several times to see the results.
from redlines import Redlines
test = Redlines("The quick brown fox jumps over the lazy dog.", markdown_style="none")
assert (
test.compare("The quick brown fox walks past the lazy dog.")
== "The quick brown fox <del>jumps over </del><ins>walks past </ins>the lazy dog."
)
assert (
test.compare("The quick brown fox jumps over the dog.")
== "The quick brown fox jumps over the <del>lazy </del>dog."
)
Redlines also features a simple command line tool redlines
to visualise the differences in text in the terminal.
Usage: redlines text [OPTIONS] SOURCE TEST
Compares the strings SOURCE and TEST and produce a redline in the terminal.
You may also want to check out the demo project redlines-textual.
Documentation
Read the available Documentation.
Uses
- View and mark changes in legislation: PLUS Explorer
- Visualise changes after ChatGPT transforms a text: ChatGPT Prompt Engineering for Developers Lesson 6
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file redlines-0.5.0.tar.gz
.
File metadata
- Download URL: redlines-0.5.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96e3b9db3e9c1bd5406516e3c6512efa1c7890f64e55950197b8a50be8ea0286 |
|
MD5 | 18270b6263b945795ac3ec02c50f9d34 |
|
BLAKE2b-256 | f6cf8c4a3b2644ac5c4f7129cc16e10537aa572cabc21f6f5cf551267b4b1b4c |
File details
Details for the file redlines-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: redlines-0.5.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74cac6af5283ad2eadb2c184b04f4d199a0e286b9b408ddb29e09890807e0c93 |
|
MD5 | e474d4413e72249d549428ac62d7ab2c |
|
BLAKE2b-256 | f292a139fbd54dbc3a96905ad7fc1a80f024923fb86703c9d7f3dab658feee13 |