File: make_contents.py

package info (click to toggle)
pycxx 7.1.8-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,392 kB
  • sloc: cpp: 6,767; python: 1,138; sh: 85; ansic: 60; makefile: 18
file content (56 lines) | stat: -rw-r--r-- 1,430 bytes parent folder | download | duplicates (10)
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
#!/usr/bin/python3
import sys

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':
        sys.stdout.write( line )
        for line in all_html_contents:
            sys.stdout.write( line )
            sys.stdout.write( '\n' )

        output = False

    elif output:
        sys.stdout.write( line )

    else:
        if line.startswith( '<h' ):
            sys.stdout.write( line, )
            output = True