From 5beb2bf906164db1eb597bd3acd2eb5decfd64ba Mon Sep 17 00:00:00 2001 From: b Date: Tue, 29 Aug 2023 22:45:30 +0000 Subject: [PATCH] now generate with full page html & css --- botm-common | 2 +- post_common.1.pm | 266 ++++++++++++++++++++++++++++++++++++++++++----- preview.1.pl | 94 +++++++++++++++-- 3 files changed, 327 insertions(+), 35 deletions(-) diff --git a/botm-common b/botm-common index bdf2577..6b789b4 160000 --- a/botm-common +++ b/botm-common @@ -1 +1 @@ -Subproject commit bdf2577b82d59fed0450c2a8fc61a46efe5d19eb +Subproject commit 6b789b4bd0ac1d87d3a2d8598ad229298e2c4777 diff --git a/post_common.1.pm b/post_common.1.pm index e0c78dc..b1a3f8e 100644 --- a/post_common.1.pm +++ b/post_common.1.pm @@ -31,7 +31,9 @@ our @EXPORT_OK = ( 'prepare_post', 'wget', 'CODE', - 'bbcode_to_html' + 'bbcode_to_html', + 'HTML_PAGE_START', 'HTML_PAGE_END', 'HTML_POST_START', 'HTML_POST_END', + 'HTML_STYLE' ); ###PERL_LIB: use lib '/botm/lib/post'; @@ -181,6 +183,194 @@ sub prepare_post { return %post; } +######## +# HTML # +######## + +use constant HTML_PAGE_START => { + 'botm' => [ + '', + '', + '', + '&_title;', + '', + '', + '', + # '

&_title;

