File: fix-lex-files.py

package info (click to toggle)
golly 3.3-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 20,176 kB
  • sloc: cpp: 72,638; ansic: 25,919; python: 7,921; sh: 4,245; objc: 3,721; java: 2,781; xml: 1,362; makefile: 530; javascript: 279; perl: 69
file content (76 lines) | stat: -rw-r--r-- 2,050 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Fix lexicon .htm files included with iOS/Android/web Golly.
# 
# We replace this text:
#
# <center><table cellspacing=0 cellpadding=0><tr><td><pre><a href="lexpatt:">
# .O.....
# ...O...
# OO..OOO
# </a></pre>etc...
#
# with:
#
# <center><table cellspacing=0 cellpadding=0><tr><td><pre><a href="lexpatt:.O.....$...O...$OO..OOO$">
# .O.....
# ...O...
# OO..OOO
# </a></pre></td></tr></table></center>
#
# We also increase font size used for links at top and bottom of each page.

import re

# ------------------------------------------------------------------------------

def fix_file(filename):
    print 'fixing ' + filename
    f = open(filename, 'r')
    contents = f.read()
    
    # use re.DOTALL to include newlines in match
    for pattdata in re.findall('<a href="lexpatt:">\n(.*?)</a>', contents, re.DOTALL):
        newdata = pattdata.replace('\n','$')
        contents = contents.replace('<a href="lexpatt:">\n'+pattdata+'</a>',
                                    '<a href="lexpatt:'+newdata+'"\n>'+pattdata+'</a>', 1)
    
    # remove small font used for links at top and bottom of each page
    contents = contents.replace('<font size=-1><b>', '<b>', 2)
    contents = contents.replace('Z</A></b></font>', 'Z</A></b>', 2)
    
    f.close()
    
    f = open(filename, 'w')
    f.write(contents)
    f.close()

# ------------------------------------------------------------------------------

fix_file("lex.htm")
fix_file("lex_1.htm")
fix_file("lex_a.htm")
fix_file("lex_b.htm")
fix_file("lex_c.htm")
fix_file("lex_d.htm")
fix_file("lex_e.htm")
fix_file("lex_f.htm")
fix_file("lex_g.htm")
fix_file("lex_h.htm")
fix_file("lex_i.htm")
fix_file("lex_j.htm")
fix_file("lex_k.htm")
fix_file("lex_l.htm")
fix_file("lex_m.htm")
fix_file("lex_n.htm")
fix_file("lex_o.htm")
fix_file("lex_p.htm")
fix_file("lex_q.htm")
fix_file("lex_r.htm")
fix_file("lex_s.htm")
fix_file("lex_t.htm")
fix_file("lex_u.htm")
fix_file("lex_v.htm")
fix_file("lex_w.htm")
fix_file("lex_x.htm")
fix_file("lex_y.htm")
fix_file("lex_z.htm")
fix_file("lex_bib.htm")