# Diffing paragraphs

**URL:** <https://www.ruby-forum.com/t/diffing-paragraphs/49431>\
**Category:** Rails\
**Created:** [December 4, 2005, 1:55pm UTC](https://www.ruby-forum.com/t/diffing-paragraphs/49431 "2005-12-04T13:55:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marshall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58956e/32.png) [@marshall](https://www.ruby-forum.com/u/marshall)\
**Post date:** [December 4, 2005, 1:55pm UTC](https://www.ruby-forum.com/t/diffing-paragraphs/49431/1 "2005-12-04T13:55:27Z")

</div>

Hi all,

Is there a decent equivalent of Perl’s Text::ParagraphDiff[1] that I can  
use with Rails to show differences between two versions of a story?

I’ve found something called xhtmldiff, but it requires funky REXML  
objects that I can’t get to play nice with simple\_format(). The diff  
algorithm that comes with Instiki is nice, but it doesn’t seem to scale  
(works okay on 500 characters, appears to hang \> 1000, which is still  
rather short).

–  
Marshall Roch

[1]

> **[Text::ParagraphDiff - Visual Difference for paragraphed text. - metacpan.org](https://metacpan.org/release/JRYAN/Text-ParagraphDiff-2.70/view/lib/Text/ParagraphDiff.pm)**
>
> Visual Difference for paragraphed text.

---

<div class="post-metadata">

**Author:** ![marshall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58956e/32.png) [@marshall](https://www.ruby-forum.com/u/marshall)\
**Post date:** [December 4, 2005, 4:38pm UTC](https://www.ruby-forum.com/t/diffing-paragraphs/49431/2 "2005-12-04T16:38:45Z")

</div>

there is an htmldiff module that comes with spark that may work for you.

[http://rubyforge.org/frs/?group\_id=418](http://rubyforge.org/frs/?group_id=418)

---

<div class="post-metadata">

**Author:** ![marshall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58956e/32.png) [@marshall](https://www.ruby-forum.com/u/marshall)\
**Post date:** [December 4, 2005, 5:19pm UTC](https://www.ruby-forum.com/t/diffing-paragraphs/49431/3 "2005-12-04T17:19:53Z")

</div>

On Sun, 4 Dec 2005, Marshall Roch wrote:

> Hi all,
> 
> Is there a decent equivalent of Perl’s Text::ParagraphDiff[1] that I can  
> use with Rails to show differences between two versions of a story?
> 
> I’ve found something called xhtmldiff, but it requires funky REXML objects  
> that I can’t get to play nice with simple\_format(). The diff algorithm that  
> comes with Instiki is nice, but it doesn’t seem to scale (works okay on 500  
> characters, appears to hang \> 1000, which is still rather short).

[http://raa.ruby-lang.org/project/docdiff/](http://raa.ruby-lang.org/project/docdiff/)  
[http://raa.ruby-lang.org/project/diff-lcs/](http://raa.ruby-lang.org/project/diff-lcs/)  
[http://raa.ruby-lang.org/project/algorithm-diff/](http://raa.ruby-lang.org/project/algorithm-diff/)  
[http://raa.ruby-lang.org/project/simple-diff/](http://raa.ruby-lang.org/project/simple-diff/)

however, if performance we’re key you’d have to come up with an  
extremely good  
reason not to use

require “tempfile”

a = Tempfile::new “a#{ rand }”  
b = Tempfile::new “b#{ rand }”

a.write “some text”  
b.write “some other text”

a.close  
b.close

diff = `diff -bBu #{ a.path } #{ b.path }`

a.close!  
b.close!

regards.

## -a

# =============================================================================== | ara [dot] t [dot] howard [at] noaa [dot] gov | all happiness comes from the desire for others to be happy. all misery | comes from the desire for oneself to be happy. | – bodhicaryavatara
