Debian Codegraph @

lib/Text/Markup/HTML.pm

raw
1 package Text::Markup::HTML;
2
3 use 5.8.1;
4 use strict;
5 use warnings;
6 use Text::Markup;
7
8 our $VERSION = '0.41';
9
10 sub import {
11 # Replace the regex if passed one.
12 Text::Markup->register( html => $_[1] ) if $_[1];
13 }
14
15 sub parser {
16 my ($file, $encoding, $opts) = @_;
17 my $html = do {
18 open my $fh, '<:raw', $file or die "Cannot open $file: $!\n";
19 local $/;
20 <$fh>;
21 };
22 return $html =~ /\S/ ? $html : undef
23 }
24
25 1;
26 __END__
27
28 =head1 Name
29
30 Text::Markup::HTML - HTML parser for Text::Markup
31
32 =head1 Synopsis
33
34 use Text::Markup;
35 my $html = Text::Markup->new->parse(file => 'hello.html');
36
37 =head1 Description
38
39 This is the L<HTML|https://whatwg.org/html/> parser for L<Text::Markup>. All
40 it does is read in the HTML file and return it as a string. It makes no
41 assumptions about encoding, and returns the string raw as read from the file,
42 with no decoding. It recognizes files with the following extensions as HTML:
43
44 =over
45
46 =item F<.html>
47
48 =item F<.htm>
49
50 =item F<.xhtml>
51
52 =item F<.xhtm>
53
54 =back
55
56 To change it the files it recognizes, load this module directly and pass a
57 regular expression matching the desired extension(s), like so:
58
59 use Text::Markup::HTML qr{hachetml};
60
61 =head1 Author
62
63 David E. Wheeler <[email protected]>
64
65 =head1 Copyright and License
66
67 Copyright (c) 2011-2025 David E. Wheeler. Some Rights Reserved.
68
69 This module is free software; you can redistribute it and/or modify it under
70 the same terms as Perl itself.
71
72 =cut