File: element-format.pl

package info (click to toggle)
libhtml-formatexternal-perl 26-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 408 kB
  • ctags: 115
  • sloc: perl: 2,397; sh: 164; makefile: 10
file content (89 lines) | stat: -rw-r--r-- 2,857 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl -w

# Copyright 2013 Kevin Ryde

# HTML-FormatExternal is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 3, or (at your option) any
# later version.
#
# HTML-FormatExternal is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with HTML-FormatExternal.  If not, see <http://www.gnu.org/licenses/>.

use strict;
use warnings;
use Module::Load;
use HTML::TreeBuilder;
use Data::Dumper;
$Data::Dumper::Useqq = 1;
use FindBin qw($Bin);

my $class;
$class = 'HTML::FormatText::WithLinks';
$class = 'HTML::FormatText::WithLinks::AndTables';
$class = 'HTML::FormatText::W3m';
$class = 'HTML::FormatText';
$class = 'HTML::FormatText::Netrik';
$class = 'HTML::FormatText::Links';
$class = 'HTML::FormatText::Html2text';
$class = 'HTML::FormatText::Elinks';
$class = 'HTML::FormatText::Lynx';
Module::Load::load ($class);

#  <base href="file:///tmp/">

{
  # output_charset => 'ascii',
  # output_charset => 'ANSI_X3.4-1968',
  # output_charset => 'utf-8'
  my $output_charset = 'utf-8';

  # input_charset => 'shift-jis',
  # input_charset => 'iso-8859-1',
  # input_charset => 'utf-8',
  my $input_charset;
  $input_charset = 'utf16le';
  $input_charset = 'ascii';

  my $formatter = $class->new (
                               input_charset  => $input_charset,
                               output_charset => $output_charset,
                               rightmargin => 60,
                               # leftmargin => 20,
                               justify => 1,

                               base => "http://foo.org/\x{2022}/foo.html",


                               #      lynx_options => [ '-underscore',
                               #                        '-underline_links',
                               #                        '-with_backspaces',
                               #                      ],
                               justify => 1,
                              );

  # {
  #   my $filename = "$FindBin::Bin/base.html";
  #   # my $filename = "/tmp/rsquo.html";
  #   my $tree = HTML::TreeBuilder->new;
  #   $tree->parse_file($filename);
  # }

  my $tree = HTML::Element->new('a', href => 'http://www.perl.com/');
  $tree->push_content("The Perl Homepage");
  print "$tree\n";
  print $tree->as_HTML;

  my $str = $tree->format($formatter);
  $Data::Dumper::Purity = 1;
  print $str;
  print Data::Dumper->new([\$str],['output'])->Useqq(0)->Dump;
  print "utf8 flag ",(utf8::is_utf8($str) ? 'yes' : 'no'), "\n";
  exit 0;
}