3 # t/xhtml01.t - check basic output from Pod::Simple::XHTML
11 #use Test::More tests => 56;
12 use Test::More 'no_plan';
14 use_ok('Pod::Simple::XHTML') or exit;
16 my $parser = Pod::Simple::XHTML->new ();
17 isa_ok ($parser, 'Pod::Simple::XHTML');
21 my $PERLDOC = "http://search.cpan.org/perldoc";
22 my $MANURL = "http://man.he.net/man";
24 initialize($parser, $results);
25 $parser->parse_string_document( "=head1 Poit!" );
26 is($results, qq{<h1 id="Poit-">Poit!</h1>\n\n}, "head1 level output");
28 initialize($parser, $results);
29 $parser->parse_string_document( "=head2 Yada Yada Operator
30 X<...> X<... operator> X<yada yada operator>" );
31 is($results, qq{<h2 id="Yada-Yada-Operator">Yada Yada Operator </h2>\n\n}, "head ID with X<>");
33 initialize($parser, $results);
34 $parser->html_h_level(2);
35 $parser->parse_string_document( "=head1 Poit!" );
36 is($results, qq{<h2 id="Poit-">Poit!</h2>\n\n}, "head1 level output h_level 2");
38 initialize($parser, $results);
39 $parser->parse_string_document( "=head2 I think so Brain." );
40 is($results, qq{<h2 id="I-think-so-Brain.">I think so Brain.</h2>\n\n}, "head2 level output");
42 initialize($parser, $results);
43 $parser->parse_string_document( "=head3 I say, Brain..." );
44 is($results, qq{<h3 id="I-say-Brain...">I say, Brain...</h3>\n\n}, "head3 level output");
46 initialize($parser, $results);
47 $parser->parse_string_document( "=head4 Zort & Zog!" );
48 is($results, qq{<h4 id="Zort-Zog-">Zort & Zog!</h4>\n\n}, "head4 level output");
52 Pod::Simple::XHTML->_out(
53 sub { $code->($_[0]) if $code },
58 x("=head1 Header\n\n=for html <div>RAW<span>!</span></div>\n\nDone."),
59 qr/.+<\/h1>\s+<div>RAW<span>!<\/span><\/div>\s+.*/sm,
63 initialize($parser, $results);
64 $parser->parse_string_document(<<'EOPOD');
67 Gee, Brain, what do you want to do tonight?
70 is($results, <<'EOHTML', "simple paragraph");
71 <p>Gee, Brain, what do you want to do tonight?</p>
76 initialize($parser, $results);
77 $parser->parse_string_document(<<'EOPOD');
80 B: Now, Pinky, if by any chance you are captured during this mission,
81 remember you are Gunther Heindriksen from Appenzell. You moved to
82 Grindelwald to drive the cog train to Murren. Can you repeat that?
84 P: Mmmm, no, Brain, dont think I can.
87 is($results, <<'EOHTML', "multiple paragraphs");
88 <p>B: Now, Pinky, if by any chance you are captured during this mission, remember you are Gunther Heindriksen from Appenzell. You moved to Grindelwald to drive the cog train to Murren. Can you repeat that?</p>
90 <p>P: Mmmm, no, Brain, dont think I can.</p>
94 initialize($parser, $results);
95 $parser->parse_string_document(<<'EOPOD');
100 P: Gee, Brain, what do you want to do tonight?
104 B: The same thing we do every night, Pinky. Try to take over the world!
110 is($results, <<'EOHTML', "simple bulleted list");
113 <li><p>P: Gee, Brain, what do you want to do tonight?</p>
116 <li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p>
124 initialize($parser, $results);
125 $parser->parse_string_document(<<'EOPOD');
130 P: Gee, Brain, what do you want to do tonight?
134 B: The same thing we do every night, Pinky. Try to take over the world!
152 is($results, <<'EOHTML', "nested bulleted list");
155 <li><p>P: Gee, Brain, what do you want to do tonight?</p>
158 <li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p>
162 <li><p>Take over world</p>
165 <li><p>Do laundry</p>
177 initialize($parser, $results);
178 $parser->parse_string_document(<<'EOPOD');
183 P: Gee, Brain, what do you want to do tonight?
187 B: The same thing we do every night, Pinky. Try to take over the world!
193 is($results, <<'EOHTML', "numbered list");
196 <li><p>P: Gee, Brain, what do you want to do tonight?</p>
199 <li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p>
207 initialize($parser, $results);
208 $parser->parse_string_document(<<'EOPOD');
213 P: Gee, Brain, what do you want to do tonight?
217 B: The same thing we do every night, Pinky. Try to take over the world!
235 is($results, <<'EOHTML', "nested numbered list");
238 <li><p>P: Gee, Brain, what do you want to do tonight?</p>
241 <li><p>B: The same thing we do every night, Pinky. Try to take over the world!</p>
245 <li><p>Take over world</p>
248 <li><p>Do laundry</p>
259 initialize($parser, $results);
260 $parser->parse_string_document(<<'EOPOD');
265 Gee, Brain, what do you want to do tonight?
269 The same thing we do every night, Pinky. Try to take over the world!
275 is($results, <<'EOHTML', "list with text headings");
281 <p>Gee, Brain, what do you want to do tonight?</p>
287 <p>The same thing we do every night, Pinky. Try to take over the world!</p>
294 initialize($parser, $results);
295 $parser->parse_string_document(<<'EOPOD');
300 Gee, Brain, what do you want to do tonight?
304 The same thing we do every night, Pinky. Try to take over the world!
310 is($results, <<'EOHTML', "list with bullet and text headings");
315 <p>Gee, Brain, what do you want to do tonight?</p>
320 <p>The same thing we do every night, Pinky. Try to take over the world!</p>
327 initialize($parser, $results);
328 $parser->parse_string_document(<<'EOPOD');
331 =item * Brain <brain@binkyandthebrain.com>
333 =item * Pinky <pinky@binkyandthebrain.com>
339 is($results, <<'EOHTML', "bulleted author list");
342 <li><p>Brain <brain@binkyandthebrain.com></p>
345 <li><p>Pinky <pinky@binkyandthebrain.com></p>
352 initialize($parser, $results);
353 $parser->parse_string_document(<<'EOPOD');
360 =item World Domination
370 is($results, <<'EOHTML', 'nested lists');
378 <dt>World Domination</dt>
393 initialize($parser, $results);
394 $parser->parse_string_document(<<'EOPOD');
403 =item World Domination
421 is($results, <<'EOHTML', 'multiparagraph nested lists');
431 <dt>World Domination</dt>
434 <p>Fight the good fight</p>
437 <dt>Go to Europe</dt>
440 <p>(Steve Martin joke)</p>
456 initialize($parser, $results);
457 $parser->parse_string_document(<<'EOPOD');
465 is($results, <<'EOHTML', "code block");
466 <pre><code> 1 + 1 = 2;
467 2 + 2 = 4;</code></pre>
472 initialize($parser, $results);
473 $parser->parse_string_document(<<'EOPOD');
476 A plain paragraph with a C<functionname>.
478 is($results, <<"EOHTML", "code entity in a paragraph");
479 <p>A plain paragraph with a <code>functionname</code>.</p>
484 initialize($parser, $results);
485 $parser->html_header("<html>\n<body>");
486 $parser->html_footer("</body>\n</html>");
487 $parser->parse_string_document(<<'EOPOD');
490 A plain paragraph with body tags turned on.
492 is($results, <<"EOHTML", "adding html body tags");
496 <p>A plain paragraph with body tags turned on.</p>
504 initialize($parser, $results);
505 $parser->html_css('style.css');
506 $parser->html_header(undef);
507 $parser->html_footer(undef);
508 $parser->parse_string_document(<<'EOPOD');
511 A plain paragraph with body tags and css tags turned on.
513 like($results, qr/<link rel='stylesheet' href='style.css' type='text\/css' \/>/,
514 "adding html body tags and css tags");
517 initialize($parser, $results);
518 $parser->parse_string_document(<<'EOPOD');
521 A plain paragraph with S<non breaking text>.
523 is($results, <<"EOHTML", "Non breaking text in a paragraph");
524 <p>A plain paragraph with <span style="white-space: nowrap;">non breaking text</span>.</p>
528 initialize($parser, $results);
529 $parser->parse_string_document(<<'EOPOD');
532 A plain paragraph with a L<Newlines>.
534 is($results, <<"EOHTML", "Link entity in a paragraph");
535 <p>A plain paragraph with a <a href="$PERLDOC?Newlines">Newlines</a>.</p>
539 initialize($parser, $results);
540 $parser->parse_string_document(<<'EOPOD');
543 A plain paragraph with a L<perlport/Newlines>.
545 is($results, <<"EOHTML", "Link entity in a paragraph");
546 <p>A plain paragraph with a <a href="$PERLDOC?perlport#Newlines">"Newlines" in perlport</a>.</p>
550 initialize($parser, $results);
551 $parser->parse_string_document(<<'EOPOD');
554 A plain paragraph with a L<Boo|http://link.included.here>.
556 is($results, <<"EOHTML", "A link in a paragraph");
557 <p>A plain paragraph with a <a href="http://link.included.here">Boo</a>.</p>
561 initialize($parser, $results);
562 $parser->parse_string_document(<<'EOPOD');
565 A plain paragraph with a L<http://link.included.here>.
567 is($results, <<"EOHTML", "A link in a paragraph");
568 <p>A plain paragraph with a <a href="http://link.included.here">http://link.included.here</a>.</p>
572 initialize($parser, $results);
573 $parser->parse_string_document(<<'EOPOD');
576 A plain paragraph with a L<http://link.included.here?o=1&p=2>.
578 is($results, <<"EOHTML", "A link in a paragraph");
579 <p>A plain paragraph with a <a href="http://link.included.here?o=1&p=2">http://link.included.here?o=1&p=2</a>.</p>
583 initialize($parser, $results);
584 $parser->parse_string_document(<<'EOPOD');
587 A plain paragraph with B<bold text>.
589 is($results, <<"EOHTML", "Bold text in a paragraph");
590 <p>A plain paragraph with <b>bold text</b>.</p>
594 initialize($parser, $results);
595 $parser->parse_string_document(<<'EOPOD');
598 A plain paragraph with I<italic text>.
600 is($results, <<"EOHTML", "Italic text in a paragraph");
601 <p>A plain paragraph with <i>italic text</i>.</p>
605 initialize($parser, $results);
606 $parser->parse_string_document(<<'EOPOD');
609 A plain paragraph with a F<filename>.
611 is($results, <<"EOHTML", "File name in a paragraph");
612 <p>A plain paragraph with a <i>filename</i>.</p>
616 # It's not important that 's (apostrophes) be encoded for XHTML output.
617 initialize($parser, $results);
618 $parser->parse_string_document(<<'EOPOD');
621 # this header is very important & dont you forget it
622 my $text = "File is: " . <FILE>;
624 is($results, <<"EOHTML", "Verbatim text with encodable entities");
625 <pre><code> # this header is very important & dont you forget it
626 my \$text = "File is: " . <FILE>;</code></pre>
630 initialize($parser, $results);
631 $parser->parse_string_document(<<'EOPOD');
634 A text paragraph using E<sol> and E<verbar> special POD entities.
637 is($results, <<"EOHTML", "Text with decodable entities");
638 <p>A text paragraph using / and | special POD entities.</p>
642 initialize($parser, $results);
643 $parser->parse_string_document(<<'EOPOD');
646 A text paragraph using numeric POD entities: E<60>, E<62>.
649 is($results, <<"EOHTML", "Text with numeric entities");
650 <p>A text paragraph using numeric POD entities: <, >.</p>
654 SKIP: for my $use_html_entities (0, 1) {
655 if ($use_html_entities and not $Pod::Simple::XHTML::HAS_HTML_ENTITIES) {
656 skip("HTML::Entities not installed", 1);
658 local $Pod::Simple::XHTML::HAS_HTML_ENTITIES = $use_html_entities;
659 initialize($parser, $results);
660 $parser->parse_string_document(<<'EOPOD');
663 # this header is very important & dont you forget it
664 B<my $file = <FILEE<gt> || Blank!;>
665 my $text = "File is: " . <FILE>;
667 is($results, <<"EOHTML", "Verbatim text with markup and embedded formatting");
668 <pre><code> # this header is very important & dont you forget it
669 <b>my \$file = <FILE> || Blank!;</b>
670 my \$text = "File is: " . <FILE>;</code></pre>
674 # Specify characters to encode.
675 initialize($parser, $results);
676 $parser->html_encode_chars('><"&T');
677 $parser->parse_string_document(<<'EOPOD');
680 This is Anna's "Answer" to the <q>Question</q>.
685 my $T = $use_html_entities ? 84 : 'x54';
686 is($results, <<"EOHTML", 'HTML Entities should be only for specified characters');
687 <p>&#$T;his is Anna's "Answer" to the <q>Question</q>.</p>
694 ok $parser = Pod::Simple::XHTML->new, 'Construct a new parser';
696 $parser->output_string( \$results ); # Send the resulting output to a string
697 ok $parser->parse_string_document( "=head1 Poit!" ), 'Parse with headers';
698 like $results, qr{\Q<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />},
699 'Should have proper http-equiv meta tag';
701 ok $parser = Pod::Simple::XHTML->new, 'Construct a new parser again';
702 ok $parser->html_charset('UTF-8'), 'Set the html charset to UTF-8';
704 $parser->output_string( \$results ); # Send the resulting output to a string
705 ok $parser->parse_string_document( "=head1 Poit!" ), 'Parse with headers';
706 like $results, qr{\Q<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />},
707 'Should have http-equiv meta tag with UTF-8';
709 # Test the link generation methods.
710 is $parser->resolve_pod_page_link('Net::Ping', 'INSTALL'),
711 "$PERLDOC?Net::Ping#INSTALL",
712 'POD link with fragment';
713 is $parser->resolve_pod_page_link('perlpodspec'),
714 "$PERLDOC?perlpodspec", 'Simple POD link';
715 is $parser->resolve_pod_page_link(undef, 'SYNOPSIS'), '#SYNOPSIS',
716 'Simple fragment link';
717 is $parser->resolve_pod_page_link(undef, 'this that'), '#this-that',
718 'Fragment link with space';
719 is $parser->resolve_pod_page_link('perlpod', 'this that'),
720 "$PERLDOC?perlpod#this-that",
721 'POD link with fragment with space';
723 is $parser->resolve_man_page_link('crontab(5)', 'EXAMPLE CRON FILE'),
724 "${MANURL}5/crontab", 'Man link with fragment';
725 is $parser->resolve_man_page_link('crontab(5)'),
726 "${MANURL}5/crontab", 'Man link without fragment';
727 is $parser->resolve_man_page_link('crontab'),
728 "${MANURL}1/crontab", 'Man link without section';
730 # Make sure that batch_mode_page_object_init() works.
731 ok $parser->batch_mode_page_object_init(0, 0, 0, 0, 6),
732 'Call batch_mode_page_object_init()';
733 ok $parser->batch_mode, 'We should be in batch mode';
734 is $parser->batch_mode_current_level, 6,
735 'The level should have been set';
737 ######################################
740 $_[0] = Pod::Simple::XHTML->new ();
741 $_[0]->html_header("");
742 $_[0]->html_footer("");
743 $_[0]->output_string( \$results ); # Send the resulting output to a string