1HTML::FormatText::WithLUisnekrs(C3o)ntributed Perl DocumHeTnMtLa:t:iFoonrmatText::WithLinks(3)
2
3
4

NAME

6       HTML::FormatText::WithLinks - HTML to text conversion with links as
7       footnotes
8

SYNOPSIS

10           use HTML::FormatText::WithLinks;
11
12           my $f = HTML::FormatText::WithLinks->new();
13
14           my $html = qq(
15           <html>
16           <body>
17           <p>
18               Some html with a <a href="http://example.com/">link</a>
19           </p>
20           </body>
21           </html>
22           );
23
24           my $text = $f->parse($html);
25
26           print $text;
27
28           # results in something like
29
30           Some html with a [1]link
31
32           1. http://example.com/
33
34           my $f2 = HTML::FormatText::WithLinks->new(
35               before_link => '',
36               after_link => ' [%l]',
37               footnote => ''
38           );
39
40           $text = $f2->parse($html);
41           print $text;
42
43           # results in something like
44
45           Some html with a link [http://example.com/]
46
47           my $f3 = HTML::FormatText::WithLinks->new(
48               link_num_generator => sub {
49                   return "*" x (shift() + 1);
50               },
51               footnote => '[%n] %l'
52           );
53
54           $text = $f3->parse($html);
55           print $text;
56
57           # results in something like
58
59           Some html with a [*]link
60
61           [*] http://example.com/
62

DESCRIPTION

64       HTML::FormatText::WithLinks takes HTML and turns it into plain text but
65       prints all the links in the HTML as footnotes. By default, it attempts
66       to mimic the format of the lynx text based web browser's --dump option.
67

METHODS

69       new
70
71           my $f = HTML::FormatText::WithLinks->new( %options );
72
73       Returns a new instance. It accepts all the options of HTML::FormatText
74       plus
75
76       base
77           a base option. This should be set to a URI which will be used to
78           turn any relative URIs on the HTML to absolute ones.
79
80       before_link (default: '[%n]')
81       after_link (default: '')
82       footnote (default: '[%n] %l')
83           a string to print before a link (i.e. when the <a> is found), after
84           link has ended (i.e. when then </a> is found) and when printing out
85           footnotes.
86
87           "%n" will be replaced by the link number, "%l" will be replaced by
88           the link itself.
89
90           If footnote is set to '', no footnotes will be printed.
91
92       link_num_generator (default: sub { return shift() + 1 })
93           link_num_generator is a sub that returns the value to be printed
94           for a given link number. The internal store starts numbering at 0.
95
96       with_emphasis
97           If set to 1 then italicised text will be surrounded by / and bolded
98           text by _.
99
100       parse
101
102           my $text = $f->parse($html);
103
104       Takes some HTML and returns it as text. Returns undef on error.
105
106       Will also return undef if you don't pass it undef. Returns an empty
107       string if passed an empty string.
108
109       parse_file
110
111           my $text = $f->parse_file($filename);
112
113       Takes a filename and returns the contents of the file as plain text.
114       Returns undef on error.
115
116       error
117
118           $f->error();
119
120       Returns the last error that occured. In practice this is likely to be
121       either a warning that parse_file couldn't find the file or that
122       HTML::TreeBuilder failed.
123

CAVEATS

125       When passing HTML fragments the results may be a little unpredictable.
126       I've tried to work round the most egregious of the issues but any unex‐
127       pected results are welcome.
128
129       Also note that if for some reason there is an a tag in the document
130       that does not have an href attribute then it will be quietly ignored.
131       If this is really a problem for anyone then let me know and I'll see if
132       I can think of a sensible thing to do in this case.
133

AUTHOR

135       Struan Donald. <struan@cpan.org>
136
137       <http://www.exo.org.uk/code/>
138
139       Ian Malpass <ian@indecorous.com> was responsible for the custom format‐
140       ting bits and the nudge to release the code.
141
143       Copyright (C) 2003 Struan Donald and Ian Malpass. All rights reserved.
144
145       This program is free software; you can redistribute it and/or modify it
146       under the same terms as Perl itself.
147

SEE ALSO

149       perl(1), HTML::Formatter.
150
151
152
153perl v5.8.8                       2006-08-30    HTML::FormatText::WithLinks(3)
Impressum