', + '' + ], + 'bsta' => [ + ], + 'phpbb' => [ + ] +}; + +use constant HTML_POST_START => { + 'botm' => [ + '
', + '
&_subject;
', + '
&_username; • &_time;
', + '
', + '' + ], + 'bsta' => [ + ], + 'phpbb' => [ + ] +}; + +use constant HTML_POST_END => { + 'botm' => [ + '
', + '' + ], + 'bsta' => [ + ], + 'phpbb' => [ + ] +}; + +use constant HTML_PAGE_END => { + 'botm' => [ + '' + ], + 'bsta' => [ + ], + 'phpbb' => [ + ] +}; + +# TODO get CSS from silent chronotransponder +use constant HTML_STYLE => { + 'botm' => [ + '', + 'html', + '{', + ' background-color: #ffffff;', + ' border-color: #000000;', + ' color: #000000;', + '}', + 'a', + '{', + ' border-color:', + ' #0057af;', + ' color: #0057af;', + ' text-decoration:underline;', + '}', + 'a:visited', + '{', + ' border-color: #bb6622;', + ' color: #bb6622;', + '}', + 'a:hover', + '{', + ' border-color: #bb6622;', + ' color: #bb6622;', + '}', + 'a:hover:visited', + '{', + ' border-color: #0057af;', + ' color: #0057af;', + '}', + '::selection', + '{', + ' color: #ffffff;', + ' background-color: #bb6622;', + '}', + '.br', + '{', + ' border-color:', + ' #bb6622!important;', + ' color: #bb6622!important;', + '}', + '.ni', + '{', + ' border-color: #0057af!important;', + ' color: #0057af!important;', + '}', + '.bi', + '{', + ' border-color: #ffffff!important;', + ' color: #ffffff!important;', + '}', + 'div.pl', + '{', + ' border-color: #0057af;', + ' border-width: 4px 16px 16px 16px;', + ' border-style: solid;', + '}', + '.tp', + '{', + ' text-align: right;', + '}', + 'div.pls', + '{', + ' text-align: center;', + ' font-weight: bold;', + ' color: #ffffff;', + ' background-color: #0057af;', + ' width: 100%;', + '}', + 'div.plt', + '{', + ' color: #ffffff;', + ' background-color: #0057af;', + ' width: 100%;', + ' clear: both;', + '}', + 'div.plw', + '{', + ' background-color: #ffffff;', + ' color: #000000;', + ' padding: 4px;', + ' clear: both;', + '}', + 'blockquote.pq', + '{', + ' color: #000000;', + ' background-color: #ffffff;', + ' text-decoration: inherit;', + ' font: inherit;', + ' border-color: #bb6622;', + ' border-width: 4px;', + ' border-style: solid;', + ' padding: 2px;', + '}', + 'cite.pq', + '{', + ' text-decoration:', + ' inherit;', + ' font: inherit;', + '}', + 'dl.pq', + '{', + ' color: #000000;', + ' background-color: #ffffff;', + ' border-color: #0057af;', + ' border-width: 4px;', + ' border-style: solid;', + ' padding: 2px;', + '}', + 'dt.pq', + '{', + ' color: #0057af;', + ' font-weight: bold;', + '}', + 'code.pq', + '{', + ' max-height: 200px;', + ' overflow: auto;', + ' white-space: normal;', + ' display: block;', + '}', + '' + ], + 'bsta' => [ + ], + 'phpbb' => [ + ] +}; + ########## # BBCODE # ########## @@ -777,7 +967,7 @@ sub bbcode_to_html { if ($print) { print "unmatched tag\n"; } - $add_html .= html_entity_encode_dec($tag); + $add_html .= html_entity_encode_dec($tag, 1); } elsif ($tag_name eq '_') { @@ -786,18 +976,26 @@ sub bbcode_to_html { elsif ($tag_name eq 'quote') { if ($tag_value eq '') { - $add_html .= '
'; - #$add_html .= '
'; + if ($cmd_options->{'post-style'} eq 'phpbb') { + $add_html .= '
'; + } + else { + $add_html .= '
'; + } } else { if ($tag_value =~ m/^"(.*)"$/gs) { $tag_value = bbcode_to_html($cmd_options, $post, $1); } else { - $tag_value = 'QUOTE MARKS MISSING; '.html_entity_encode_dec($tag_value) + $tag_value = 'QUOTE MARKS MISSING; '.html_entity_encode_dec($tag_value, 1) + } + if ($cmd_options->{'post-style'} eq 'phpbb') { + $add_html .= '
'.$tag_value.' wrote:'; + } + else { + $add_html .= '
'.$tag_value.' wrote:
'; } - $add_html .= '
'.$tag_value.' wrote:'; - # $add_html .= '
'.$tag_value.' wrote:
'; } } @@ -827,11 +1025,15 @@ sub bbcode_to_html { if ($print) { print "not a tag, actually\n"; } - $add_html .= html_entity_encode_dec($tag); + $add_html .= html_entity_encode_dec($tag, 1); } else { - $add_html .= '
Code: Select all
'; - # $add_html .= '
Code: Select all
'; + if ($cmd_options->{'post-style'} eq 'phpbb') { + $add_html .= '
Code: Select all
'; + } + else { + $add_html .= '
Code: Select all
'; + } } if ($tag_value ne '') { $add_html .= 'INVALID VALUE; '; @@ -850,7 +1052,7 @@ sub bbcode_to_html { print 'Implied value: '.$tag_value."\n"; } } - $add_html .= ''; + $add_html .= ''; } elsif ($tag_name eq 'size') { @@ -907,8 +1109,12 @@ sub bbcode_to_html { } elsif ($tag_name eq 'spoiler') { - $add_html .= '
Spoiler:
'; - # $add_html .= '
Spoiler:
'; + if ($cmd_options->{'post-style'} eq 'phpbb') { + $add_html .= '
Spoiler:
'; + } + else { + $add_html .= '
Spoiler:
'; + } if ($tag_value ne '') { $add_html .= 'INVALID VALUE; '; } @@ -953,7 +1159,7 @@ sub bbcode_to_html { if ($print) { print "unknown tag\n" } - $add_html .= html_entity_encode_dec($tag); + $add_html .= html_entity_encode_dec($tag, 1); } } @@ -964,7 +1170,7 @@ sub bbcode_to_html { if ($print) { print "unmatched tag\n"; } - $add_html .= html_entity_encode_dec($tag_end); + $add_html .= html_entity_encode_dec($tag_end, 1); } elsif ($tag_name eq '_') { @@ -985,7 +1191,7 @@ sub bbcode_to_html { if ($print) { print "not a tag, actually\n"; } - $add_html .= html_entity_encode_dec($tag_end); + $add_html .= html_entity_encode_dec($tag_end, 1); } else { $add_html .= '
'; @@ -993,8 +1199,12 @@ sub bbcode_to_html { } elsif ($tag_name eq 'img') { - $add_html .= '" alt="Image" />'; - # $add_html .= '" alt="Image">'; + if ($cmd_options->{'post-style'} eq 'phpbb') { + $add_html .= '" alt="Image" />'; + } + else { + $add_html .= '" alt="Image">'; + } if ($tag_value ne '') { $add_html .= 'INVALID VALUE; '; } @@ -1042,7 +1252,7 @@ sub bbcode_to_html { if ($print) { print "unknown tag\n"; } - $add_html .= html_entity_encode_dec($tag_end); + $add_html .= html_entity_encode_dec($tag_end, 1); } } @@ -1062,7 +1272,7 @@ sub bbcode_to_html { # and this will not interfere with detecting the start and end # of an URL which needs to be escaped anyway. - $text = html_entity_encode_dec($text); + $text = html_entity_encode_dec($text, 1); # preserve indentation in [code] if ($in_code > 0) { @@ -1077,13 +1287,21 @@ sub bbcode_to_html { # convert smilies if (($post->{'smilies'}) and ($tag_name !~ /^((code)|(img))$/)) { - $text =~ s/(^|[ \t])((:([D\(\)o\?xP\|]|(((shock)|(lol)|(oops)|(cry)|(evil)|(twisted)|(roll)|(wink)|(idea)|(arrow)|(mrgreen)|[!\?]):)))|(8-\))|(;\)))($|[ \t])/' '.$2.' '/gme; - # $text =~ s/(^|[ \t])((:([D\(\)o\?xP\|]|(((shock)|(lol)|(oops)|(cry)|(evil)|(twisted)|(roll)|(wink)|(idea)|(arrow)|(mrgreen)|[!\?]):)))|(8-\))|(;\)))($|[ \t])/' '.$2.' '/gme; + if ($cmd_options->{'post-style'} eq 'phpbb') { + $text =~ s/(^|[ \t])((:([D\(\)o\?xP\|]|(((shock)|(lol)|(oops)|(cry)|(evil)|(twisted)|(roll)|(wink)|(idea)|(arrow)|(mrgreen)|[!\?]):)))|(8-\))|(;\)))($|[ \t])/' '.$2.' '/gme; + } + else { + $text =~ s/(^|[ \t])((:([D\(\)o\?xP\|]|(((shock)|(lol)|(oops)|(cry)|(evil)|(twisted)|(roll)|(wink)|(idea)|(arrow)|(mrgreen)|[!\?]):)))|(8-\))|(;\)))($|[ \t])/' '.$2.' '/gme; + } } # convert NL - $text =~ s/\r?\n/\n/gs; - # $text =~ s/\r?\n/
\n/gs; + if ($cmd_options->{'post-style'} eq 'phpbb') { + $text =~ s/\r?\n/\n/gs; + } + else { + $text =~ s/\r?\n/
\n/gs; + } $add_html .= $text; } diff --git a/preview.1.pl b/preview.1.pl index e1489aa..e176711 100644 --- a/preview.1.pl +++ b/preview.1.pl @@ -23,12 +23,15 @@ use Encode ('encode', 'decode'); ###PERL_LIB: use lib '/botm/lib/post'; use botm_common ( - 'read_data_file', 'write_data_file' + 'read_data_file', 'write_data_file', + 'html_entity_encode_dec' ); use post_common ( 'prepare_post', 'CODE', - 'bbcode_to_html' + 'bbcode_to_html', + 'HTML_PAGE_START', 'HTML_PAGE_END', 'HTML_POST_START', 'HTML_POST_END', + 'HTML_STYLE' ); ###PERL_VERSION: use constant VERSION => 'x.x.x'; @@ -59,6 +62,14 @@ use constant HELP_TEXT => "\n". " -o, --output-file=OUTPUT_FILE\n". "\n". + " --content-only\n". + " --smiley-url=SMILEY_URL\n". + " --css-url=CSS_URL\n". + " --inline-css\n". + " --post-style=\n". + " phpbb\n". + " botm\n". + "\n". " -q, --quiet\n". " -v, --verbose\n". # " --keep-tempfile\n". @@ -95,7 +106,13 @@ GetOptions ( 'notify|N' => \$options{ 'notify'}, 'no-notify|n' => \$options{'no-notify'}, - 'output-file|o=s' => \$options{'output-file'}, + 'output-file|o=s'=> \$options{'output-file'}, + + 'content-only' => \$options{'content-only'}, + 'smiley-url=s' => \$options{'smiley-url'}, + 'css-url=s' => \$options{'css-url'}, + 'inline-css' => \$options{'inline-css'}, + 'post-style=s' => \$options{'post-style'}, 'quiet|q' => \$options{'quiet'}, 'verbose|v' => \$options{'verbose'}, @@ -127,6 +144,10 @@ if ($options{'quiet'} ne '') { if (($options{'output-file'} eq '') and ($options{'verbose'} eq '')) { $options{'quiet'} = '1'; } +if ($options{'post-style'} !~ /^((botm)|(bsta)|(phpbb))$/) { + # $options{'post-style'} = 'phpbb'; + $options{'post-style'} = 'botm'; +} unless ($options{'quiet'} ne '') { print "PREVIEW $$ $time - $timetext\n\n"; @@ -142,6 +163,11 @@ if ((scalar @ARGV) == 0) { } my $fh; +my $code; +my %data; +my %post; +my $html; + if ($options{'output-file'} ne '') { unless (open ($fh, '>:encoding(UTF-8)', encode('locale_fs', $options{'output-file'}))) { unless ($options{'quiet'} ne '') { @@ -153,12 +179,16 @@ if ($options{'output-file'} ne '') { } else { $fh = \*STDOUT; + binmode STDOUT, ':encoding(UTF-8)'; +} + +$code = CODE->{'OK'}; + +unless ($options{'content-only'} ne '') { + print_preview($fh, HTML_PAGE_START(), \%post, \%options); } -my $code = CODE->{'OK'}; foreach my $arg (@ARGV) { - my $r; - unless ($options{'quiet'} ne '') { if ($arg == \*STDIN) { print "STDIN\n"; @@ -168,7 +198,7 @@ foreach my $arg (@ARGV) { } } - my %data = (); + %data = (); unless (($arg == \*STDIN) and ($options{'content'} ne '') and ($options{'data-only'} ne '')) { %data = read_data_file($arg, ENCODING_FILE, $options{'data-only'}); @@ -192,7 +222,7 @@ foreach my $arg (@ARGV) { print "\n"; } - my %post = prepare_post(\%options, \%data); + %post = prepare_post(\%options, \%data); if ($options{'verbose'} ne '') { print "POST\n"; write_data_file(\*STDOUT, 'console_out', 0, \%post); @@ -200,7 +230,7 @@ foreach my $arg (@ARGV) { } # now generate preview - my $html = bbcode_to_html(\%options, \%post); + $html = bbcode_to_html(\%options, \%post); if ($options{'verbose'} ne '') { print "HTML\n"; @@ -208,9 +238,53 @@ foreach my $arg (@ARGV) { print "\n"; } + unless ($options{'content-only'} ne '') { + print_preview($fh, HTML_POST_START(), \%post, \%options); + } + print $fh $html."\n"; + + unless ($options{'content-only'} ne '') { + print_preview($fh, HTML_POST_END(), \%post, \%options); + } +} +unless ($options{'content-only'} ne '') { + print_preview($fh, HTML_PAGE_END(), \%post, \%options); } - close ($fh); exit $code; + + +sub print_preview { + (my $fh, my $data, my $post, my $options) = @_; + + my @data_list = @{$data->{$options->{'post-style'}}}; + + foreach my $data_line (@data_list) { + + if ($data_line =~ m/&_css_url;/gs) { + if ($options->{'css-url'} ne '') { + print $fh $`. $options->{'css-url'} . $' . "\n"; + } + next; + } + + if ($data_line =~ m/&_inline_css;/gs) { + if ($options->{'inline-css'} ne '') { + print $fh $`; + print_preview($fh, HTML_STYLE(), $post, $options); + print $fh $' . "\n"; + } + next; + } + + $data_line =~ s/&_title;/preview/gs; + $data_line =~ s/&_subject;/html_entity_encode_dec($post->{'subject'},1)/gse; + $data_line =~ s/&_username;/html_entity_encode_dec($post->{'username'},1)/gse; + $data_line =~ s/&_time;/\$time/gs; # TODO + $data_line =~ s/&_post_class;/html_entity_encode_dec($post->{'class'},1)/gse; + + print $fh $data_line."\n"; + } +} \ No newline at end of file -- 2.30.2