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

CAVEATS

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

AUTHOR

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

SEE ALSO

150       perl(1), HTML::Formatter.
151
152
153
154perl v5.12.0                      2007-04-18    HTML::FormatText::WithLinks(3)
Impressum