Skip to main content

Compare text, and produce human-readable differences or deltas which look like track changes in Microsoft Word.

Project description

Redlines

Repository banner image

Redlines produces a Markdown 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.

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 over walks past the lazy dog.

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.",
)
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.")
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."
)

Uses

Roadmap / Contributing

Please feel free to post issues and comments. I work on this in my free time, so please excuse lack of activity.

Nice things to do

  • Style the way changes are presented
  • Other than Markdown, have other output formats (HTML? PDF?)
  • Associate changes with an author
  • Show different changes by different authors or times.

If this was useful to you, please feel free to contact me!

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redlines-0.3.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redlines-0.3.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file redlines-0.3.0.tar.gz.

File metadata

  • Download URL: redlines-0.3.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for redlines-0.3.0.tar.gz
Algorithm Hash digest
SHA256 03d5a7f41812c5af4fdbc1681d2ac7d916ecc0eff88c48d0fa9b09d3ed1ab771
MD5 603a1928618e8fb21c0319ab3cd9db84
BLAKE2b-256 f4c2f7a5820e00720aff56ec19d911decced6a50b56802bc0e555f8d991c8965

See more details on using hashes here.

File details

Details for the file redlines-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: redlines-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for redlines-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64ae4443282f65d16d7662aec2b1d6a7d5b889deeae829f93aa962506cd61a5b
MD5 2779453edb738a7ad3ffa5f9eab8b765
BLAKE2b-256 fab3921dc3efeb04f089f534ddbb4976ac2ef48921670a19aef520d155923dde

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page