redlines

Redlines

Redlines compares two strings/text and shows their differences. The changes are represented with strike-throughs and highlights, similar to Microsoft Word's track changes.

The output can be in JSON, Markdown, HTML, or rich format. JSON is the default for CLI and automation use.

Quick Start

from redlines import Redlines

# Create a Redlines object
test = Redlines(
    "The quick brown fox jumps over the lazy dog.",
    "The quick brown fox walks past the lazy dog.",
)

# Get markdown output with <del>/<ins> tags
print(test.compare(markdown_style="none"))
# Output: The quick brown fox <del>jumps over </del><ins>walks past </ins>the lazy dog.

# Get JSON output (structured data)
print(test.output_json())

# Get rich output (terminal display)
print(test.output_rich)

Installation

pip install redlines

# Optional: PDF file comparison
pip install redlines[pdf]

# Optional: Advanced sentence detection (Python 3.11+)
pip install redlines[nupunkt]

# Optional: Levenshtein distance statistics
pip install redlines[levenshtein]

For AI Agents & Automation

🤖 Using with AI coding agents?

See the Agent Integration Guide for:

  • JSON schema documentation
  • CLI automation patterns
  • Error handling cookbook
  • Performance guidelines
  • Runnable examples

Quick CLI usage:

# Outputs JSON by default
redlines "old text" "new text"

# Pretty-print JSON
redlines file1.txt file2.txt --pretty

# Other formats
redlines text "source" "test"       # Rich terminal display
redlines markdown file1.txt file2.txt  # Markdown output

API Documentation

  • Redlines - Main comparison class
  • Document - File input support
  • PDF - PDF file support (optional)
  • Processor - Custom tokenization
  • CLI - Command-line interface
 1"""
 2# Redlines
 3
 4`Redlines` compares two strings/text and shows their differences. The changes are represented with
 5strike-throughs and highlights, similar to Microsoft Word's track changes.
 6
 7The output can be in JSON, Markdown, HTML, or `rich` format. JSON is the default for CLI and automation use.
 8
 9## Quick Start
10
11```python
12from redlines import Redlines
13
14# Create a Redlines object
15test = Redlines(
16    "The quick brown fox jumps over the lazy dog.",
17    "The quick brown fox walks past the lazy dog.",
18)
19
20# Get markdown output with <del>/<ins> tags
21print(test.compare(markdown_style="none"))
22# Output: The quick brown fox <del>jumps over </del><ins>walks past </ins>the lazy dog.
23
24# Get JSON output (structured data)
25print(test.output_json())
26
27# Get rich output (terminal display)
28print(test.output_rich)
29```
30
31## Installation
32
33```bash
34pip install redlines
35
36# Optional: PDF file comparison
37pip install redlines[pdf]
38
39# Optional: Advanced sentence detection (Python 3.11+)
40pip install redlines[nupunkt]
41
42# Optional: Levenshtein distance statistics
43pip install redlines[levenshtein]
44```
45
46## For AI Agents & Automation
47
48**🤖 Using with AI coding agents?**
49
50See the [Agent Integration Guide](https://github.com/houfu/redlines/blob/main/AGENT_GUIDE.md) for:
51- JSON schema documentation
52- CLI automation patterns
53- Error handling cookbook
54- Performance guidelines
55- [Runnable examples](https://github.com/houfu/redlines/tree/main/examples)
56
57Quick CLI usage:
58```bash
59# Outputs JSON by default
60redlines "old text" "new text"
61
62# Pretty-print JSON
63redlines file1.txt file2.txt --pretty
64
65# Other formats
66redlines text "source" "test"       # Rich terminal display
67redlines markdown file1.txt file2.txt  # Markdown output
68```
69
70## API Documentation
71
72* [Redlines](redlines/redlines.html) - Main comparison class
73* [Document](redlines/document.html) - File input support
74* [PDF](redlines/pdf.html) - PDF file support (optional)
75* [Processor](redlines/processor.html) - Custom tokenization
76* [CLI](redlines/cli.html) - Command-line interface
77
78"""
79
80from .document import *
81from .enums import *
82from .pdf import *
83from .processor import *
84from .redlines import *