# This is the html tags for w3bbc_html.pl
sub html_tag_img {
local(*opts,*open) = @_;
local($url) = &wwwurl'absolute($gl_base_url,$open{'img_src'});
$gl_page_url{$url} = 1;
$open{'img_src'} = $url;
#&url_seen($url);
local($msg,$pic,$relief,$old,$content_type,$_);
delete $opts{'_first'}; # cuz image is first..
$pic = $gl_image_cache{$url};
unless ($pic && -e $pic) {
local($headers,@headers,%headers,$content);
print STDERR "\n\t\Retrieving $url\n";
$resp = &www'lrequest('GET',*url,*headers,*content, $gl_document_timeout);
if ($resp =~ /^2/) { # response ok
$gl_picnum++;
if ($headers{'content-type'} eq 'image/gif') {
$pic = "$gl_dir_tmp/pic.$$.".time.".$gl_picnum.gif";
} elsif ($headers{'content-type'} eq 'image/x-xbitmap') {
$pic = "$gl_dir_tmp/pic.$$.".time.".$gl_picnum.xbm";
}
open(OUT, ">$pic"); print OUT $content; close(OUT);
$gl_image_cache{$url} = $pic;
$gl_image_cache_type{$url} = $headers{'content-type'};
open(OUT,">>$gl_cache_file");
print OUT "$url\t$pic\t$headers{'content-type'}\n";
close(OUT);
} else { $pic = $gl_image_error_img; }
}
#print STDERR "headers{'content-type'}='$headers{'content-type'}'\n";
#print STDERR "gl_image_cache{$url}='$gl_image_cache{$url}'\n";
#print STDERR "gl_image_cache_type{$url}='$gl_image_cache_type{$url}'\n";
$content_type = $headers{'content-type'} || $gl_image_cache_type{$url};
#print STDERR "content_type='$content_type'\n";
#if (($content_type eq 'image/gif') || ($content_type eq 'image/x-xbitmap')) {
if ($pic) {
$gl_htext_widget_num++;
$msg .= <',"+&set_window_status('$footer')");
&tk'bind("\$root_win_html.view.$gl_htext_widget_num",'',"+&set_window_status('')");
if ("$opts{'a_href'}") {
if ("$open{'img_ismap'}") {
&tk'bind("\$root_win_html.view.$gl_htext_widget_num",'<1>',"&goto_url('$opts{'a_href'}',0,'%x','%y')");
} else {
&tk'bind("\$root_win_html.view.$gl_htext_widget_num",'<1>',"&goto_url('$opts{'a_href'}')");
}
&tk'bind("\$root_win_html.view.$gl_htext_widget_num",'<3>',"&set_window_url('$opts{'a_href'}')");
}
EOF
}
$msg .= "%%";
}
$opts{'_newlines'} = 0;
#&set_window_status($old) if ($old =~ /\S/);
#print STDERR "html_tag_img returns\n$msg\n";
#print STDERR "gl_msg_after='$gl_msg_after'\n";
return($msg);
}
sub html_tag_em {
local(*opts,*open,*close,$html) = @_;
return unless($html);
local($msg,$emphasis,@parsed);
# Bold tag
if (&w3bbc_html'has_tag($html)) {
@parsed = ();
&w3bbc_html'parse_html(*parsed,$html);
local(@save) = ($opts{'font_emphasis'});
if (($open eq 'b') || ($open eq 'strong') || ($open eq 'dfn')) {
$emphasis = 'bold';
} elsif (($open eq 'i') || ($open eq 'cite') || ($open eq 'em')) {
$emphasis = 'italic';
} else {
die "Don't recognize open tag $open\n";
}
($opts{'font_emphasis'}) = $emphasis;
$msg = &w3bbc_html'process_html(*opts,*parsed);
($opts{'font_emphasis'}) = @save;
} elsif ($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'};
local($routine) = $w3bbc_html'tags_block{'a'};
local(@save) = ($opts{'font_emphasis'});
if (($open eq 'b') || ($open eq 'strong') || ($open eq 'dfn')) {
$emphasis = 'bold';
} elsif (($open eq 'i') || ($open eq 'cite') || ($open eq 'em')) {
$emphasis = 'italic';
} else {
die "Don't recognize open tag $open\n";
}
($opts{'font_emphasis'}) = $emphasis;
$msg = &$routine(*opts,*open2,*close2,$html);
($opts{'font_emphasis'}) = @save;
} else {
$gl_htext_widget_num++;
if (($open eq 'b') || ($open eq 'strong') || ($open eq 'dfn')) {
$emphasis = 'bold';
} elsif (($open eq 'i') || ($open eq 'cite') || ($open eq 'em')) {
$emphasis = 'italic';
} else {
die "Don't recognize open tag $open\n";
}
local(@save) = ($opts{'font_emphasis'});
$opts{'font_emphasis'} = $emphasis;
local(@text,$text);
@text = &w3bbc_html'wordwrap($opts{'_line_len'},$opts{'_max_len'},$html);
local($indent_space) = ($opts{'_textspace'} x ($opts{'_indent'}+1));
for $text (0..$#text) {
$msg .= $indent_space if ($opts{'_indent'} && $text);
$msg .= &tag_display_label(*opts,$text[$text]);
$msg .= &w3bbc_html'newlines(*opts,1) unless($text == $#text);
}
($opts{'font_emphasis'}) = @save;
}
return($msg);
}
sub html_tag_title {
local(*opts,*open,*close,$html) = @_;
return unless($html =~ /\S/);
if (&w3bbc_html'has_tag($html)) {
@parsed = ();
&w3bbc_html'parse_html(*parsed,$html);
$html = &w3bbc_html'process_html(*opts,*parsed);
}
$html = "Title has internal tags that can't be displayed."
if ($html =~ /%%/);
$html = &w3bbc_html'unescape($html);
$html =~ s/\\/\\\\/g;
$html =~ s/'/\\'/g;
return "%%\n\&set_window_title('$html');\n%%";
}
sub html_tag_a {
local(*opts,*open,*close,$html) = @_;
local($url,$msg,@parsed);
if ($open{'a_href'}) {
$url = &wwwurl'absolute($gl_base_url,$open{'a_href'});
$gl_page_url{$url} = 1;
$open{'a_href'} = $url;
} else {
$url = $opts{'a_href'};
$gl_page_url{$url} = 1;
}
&url_seen($url) unless($opts{'_tag'} eq 'a');
if (&w3bbc_html'has_tag($html)) {
@parsed = ();
&w3bbc_html'parse_html(*parsed,$html);
local(@save) = ($opts{'a_href'},$opts{'_tag'});
$opts{'a_href'} = $url;
$opts{'_tag'} = 'a' if ($url);
$msg = &w3bbc_html'process_html(*opts,*parsed);
($opts{'a_href'},$opts{'_tag'}) = @save;
} else {
local($footer,$color);
if ($open{'a_alt'}) { $footer = "($open{'a_alt'}) $url"; }
else { $footer = $url; }
$html =~ s/\s+/ /g;
if ($opts{'_tag'} eq 'pre') {
$msg .= &msg_tag_a(*opts,$html,$url,$footer);
} else {
local(@text,$text);
local($indent_space) = ($opts{'_textspace'} x ($opts{'_indent'}+1));
@text = &w3bbc_html'wordwrap($opts{'_line_len'},$opts{'_max_len'},$html);
for $text (0..$#text) {
$msg .= $indent_space if ($opts{'_indent'} && $text);
#print STDERR "a_href text[$text]='$text[$text]'\n";
$msg .= &msg_tag_a(*opts,$text[$text],$url,$footer) if($text[$text]);
$msg .= &w3bbc_html'newlines(*opts,1) unless($text == $#text);
}
}
}
return($msg);
}
sub msg_tag_a {
local(*opts,$html,$url,$footer) = @_;
local($msg);
&w3bbc_html'display_text(*opts,$html);
$html =~ s/\\/\\\\/g; # Escape backslash
$html =~ s/'/\\'/g; # Escape 'single quotes'
$gl_htext_widget_num++;
$html = &w3bbc_html'unescape($html);
$msg .= <',"&display_footer_url('$footer','%W')");
&tk'bind("\$root_win_html.view.$gl_htext_widget_num",'',"&clear_footer_url('%W')");
&tk'bind("\$root_win_html.view.$gl_htext_widget_num",'<3>',"&set_window_url('$url')");
EOF
}
$msg .= '%%';
return($msg);
}
sub html_tag_h {
local(*opts,*open,*close,$html) = @_;
local($ret,$type,@parsed);
local($start) = $open;
unless ($opts{'_tag'} =~ /^h/i) {
$html =~ s/^\s+//;
$html =~ s/\s+$//;
$ret = &w3bbc_html'newlines(*opts,2);
}
$html =~ s/\s+/ /g;
$start =~ s/^h//i;
$type = 'header' . int($start);
if (&w3bbc_html'has_tag($html)) {
local(@save) = ($opts{'font_type'},$opts{'font_emphasis'},$opts{'_tag'});
$opts{'font_type'} = $type;
$opts{'font_emphasis'} = 'none';
$opts{'_tag'} = $open;
@parsed = ();
&w3bbc_html'parse_html(*parsed,$html);
$ret .= &w3bbc_html'process_html(*opts,*parsed);
($opts{'font_type'},$opts{'font_emphasis'},$opts{'_tag'}) = @save;
} else {
local(@save) = ($opts{'font_type'},$opts{'font_emphasis'});
$opts{'font_type'} = $type;
$opts{'font_emphasis'} = 'none';
local(@text,$text);
@text = &w3bbc_html'wordwrap($opts{'_line_len'},$opts{'_max_len'},$html);
for $text (0..$#text) {
$ret .= &tag_display_label(*opts,$text[$text]);
$ret .= &w3bbc_html'newlines(*opts,1) unless($text == $#text);
}
($opts{'font_type'},$opts{'font_emphasis'}) = @save;
}
$ret .= &w3bbc_html'newlines(*opts,2) unless($opts{'_tag'} =~ /^h/i);
return($ret);
}
sub html_tag_isindex {
local(*opts,*open) = @_;
return "%%\n\&cb_disp_isindex_win('$gl_current_url');\n%%";
}
sub html_tag_pre {
local(*opts,*tag,*close_tag,$html) = @_;
return unless($html);
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{'font_type'} = 'plain';
$opts{'font_emphasis'} = 'none';
$opts{'_tag'} = 'pre';
$ret .= &w3bbc_html'process_html(*opts,*parsed);
($opts{'_tag'},$opts{'font_type'},$opts{'font_emphasis'}) = @save;
} else {
if ($html =~ /[\r\n]/) {
#print STDERR "html\n$html\n";
local($h);
while ($html =~ /[\r\n]/) {
($h,$html) = split(/[\r\n]/,$html,2);
$ret .= &w3bbc_html'unescape($h);
&w3bbc_html'display_text(*opts,$h);
$ret .= &w3bbc_html'newlines(*opts,1);
}
}
if ($html) {
local($esc) = &w3bbc_html'unescape($html);
&w3bbc_html'display_text(*opts,$esc);
$ret .= $esc;
}
}
return($ret);
}
sub tag_display_label {
local(*opts,$html) = @_;
#print STDERR "tag_display_label(opts,$font,$html)\n";
#print STDERR "opts{'font_type'}='$opts{'font_type'}'\n";
#print STDERR "opts{'font_emphasis'}='$opts{'font_emphasis'}'\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);
local($ret);
$html = &w3bbc_html'unescape($html);
$gl_htext_widget_num++;
&w3bbc_html'display_text(*opts,$html);
$html =~ s/\\/\\\\/g; # Escape backslash
$html =~ s/'/\\'/g; # Escape 'single quotes'
$ret .= <