File: make_contents.py

package info (click to toggle)
pycxx 6.2.5-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,212 kB
  • ctags: 2,729
  • sloc: cpp: 6,126; python: 756; sh: 89; ansic: 60; makefile: 54
file content (52 lines) | stat: -rw-r--r-- 1,308 bytes parent folder | download | duplicates (6)
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
all_lines = open( 'PyCXX.html' ).readlines()

all_contents = []

for line in all_lines:
    if( line.startswith( '<h1><a name=' )
    or line.startswith( '<h2><a name=' ) ):
        all_contents.append( line )

all_html_contents = []
all_html_contents.append( '<ul>' )

nested = False
indent = ''
cls = 'contents_h1'
for line in all_contents:
    tag = line[0:len('<h1>')]
    contents = line[len('<h1><a name="'):-(len('</a></h1>')+1)]
    if nested:
        if tag == '<h1>':
            all_html_contents.append( '    </ul></li>' )
            nested = False
            indent = ''
            cls = 'contents_h1'
    else:
        if tag == '<h2>':
            nested = True
            indent = '    '
            cls = 'contents_h2'
            all_html_contents.append( '    <li><ul>' )
    all_html_contents.append( '%s<li class="%s"><a href="#%s</a></li>' % (indent, cls, contents) )

if nested:
    all_html_contents.append( '    </ul></li>' )
all_html_contents.append( '</ul>' )

output = True
for line in all_lines:
    if line == '<h2>Contents</h2>\n':
        print line,
        for line in all_html_contents:
            print line

        output = False

    elif output:
        print line,

    else:
        if line.startswith( '<h' ):
            print line,
            output = True