summaryrefslogtreecommitdiff
path: root/Build/source/utils/texi2html/examples/book.init
blob: a4147a383058940e5425be05aa1d56e09d842ed5 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# This is based on the scriptbasic style

$DO_CONTENTS = 1;

@SECTION_BUTTONS =
    (
     'Back', 'Forward', ' ', 'Contents', 'Index', 'About'
    );

@CHAPTER_BUTTONS =
    (
     'Back', 'Forward', ' ', 'Contents', 'Index', 'About'
    );

@MISC_BUTTONS = ('Contents', 'Index', 'About');

@SECTION_FOOTER_BUTTONS = ('Contents', 'Index', 'About');

@NODE_FOOTER_BUTTONS = ('Back', 'Forward');

$WORDS_IN_PAGE = undef;
$SHOW_MENU = 0;

$BIG_RULE = '<hr size="2">';

sub print_sub_toc($$);

sub print_sub_toc($$)
{
    my $parent_element = shift;
    my $element = shift;
    my $result = &$anchor('', main::href($element, $parent_element->{'file'}), $element->{'text'}) . " <br>\n";
#print STDERR "SUB_TOC $element->{'text'}\n"; #sleep 1;
    if (exists($element->{'child'}))
    {
#print STDERR "SUB_TOC child $element->{'child'}->{'text'}\n"; 
         $result .= "<ul>\n". print_sub_toc($parent_element, $element->{'child'}) ."</ul>\n";
    }
    if (exists($element->{'next'}))
    {
#print STDERR "SUB_TOC next($element->{'text'}) $element->{'next'}->{'text'}\n"; 
         $result .= print_sub_toc($parent_element, $element->{'next'});
    }
    return $result;
}

sub print_up_toc($$)
{
    my $fh = shift;
    my $element = shift;
    my $current_element = $element;
    my @elements;
    while (defined($current_element->{'up'}) and ($current_element->{'up'} ne $current_element))
    {
        unshift (@elements, $current_element->{'up'});
        $current_element = $current_element->{'up'};
    }
    #print $fh "<ul>" . &$anchor('', $Texi2HTML::HREF{Contents}, '[' . $Texi2HTML::NAME{Contents} . ']') . " <br>\n";
    foreach my $elem (@elements)
    {
        print $fh "<ul>" . &$anchor('', main::href($elem, $element->{'file'}), $elem->{'text'}) . " <br>\n";
    }
    foreach my $elem (@elements)
    {
        print $fh "</ul>\n";
    }
    print $fh "</ul>\n";
}

$print_section = \&book_print_section;
$print_Top = \&book_print_Top;
$print_Toc = \&book_print_Toc;
$element_file_name = \&book_element_file_name;

sub book_print_section($$$)
{
    my $fh = shift;
    my $first_in_page = shift;
    my $previous_is_top = shift;
    my $buttons = \@SECTION_BUTTONS;

    if ($first_in_page and $SECTION_NAVIGATION)
    {
        #print_up_toc($fh, $Texi2HTML::THIS_ELEMENT) if ($SPLIT eq 'node');
        print_up_toc($fh, $Texi2HTML::THIS_ELEMENT);
        &$print_head_navigation($fh, $buttons);
    }
    else
    { # got to do this here, as it isn't done in print_head_navigation
        main::print_lines($fh, $Texi2HTML::THIS_HEADER);
        &$print_navigation($fh, $buttons) if ($SECTION_NAVIGATION);
    }
    my $nw = main::print_lines($fh);
    if (defined $SPLIT
        and (($SPLIT eq 'node') && $SECTION_NAVIGATION))
    {
        &$print_foot_navigation($fh);
        print $fh "$SMALL_RULE\n";
        &$print_navigation($fh, \@NODE_FOOTER_BUTTONS) if (!defined($WORDS_IN_PAGE) or (defined ($nw)
                                    and $nw >= $WORDS_IN_PAGE));
    }
}

sub book_print_Top($$)
{
    my $fh = shift;
    my $has_top_heading = shift;

    my $buttons = \@MISC_BUTTONS;
    &$print_head_navigation($fh, $buttons);
    print $fh $Texi2HTML::TITLEPAGE;
    print $fh "<h1 class=\"settitle\">$Texi2HTML::NAME{Top}</h1>\n"
        unless ($has_top_heading);
    main::print_lines($fh, $Texi2HTML::THIS_SECTION);
    print $fh '<h2> ' . $Texi2HTML::NAME{'Contents'} . "</h2>\n" ;
    main::print_lines($fh, $Texi2HTML::TOC_LINES);
}

sub book_print_Toc
{
    my $fh = shift;
    &$print_page_head($fh) if $SPLIT;
    #print $fh $Texi2HTML::TITLEPAGE;
    print $fh '<h2> ' . $Texi2HTML::NAME{'Contents'} . "</h2>\n" ;
    main::print_lines($fh);
    &$print_misc_footer($fh, \@MISC_BUTTONS);
}

my $unumbered_nr = -1;
my $previous_nr;
my $previous_file_name; 

sub book_element_file_name($$$)
{
    my $element = shift;
    my $is_top = shift;
    my $prefix = shift;

    if (defined($previous_nr) and ($element->{'doc_nr'} == $previous_nr))
    {
        return $previous_file_name;
    }
    if ($is_top)
    {
        $previous_file_name = "${prefix}_top.html";
    }
    elsif (defined($element->{'number'}) and ($element->{'number'} ne ''))
    {
         my $number = $element->{'number'};
         $number .= '.' unless ($number =~ /\.$/);
         $previous_file_name = "${prefix}_$number" . 'html';
    }
    else
    {
         $unumbered_nr++;
         $previous_file_name = "${prefix}_U." . $unumbered_nr . '.html'; 
    }
    $previous_nr = $element->{'doc_nr'};
    return $previous_file_name;
}

$heading = \&book_heading;

sub book_heading($)
{
    my $element = shift;
    my $level = 3;
    if (!$element->{'node'})
    {
        $level = $element->{'level'};
    }
    $level = 1 if ($level == 0);
    my $text = $element->{'text'};
    if (!$element->{'node'} and (!$NUMBER_SECTIONS))
    {
        $text = $element->{'name'};
    }
    return '' if ($text !~ /\S/);
    my $class = $element->{'tag_level'};
    $class = 'unnumbered' if ($class eq 'top');
    if (defined($element->{'tocid'}) and $TOC_LINKS)
    {
         $text = &$anchor ('', "$Texi2HTML::THISDOC{'toc_file'}#$element->{'tocid'}", $text);
    }
    $text = "<h$level class=\"$class\"> $text </h$level>\n";
    #if (defined($SPLIT)  and ($SPLIT eq 'node') 
    if (exists($element->{'child'}) 
        and ($element->{'tag_level'} !~ /heading/))
    {
        $text .= "<ul>\n";
        $text .= "" . print_sub_toc($element, $element->{'child'});
        $text .= "</ul>\n";
    }
    return $text;
}

1;