Back to index

plone3  3.1.7
Classes | Functions | Variables
CMFDiffTool.libs.htmldiff Namespace Reference

Classes

class  HTMLMatcher
class  NoTagHTMLMatcher
class  SimpleHTMLMatcher
class  TextMatcher

Functions

def htmlEncode
def htmldiff
def diffFiles
def simplehtmldiff

Variables

tuple commentRE = re.compile('<!--.*?-->', re.S)
tuple tagRE = re.compile('<.*?>', re.S)
tuple headRE = re.compile('<\s*head\s*>', re.S | re.I)

Detailed Description

htmldiff.py
(C) Ian Bicking <ianb@colorstudy.com>

Finds the differences between two HTML files.  *Not* line-by-line
comparison (more word-by-word).

Command-line usage:
  ./htmldiff.py test1.html test2.html

Better results if you use mxTidy first.  The output is HTML.

Function Documentation

def CMFDiffTool.libs.htmldiff.diffFiles (   f1,
  f2 
)

Definition at line 171 of file htmldiff.py.

00171 
00172 def diffFiles(f1, f2):
00173     source1 = open(f1).read()
00174     source2 = open(f2).read()
00175     return htmldiff(source1, source2, True)

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFDiffTool.libs.htmldiff.htmldiff (   source1,
  source2,
  addStylesheet = False 
)
Return the difference between two pieces of HTML

    >>> htmldiff('test1', 'test2')
    '<span class="delete">test1 </span> <span class="insert">test2 </span> '
    >>> htmldiff('test1', 'test1')
    'test1 '
    >>> htmldiff('<b>test1</b>', '<i>test1</i>')
    '<span class="tagDelete">delete: <tt>&lt;b&gt;</tt></span> <span class="tagInsert">insert: <tt>&lt;i&gt;</tt></span> <i> test1 <span class="tagDelete">delete: <tt>&lt;/b&gt;</tt></span> <span class="tagInsert">insert: <tt>&lt;/i&gt;</tt></span> </i> '

Definition at line 157 of file htmldiff.py.

00157 
00158 def htmldiff(source1, source2, addStylesheet=False):
00159     """
00160     Return the difference between two pieces of HTML
00161 
00162         >>> htmldiff('test1', 'test2')
00163         '<span class="delete">test1 </span> <span class="insert">test2 </span> '
00164         >>> htmldiff('test1', 'test1')
00165         'test1 '
00166         >>> htmldiff('<b>test1</b>', '<i>test1</i>')
00167         '<span class="tagDelete">delete: <tt>&lt;b&gt;</tt></span> <span class="tagInsert">insert: <tt>&lt;i&gt;</tt></span> <i> test1 <span class="tagDelete">delete: <tt>&lt;/b&gt;</tt></span> <span class="tagInsert">insert: <tt>&lt;/i&gt;</tt></span> </i> '
00168     """
00169     h = HTMLMatcher(source1, source2)
00170     return h.htmlDiff(addStylesheet)

Here is the caller graph for this function:

def CMFDiffTool.libs.htmldiff.htmlEncode (   s,
  esc = cgi.escape 
)

Definition at line 19 of file htmldiff.py.

00019 
00020 def htmlEncode(s, esc=cgi.escape):
00021     return esc(s, 1)

Here is the caller graph for this function:

def CMFDiffTool.libs.htmldiff.simplehtmldiff (   source1,
  source2 
)
Simpler form of htmldiff; mostly for testing, like:

    >>> simplehtmldiff('test1', 'test2')
    '-[test1 ]+[test2 ]'
    >>> simplehtmldiff('<b>Hello world!</b>', '<i>Hello you!</i>')
    '-[<b>]+[<i>]<i> Hello -[world! ]-[</b>]+[you! ]+[</i>]</i> '

Definition at line 193 of file htmldiff.py.

00193 
00194 def simplehtmldiff(source1, source2):
00195     """
00196     Simpler form of htmldiff; mostly for testing, like:
00197 
00198         >>> simplehtmldiff('test1', 'test2')
00199         '-[test1 ]+[test2 ]'
00200         >>> simplehtmldiff('<b>Hello world!</b>', '<i>Hello you!</i>')
00201         '-[<b>]+[<i>]<i> Hello -[world! ]-[</b>]+[you! ]+[</i>]</i> '
00202     """
00203     h = SimpleHTMLMatcher(source1, source2)
00204     return h.htmlDiff()


Variable Documentation

tuple CMFDiffTool.libs.htmldiff.commentRE = re.compile('<!--.*?-->', re.S)

Definition at line 22 of file htmldiff.py.

tuple CMFDiffTool.libs.htmldiff.headRE = re.compile('<\s*head\s*>', re.S | re.I)

Definition at line 24 of file htmldiff.py.

tuple CMFDiffTool.libs.htmldiff.tagRE = re.compile('<.*?>', re.S)

Definition at line 23 of file htmldiff.py.