]* )*id=\"[^<>]*>" ),
# h_open_match
re.compile( "^ *
]" ),
# h_close_match
re.compile( ".* *$" ),
# div_trans
( re.compile( " title=\"[^\"]*\"" ), "" ),
# div_extract_id
( re.compile( "^.*
*$" ), "" ),
# h_close_extract
( re.compile( "^.*(]*>" ),
# li_full_match
re.compile( "^ *]* )*id=\"[^<>]*>" ),
# strong_open_match
re.compile( "^ *]" ),
# strong_close_match
re.compile( ".* *$" ),
# li_trans
( re.compile( " title=\"[^\"]*\"" ), "" ),
# li_extract_id
( re.compile( "^.* *$" ), "" ),
# strong_close_extract
( re.compile( "^.*( 1:
# del lines[1]
# div_line_count -= 1
#while div_line_count > 1:
# div_line = div_line.rstrip() + " " + lines[1].lstrip()
# del lines[1]
# div_line_count -= 1
id = re_sub( patterns[6], div_line.rstrip() )
lines[0] = re_sub( patterns[5], div_line )
h_open_line = lines[1]
indent = h_open_line[0:len(h_open_line)-len(h_open_line.lstrip())]
h_close_lnr = len(lines) - 1
h_close_line = lines[h_close_lnr]
lines[h_close_lnr] = re_sub( patterns[7], h_close_line )
lines.append( "%s ¶\n" % indent )
lines.append( indent + re_sub( patterns[8], h_close_line ) )
def next_or_none( iterable ):
try:
return iterable.next()
except StopIteration:
return None
def transform_file( filename ):
print "transforming", filename
ifd = os.popen( "svn cat -r BASE " + filename, "r" )
ofd = open( filename, "w" )
patterns = None
line_cache = []
div_line_count = 1
changes = 0
line = next_or_none( ifd )
while line:
recheck_line = False
line_count = len(line_cache)
write_lines = line_count == 0
if write_lines:
if div_patterns[0].match( line ):
patterns = div_patterns
if li_patterns[0].match( line ):
patterns = li_patterns
if patterns:
line_cache.append( line )
write_lines = False
if not patterns[1].match( line ):
div_line_count = 2
else:
if line_count < div_line_count:
line_cache.append( line )
if not patterns[1].match( " ".join( line_cache ) ):
div_line_count += 1
if line_count == div_line_count:
if patterns[3].match( line ):
line_count += 1
else:
recheck_line = True
write_lines = True
if line_count > div_line_count:
if patterns[4].match( line ):
line_cache.append( line )
line = None
transform( patterns, line_cache, div_line_count )
write_lines = True
changes += 1
else:
line_cache.append( line )
if write_lines:
if len(line_cache) > 0:
for l in line_cache:
ofd.write( l )
line_cache = []
if line and not recheck_line:
ofd.write( line )
patterns = None
div_line_count = 1
if not recheck_line:
line = next_or_none( ifd )
print " %d changes" % changes
def search_files():
for path, dirs , files in os.walk( "." ):
ignore_dirs = ( ".svn", )
if path == "./docs":
ignore_dirs = ( ".svn", "api", "javahl" )
i = len(dirs) - 1
while i >= 0:
if dirs[i] in ignore_dirs:
del dirs[i]
i -= 1
for file in files:
if file.endswith( ".html" ):
transform_file( os.path.join( path, file ) )
if __name__ == "__main__":
#transform_file( "faq.html" )
#transform_file( "features.html" )
#transform_file( "docs/release-notes/1.6.html" )
search_files()