package w3bbc_html;
sub text_tag_pre {
local(*opts,*tag,*close,$html) = @_;
local(@parsed,@save,$ret);
#unless ($opts{'_tag'} eq 'pre') {
unless ($opts{'_tag'}) {
$html =~ s/^\s*[\r\n]+//;
$html =~ s/\s*[\r\n]+\s*$//;
$ret .= &newlines(*opts,2);
}
if (&has_tag($html)) {
@parsed = ();
&parse_html(*parsed,$html);
@save = ($opts{'_tag'},$opts{'font_type'},$opts{'font_emphasis'});
$opts{'font_type'} = 'plain';
$opts{'font_emphasis'} = '*';
$opts{'_tag'} = 'pre';
$html = &process_html(*opts,*parsed);
($opts{'_tag'},$opts{'font_type'},$opts{'font_emphasis'}) = @save;
} else {
&display_text(*opts,$html);
}
$ret .= $html;
#unless ($opts{'_tag'} eq 'pre') {
unless ($opts{'_tag'}) {
$ret .= &newlines(*opts,2);
}
return($ret);
}
sub text_tag_address {
local(*opts,*tag,*close,$html) = @_;
local(@parsed,@save,$ret);
$ret .= &newlines(*opts,1);
if ($opts{'a_href'}) {
# Rather than handle it myself, wrap it with the URL and pass it on..
local(%open2,%close2);
$open2{'a_href'} = $opts{'a_href'};
$open2{'a_name'} = $opts{'a_name'};
local($routine) = $w3bbc_html'tags_block{'a'};
$ret .= &$routine(*opts,*open2,*close2,$html);
} elsif (&has_tag($html)) {
@parsed = ();
&parse_html(*parsed,$html);
$ret .= &process_html(*opts,*parsed);
} else {
&display_text(*opts,$html);
$ret .= $html;
}
$ret .= &newlines(*opts,1);
return($ret);
}
sub text_tag_a {
local(*opts,*open,*close,$html) = @_;
local($ret) = &parse_html_tag(*opts,*tag,*close,$html);
return $ret;
}
sub text_tag_img {
return("[IMAGE]");
}
sub text_tag_h {
local(*opts,*open,*close,$html) = @_;
$html =~ s/\s+/ /g; # Convert multiple space/newlines into single space
local($ret,$text,@parsed);
$ret .= &newlines(*opts,2); # 2 newlines before..
if (&has_tag($html)) {
@parsed = ();
&parse_html(*parsed,$html);
$html = &process_html(*opts,*parsed);
}
local($start) = $open;
$start =~ s/^h//i;
$text = "Header level #$start: $html";
$ret .= $text; # put the text in the stream
&display_text(*opts,$text); # register the displayed text length
$ret .= &newlines(*opts,2); # 2 newlines after..
return($ret);
}
sub text_tag_cite {
#
# bug in routine: will capitalize HTML tags, like
#
#
local(*opts,*tag,*close,$html) = @_;
if ($open eq 'b') {
$html =~ tr/a-z/A-Z/;
} elsif ($open eq 'i') {
$html = "{$html}";
}
local(@save) = ($opts{'_tag'});
local($ret) = &parse_html_tag(*opts,*tag,*close,$html);
($opts{'_tag'}) = @save;
return $ret;
}
sub text_tag_p {
local(*opts,*tag) = @_;
return(&newlines(*opts,2));
}
sub text_tag_br {
local(*opts,*tag) = @_;
return(&newlines(*opts,1));
}
sub text_tag_li { # in case they forget the or
local(*opts,*open) = @_;
local($ret,$r);
$ret = &w3bbc_html'newlines(*opts,1,1);
$r = "o".substr($opts{'_textspace'},1);
&w3bbc_html'display_text(*opts,$r);
$ret .= $r;
return($ret);
}
sub text_tag_dt { # in case they forget the or
local(*opts,*open) = @_;
local($ret,$r);
return &w3bbc_html'newlines(*opts,2,2);
}
sub text_tag_hr {
local(*opts,*open) = @_;
local($ret,$hr);
#$ret .= &newlines(*opts,2);
$ret .= &newlines(*opts,1,1);
$hr = '-' x $opts{'_max_len'};
&display_text(*opts,$hr);
#$ret .= $hr . &newlines(*opts,2);
$ret .= $hr . &newlines(*opts,1,1);
return($ret);
}
sub text_tag_list {
local(*opts,*open,*close,$html) = @_;
#print STDERR "text_tag_list($opts{'_tag'},$open,$close,$html)\n";
#print STDERR "caller(0)=(",join(',',caller(0)),")\n";
#print STDERR "caller(1)=(",join(',',caller(1)),")\n";
#print STDERR "caller(2)=(",join(',',caller(2)),")\n";
return unless($html =~ /\S/);
local($text,$n,$oldn,$ret,$ol_num,$space,@ol_num,$noud,$type,$indent);
local($_,$subtype,$indent_space,$nl,$processed,@li,@parsed,@save);
local($len,$prefix,@text,$escaped,$tmp,$indent_space1,$indent_space2);
if ($opts{'_tag'}) {
if (&has_tag($html)) {
@parsed = ();
&parse_html(*parsed,$html);
$html = &process_html(*opts,*parsed);
return($html);
} else {
$html =~ s/\s+/ /g;
$indent = $opts{'_indent'};
$indent_space = ($opts{'_textspace'} x ($indent-1));
$indent_space1 = ($opts{'_textspace'} x ($indent));
$indent_space2 = ($opts{'_textspace'} x ($indent+1));
$len = $opts{'_max_len'} - length($indent_space2);
@text = &wordwrap($opts{'_line_len'},$len,$html);
for $text (0..$#text) {
if (($text == 0) && ($opts{'list_first'})) {
$escaped = '';
} elsif ($opts{'_line_len'}) {
$escaped = '';
} elsif (($opts{'_tag'} eq 'dl') || ($opts{'tag_subtype'} eq 'dd')) {
$escaped = $indent_space1;
} else {
$escaped = $indent_space2;
#$escaped = $indent_space;
}
$opts{'list_first'} = 0;
local(@save) = ($opts{'_tag'});
$opts{'_tag'} = '';
$ret .= $escaped . &w3bbc_html'process_html_text(*opts,$text[$text]);
($opts{'_tag'}) = @save;
$ret .= &newlines(*opts,1) unless($text == $#text);
}
}
return($ret);
}
@li = &parse_html_list($open,$html);
$ret .= &newlines(*opts,2);
local($otype,$osubtype); # otype/osubtype is old type/subtype
while (@li) {
$oldn = $n;
$otype = $type;
$osubtype = $subtype;
$noud = shift(@li);
($type,$subtype,$n) = split(/\//,$noud);
if (($oldn) && ($oldn > $n)) { # tag change, end of current tag
$ol_num = pop(@ol_num);
$ret .= &newlines(*opts,1,1);
$ret .= &newlines(*opts,1) if ($otype eq 'dl');
#$opts{'_indent'}--;
$opts{'_indent'}-=$oldn-$n;
} elsif (($oldn) && ($oldn < $n)) { # tag change, begin of new tag
push(@ol_num,$ol_num);
$ol_num = 0;
$ret .= &newlines(*opts,1,1);
$ret .= &newlines(*opts,1) if ($type eq 'dl');
#$opts{'_indent'}++;
$opts{'_indent'}+=$n-$oldn;
}
$indent = $n + $opts{'_indent'};
$text = shift(@li);
if (&has_tag($text)) {
@parsed = ();
&parse_html(*parsed,$text);
local(@save) =
($opts{'_indent'},$opts{'_tag'},$opts{'tag_type'},$opts{'tag_subtype'});
$opts{'_indent'} = $indent;
$opts{'tag_subtype'} = $subtype;
$opts{'tag_type'} = $type;
$opts{'_tag'} = $open;
#$opts{'list_first'} = 1;
$opts{'list_first'} = 1 unless($type eq '');
$text = &process_html(*opts,*parsed);
$opts{'list_first'} = 0;
($opts{'_indent'},$opts{'_tag'},$opts{'tag_type'},$opts{'tag_subtype'})
= @save;
$processed = 1;
} else {
$text =~ s/\s+/ /g;
$processed = 0;
}
$indent_space = (($indent > 1) ? ($opts{'_textspace'} x ($indent-1)):undef);
$indent_space1 = ($opts{'_textspace'} x ($indent));
$indent_space2 = ($opts{'_textspace'} x ($indent+1));
$space = $opts{'_textspace'};
$opts{'_space'} = 1;
if ($type eq 'ol') { # - tag
$ol_num++;
substr($space,0,length($ol_num)+1) = "$ol_num.";
$prefix = $indent_space . $opts{'_textspace'} . $space;
} elsif (($type eq 'ul') || ($type eq 'menu') || ($type eq 'dir')) {#
-
substr($space,0,1) = "o";
$prefix = $indent_space . $opts{'_textspace'} . $space;
} elsif (($type eq 'dl') && ($subtype eq 'dt')) { #
- tag
$prefix = $indent_space;
} elsif (($type eq 'dl') && ($subtype eq 'dd')) { #
- tag
$prefix = $indent_space . $opts{'_textspace'};
} elsif ($type eq ' ') { # Continuation
#$prefix = $indent_space . $opts{'_textspace'};
$prefix = $indent_space2;
#$prefix = $indent_space2 . $opts{'_textspace'};
} else {
warn
"Unknown type '$type' subtype '$subtype' noud='$noud' text='$text'\n";
}
if ($text) {
$len = $opts{'_max_len'} - length($indent_space);
if ($processed) {
$ret .= $prefix . $text;
} else {
if ($opts{'_space'}) { $text =~ s/^ //; $opts{'_space'} = 0; }
@text = &wordwrap($opts{'_line_len'},$len,$text);
for $text (0..$#text) {
if ($text == 0) {
$escaped = $prefix;
} elsif ($type eq 'dl' && $subtype eq 'dt') {
$escaped = $indent_space;
} elsif ($type eq 'dl' && $subtype eq 'dd') {
$escaped = $indent_space1;
} else {
$escaped = $indent_space2;
}
$ret .= $escaped .
&w3bbc_html'process_html_text(*opts,$text[$text],1);
$ret .= &newlines(*opts,1) unless($text == $#text);
}
}
}
$ret .= &newlines(*opts,1,1);
}
$ret .= &newlines(*opts,1);
return($ret);
}
sub html_tag_pre {
local(*opts,*tag,*close_tag,$html) = @_;
return unless($html);
#print STDERR "html_tag_pre($opts{'_tag'},$tag,$close_tag,$html)\n";
local(@parsed,@save,$ret);
if (&w3bbc_html'has_tag($html)) {
@parsed = ();
&w3bbc_html'parse_html(*parsed,$html);
@save = ($opts{'_tag'},$opts{'font_type'},$opts{'font_emphasis'});
$opts{'_tag'} = 'pre';
$ret .= &w3bbc_html'process_html(*opts,*parsed);
($opts{'_tag'},$opts{'font_type'},$opts{'font_emphasis'}) = @save;
} elsif ($html =~ /\S/) {
if ($html =~ /[\r\n]/) {
local($h);
while ($html =~ /[\r\n]/) {
($h,$html) = split(/[\r\n]/,$html,2);
$ret .= $h;
&w3bbc_html'display_text(*opts,$h);
$ret .= &w3bbc_html'newlines(*opts,1);
}
}
$ret .= &tag_display_label(*opts,$html);
} else {
$ret .= $html;
&w3bbc_html'display_text(*opts,$html);
}
return($ret);
}
package main;
1;