/usr/share/kio_perldoc/pod2html.pl is in kdesdk-kio-plugins 4:17.12.3-0ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 | #!/usr/bin/perl
#
# Code adapted from Pod::HtmlEasy for kio_perldoc. See CPAN for the real deal.
# Integrated and crap^H^H^H^H unnecessary dependencies removed by Michael Pyne
# <michael.pyne@kdemail.net>
#
# Copyright 2007, 2008 Michael Pyne.
# Original source is licensed to be distributed under the same terms as Perl
# itself. All changes by Michael Pyne retain this license.
#
# Based on Pod::HtmlEasy by M. P. Graciliano and Geoffrey Leach.
# http://search.cpan.org/~gleach/Pod-HtmlEasy/
#############################################################################
## Name: TieHandler.pm
## Purpose: Pod::HtmlEasy::TieHandler
## Author: Graciliano M. P.
## Modified by: Geoffrey Leach
## Created: 2/14/2007
## Copyright: (c) 2004 Graciliano M. P.
## Licence: This program is free software; you can redistribute it and/or
## modify it under the same terms as Perl itself
#############################################################################
# The function of this package is to provide a print function that is
# tied to a filehandle which is then passed as the output file to
# Pod::Parser. Note that only PRINT() and CLOSE() are defined.
# PRINT() accumulates output in an anon array, which is then referenced
# by the defining function.
package Pod::HtmlEasy::TieHandler;
use strict;
use warnings;
our $VERSION = 0.02;
sub TIEHANDLE {
my $class = shift;
my $scalar = shift;
return bless $scalar, $class;
}
sub PRINT {
my $this = shift;
push @{$this}, @_;
return 1;
}
sub FILENO { return 1; }
sub CLOSE { return 1; }
#######
# END #
#######
1;
#############################################################################
## Name: Parser.pm
## Purpose: Pod::HtmlEasy::Parser
## Author: Graciliano M. P.
## Modified by: Geoffrey Leach
## Created: 11/01/2004
## Updated: 2007-02-25
## Copyright: (c) 2004 Graciliano M. P.
## Licence: This program is free software; you can redistribute it and/or
## modify it under the same terms as Perl itself
#############################################################################
package Pod::HtmlEasy::Parser;
use base qw{ Pod::Parser };
use Carp;
use English qw{ -no_match_vars };
use feature "switch";
use strict;
use warnings;
no warnings 'experimental::smartmatch';
our $VERSION = 0.03;
our $EMPTY = q{};
our $NL = qq{\n};
our $NUL = qq{\0};
our $SPACE = q{ };
# Set to 1 for URIs like /functions/foo to fixup links in evt_on_L
our $fnPage = 0;
########
# VARS #
########
my $MAIL_RE = qr{
( # grab all of this
[\w-]+ # some word chars with '-' included foo
\0? # possible NUL escape
\@ # literal '@' @
[\w\\-]+ # another word bar
(?: # non-grabbing pattern
\. # literal '.' .
[\w\-\.]+# that word stuff stuff
\. # another literal '.' .
[\w\-]+ # another word and
| # or
\. # literal '.' .
[\w\-]+ # word nonsense
| # or empty?
) # end of non-grab
) # end of grab
}smx; # [6062]
# Treatment of embedded HTML-significant characters and embedded URIs.
# There are some characters (%html_entities below) which may in some
# circumstances be interpreted by a browser, and you probably don't want that
# Consequently, they are replaced by names defined by the W3C UNICODE spec,
# http://www.w3.org/TR/MathML2/bycodes.html, bracketed by '&' and ';'
# Thus, '>' becomes '<' This is handled by _encode_entities()
# There's a "gotchya" in this process. As we are generating HTML,
# the encoding needs to take place _before_ any HTML is generated.
# If the HTML appears garbled, and UNICODE entities appear where they
# shouldn't, this encoding has happened to late at some point.
# This is all further complicated by the fact that the POD formatting
# codes syntax uses some of the same characters, as in "L<...>", for example,
# and we can't expand those first, because some of them generate
# HTML. This is resolved by tagging the characters that we want
# to distinguish from HTML with ASCII NUL ('\0', $NUL). Thus, '$lt;' becomes
# '\0&' in _encode_entities(). Generated HTML is also handled
# this way by _nul_escape(). After all processing of the POD formatting
# codes are processed, this is reversed by _remove _nul_escapes().
# Then there's the issue of embedded URIs. URIs are also generated
# by the processing of L<...>, and can show up _inside L<...>, we
# delay processing of embedded URIs until after all of the POD
# formatting codes is complete. URIs that result from that processing
# are tagged (you guessed it!) with a NUL character, but not preceeding
# the generated URI, but after the first character. These NULs are removed
# by _remove _nul_escapes()
my %html_entities = (
q{&} => q{amp},
q{>} => q{gt},
q{<} => q{lt},
q{"} => q{quot},
);
my $HTML_ENTITIES_RE = '[' . join ('', keys %html_entities) . ']';
$HTML_ENTITIES_RE = qr{$HTML_ENTITIES_RE};
#################
# _NUL_ESCAPE #
#################
# Escape HTML-significant characters with ASCII NUL to differentiate them
# from the same characters that get converted to entity names
sub _nul_escape {
my $txt_ref = shift;
${$txt_ref} =~ s{($HTML_ENTITIES_RE)}{$NUL$1}gsm;
return;
}
#######################
# _REMOVE_NUL_ESCAPSE #
#######################
sub _remove_nul_escapes {
my $txt_ref = shift;
${$txt_ref} =~ s{$NUL}{}gsm;
return;
}
####################
# _ENCODE_ENTITIES #
####################
sub _encode_entities {
my ( $txt_ref ) = @_;
return unless $$txt_ref;
foreach my $chr ( keys %html_entities ) {
my $re = qr{(?<!$NUL)$chr};
my $replacement = '&' . $html_entities{$chr} . ';';
${$txt_ref} =~ s{$re}{$NUL$replacement}gsm;
}
return;
}
sub setFunctionPage {
my $this = shift;
our $fnPage = shift;
}
###########
# COMMAND #
###########
# Overrides command() provided by base class in Pod::Parser
sub command {
my ( $parser, $command, $paragraph, $line_num, $pod ) = @_;
if ( defined $parser->{POD_HTMLEASY}->{VERBATIM_BUFFER} ) {
_verbatim($parser);
} # [6062]
my $expansion = $parser->interpolate( $paragraph, $line_num );
$expansion =~ s{^\s*}{}gsm; # delete surrounding whitespace
$expansion =~ s{\s*$}{}gsm; # delete surrounding whitespace
# Encoding puts in a NUL; we're finished with the text, so remove them
_encode_entities( \$expansion );
_remove_nul_escapes( \$expansion );
# Create the index tag
# a_name has the text of the expansion _without_ anything between '<' and '>',
# which amounts to the HTML formatting codes, which are not processed by
# the name directive.
my $a_name = $expansion;
$a_name =~ s{<.*?>}{}gsm;
$a_name =~ /</g;
my $pos = pos($a_name);
my $start = $pos;
my $count = 0;
$count++ if defined $pos;
while(defined $pos and $count != 0)
{
my $match = $a_name =~ /\G[^<>]*([<>])/g;
last unless $match;
$pos = pos($a_name);
$count++ if $1 eq '<';
$count-- if $1 eq '>';
}
if (defined $pos and defined $start) {
$pos = $pos - $start + 1;
$start = $start - 1;
$a_name =~ s/^(.{$start}).{$pos}/$1/;
}
my $html;
given ($command) {
when ("head1") {
_add_tree_point( $parser, $expansion, 1 );
$html = $parser->{POD_HTMLEASY}
->{ON_HEAD1}( $parser->{POD_HTMLEASY}, $expansion, $a_name );
}
when ("head2") {
_add_tree_point( $parser, $expansion, 2 );
$html = $parser->{POD_HTMLEASY}
->{ON_HEAD2}( $parser->{POD_HTMLEASY}, $expansion, $a_name );
}
when ("head3") {
_add_tree_point( $parser, $expansion, 3 );
$html = $parser->{POD_HTMLEASY}
->{ON_HEAD3}( $parser->{POD_HTMLEASY}, $expansion, $a_name );
}
when ("head4") {
_add_tree_point( $parser, $expansion, 4 );
$html = $parser->{POD_HTMLEASY}
->{ON_HEAD4}( $parser->{POD_HTMLEASY}, $expansion, $a_name );
}
when ("begin") {
_add_tree_point( $parser, $expansion, 4 );
$html = $parser->{POD_HTMLEASY}
->{ON_BEGIN}( $parser->{POD_HTMLEASY}, $expansion, $a_name );
}
when ("end") {
$html = $parser->{POD_HTMLEASY}
->{ON_END}( $parser->{POD_HTMLEASY}, $expansion, $a_name );
}
when ("over") {
if ( $parser->{INDEX_ITEM} ) {
$parser->{INDEX_ITEM_LEVEL}++;
}
$html = $parser->{POD_HTMLEASY}
->{ON_OVER}( $parser->{POD_HTMLEASY}, $expansion );
}
when ("item") {
if ( $parser->{INDEX_ITEM} ) {
_add_tree_point( $parser, $expansion,
( 3 + ( $parser->{INDEX_ITEM_LEVEL} || 1 ) ) );
}
$html = $parser->{POD_HTMLEASY}
->{ON_ITEM}( $parser->{POD_HTMLEASY}, $expansion, $a_name );
}
when ("back") {
if ( $parser->{INDEX_ITEM} ) {
$parser->{INDEX_ITEM_LEVEL}--;
}
$html = $parser->{POD_HTMLEASY}
->{ON_BACK}( $parser->{POD_HTMLEASY}, $expansion );
}
when ("for") {
$html = $parser->{POD_HTMLEASY}
->{ON_FOR}( $parser->{POD_HTMLEASY}, $expansion, $a_name );
}
when ("include") {
my $file = $parser->{POD_HTMLEASY}
->{ON_INCLUDE}( $parser->{POD_HTMLEASY}, $expansion );
if ( -e $file
&& -r _ ) # _ is the last checked filehandle.
{
$parser->{POD_HTMLEASY}->parse_include($file);
}
}
default {
if ( defined $parser->{POD_HTMLEASY}->{qq{ON_\U$command\E}} ) {
$html = $parser->{POD_HTMLEASY}
->{qq{ON_\U$command\E}}( $parser->{POD_HTMLEASY},
$expansion );
}
elsif ( $command !~ /^(?:pod|cut)$/imx ) {
$html = qq{<pre>=$command $expansion</pre>};
}
else { $html = $EMPTY; }
}
};
if ( $html ne $EMPTY ) {
print { $parser->output_handle() } $html;
} # [6062]
return;
}
############
# VERBATIM #
############
# Overrides verbatim() provided by base class in Pod::Parser
sub verbatim {
my ( $parser, $paragraph, $line_num ) = @_;
if ( exists $parser->{POD_HTMLEASY}->{IN_BEGIN} ) { return; }
$parser->{POD_HTMLEASY}->{VERBATIM_BUFFER} .= $paragraph;
return;
}
sub _verbatim {
my ($parser) = @_;
if ( exists $parser->{POD_HTMLEASY}->{IN_BEGIN} ) { return; }
my $expansion = $parser->{POD_HTMLEASY}->{VERBATIM_BUFFER};
$parser->{POD_HTMLEASY}->{VERBATIM_BUFFER} = $EMPTY;
_encode_entities( \$expansion );
my $html = $parser->{POD_HTMLEASY}
->{ON_VERBATIM}( $parser->{POD_HTMLEASY}, $expansion );
# And remove any NUL escapes
_remove_nul_escapes( \$html );
if ( $html ne $EMPTY ) {
print { $parser->output_handle() } $html;
} # [6062]
return;
}
#############
# TEXTBLOCK #
#############
# Overrides textblock() provided by base class in Pod::Parser
sub textblock {
my ( $parser, $paragraph, $line_num ) = @_;
if ( exists $parser->{POD_HTMLEASY}->{IN_BEGIN} ) { return; }
if ( defined $parser->{POD_HTMLEASY}->{VERBATIM_BUFFER} ) {
_verbatim($parser);
} # [6062]
my $expansion = $parser->interpolate( $paragraph, $line_num );
$expansion =~ s{^\s+}{}gsmx;
$expansion =~ s{\s+$}{}gsmx;
# Encode HTML-specific characters before adding any HTML (eg <p>)
_encode_entities( \$expansion );
my $html = $parser->{POD_HTMLEASY}
->{ON_TEXTBLOCK}( $parser->{POD_HTMLEASY}, $expansion );
# And remove any NUL escapes
_remove_nul_escapes( \$html );
if ( $html ne $EMPTY ) { print { $parser->output_handle() } $html; }
return;
}
#####################
# INTERIOR_SEQUENCE #
#####################
# Overrides interior_sequence() provided by base class in Pod::Parser
sub interior_sequence {
my ( $parser, $seq_command, $seq_argument, $pod_seq ) = @_;
my $ret;
# If we're in the middle of a link then escaping now could break some of
# the link uncracking code.
_encode_entities(\$seq_argument) unless $seq_command eq 'L';
# Not sure how these get in here but HTML doesn't support / (which is
# simply forward slash
$seq_argument =~ s///\//g;
if ($pod_seq->nested() and $pod_seq->nested()->cmd_name() eq 'L'
and $seq_command ne 'E')
{
# Interpolating into a hyperlink, ignore formatting, unless we are
# processing an escape code
return $seq_argument;
}
given ($seq_command) {
when ("B") {
$ret = $parser->{POD_HTMLEASY}
->{ON_B}( $parser->{POD_HTMLEASY}, $seq_argument );
}
when ("C") {
$ret = $parser->{POD_HTMLEASY}
->{ON_C}( $parser->{POD_HTMLEASY}, $seq_argument );
}
when ("E") {
$ret = $parser->{POD_HTMLEASY}
->{ON_E}( $parser->{POD_HTMLEASY}, $seq_argument );
}
when ("F") {
$ret = $parser->{POD_HTMLEASY}
->{ON_F}( $parser->{POD_HTMLEASY}, $seq_argument );
}
when ("I") {
$ret = $parser->{POD_HTMLEASY}
->{ON_I}( $parser->{POD_HTMLEASY}, $seq_argument );
}
when ("L") {
my ( $text, $name, $section, $type ) = _parselink($seq_argument);
# Held off on escaping these earlier, take care of it now.
_encode_entities(\$text);
_encode_entities(\$section) if $section;
_encode_entities(\$name) if $name;
$ret = $parser->{POD_HTMLEASY}->{ON_L}(
$parser->{POD_HTMLEASY},
$seq_argument, $text, $name, $section, $type, $fnPage,
);
}
when ("S") {
$ret = $parser->{POD_HTMLEASY}
->{ON_S}( $parser->{POD_HTMLEASY}, $seq_argument );
}
when ("Z") {
$ret = $parser->{POD_HTMLEASY}
->{ON_Z}( $parser->{POD_HTMLEASY}, $seq_argument );
}
default {
if ( defined $parser->{POD_HTMLEASY}->{qq{ON_\U$seq_command\E}} )
{
$ret = $parser->{POD_HTMLEASY}
->{qq{ON_\U$seq_command\E}}( $parser->{POD_HTMLEASY},
$seq_argument );
}
else {
$ret = qq{$seq_command<$seq_argument>};
}
}
}
# Escape HTML-significant characters to prevent them from being escaped
# later.
_nul_escape( \$ret );
return $ret;
}
########################
# PREPROCESS_PARAGRAPH #
########################
# Overrides preprocess_paragraph() provided by base class in Pod::Parser
# NB: the text is _not altered.
sub preprocess_paragraph {
my $parser = shift;
my ( $text, $line_num ) = @_;
if ( $parser->{POD_HTMLEASY}{INFO_COUNT} == 3 ) {
return $text;
}
if ( not exists $parser->{POD_HTMLEASY}{PACKAGE} ) {
if ( $text =~ m{package}smx ) {
my ($pack) = $text =~ m{(\w+(?:::\w+)*)}smx;
if ( defined $pack ) {
$parser->{POD_HTMLEASY}{PACKAGE} = $pack;
$parser->{POD_HTMLEASY}{INFO_COUNT}++;
}
}
}
if ( not exists $parser->{POD_HTMLEASY}{VERSION} ) {
if ( $text =~ m{VERSION}smx ) {
my ($ver) = $text =~ m{(\d)(?:\.\d*)?}smx;
if ( defined $ver ) {
$parser->{POD_HTMLEASY}{VERSION} = $ver;
$parser->{POD_HTMLEASY}{INFO_COUNT}++;
}
}
}
# This situation is created by evt_on_head1()
if ( ( exists $parser->{POD_HTMLEASY}{TITLE} )
and ( not defined $parser->{POD_HTMLEASY}{TITLE} ) )
{
my @lines = split m{\n}smx, $text;
my $tmp_text = shift @lines;
if ( not defined $tmp_text ) { return $text; }
$tmp_text =~ s{^\s*}{}gsmx; # delete surrounding whitespace
$tmp_text =~ s{\s*$}{}gsmx; # delete surrounding whitespace
$parser->{POD_HTMLEASY}{TITLE} = $tmp_text;
$parser->{POD_HTMLEASY}{INFO_COUNT}++;
}
return $text;
}
##################
# _PARSE_SECTION #
##################
# Parse a link that is not a URL to get the name and/or section
# Algorithm may be found in perlpodspec. "About L<...> Codes"
sub _parse_section {
my $link = shift;
$link =~ s{^\s*}{}sm; # delete surrounding whitespace
$link =~ s{\s*$}{}sm; # delete surrounding whitespace
# L<"FooBar"> is a the way to specify a section without a name.
# However, L<Foo Bar> is possible, though deprecated. See below.
if ($link =~ m/^"/) {
$link =~ s{^"+\s*}{}sm; # strip the "s
$link =~ s{\s*"+$}{}sm;
return ( undef, $link );
}
# So now we have either a name by itself, or name/section
my ( $name, $section ) = split m[\s*/\s*]sm, $link, 2;
# Trim leading and trailing whitespace and quotes from section
if ($section) {
$section =~ s{"}{}gsm; # quotes
$section =~ s{^\s*}{}sm; # delete surrounding whitespace
$section =~ s{\s*$}{}sm; # delete surrounding whitespace
} # new leading/trailing
# Perlpodspec observes that and acceptable way to distinguish between L<name> and
# L<section> is that if the link contains any whitespace, then it is a section.
# The construct L<section> is deprecated.
if ( $name && $name =~ m{\s}sm && !defined $section ) {
$section = $name;
$name = undef;
}
return ( $name, $section );
}
###############
# _INFER_TEXT #
###############
# Infer the text content of a L<...> with no text| part (ie a text|-less link)
# By definition (?) either name or section is nonempty, Algorithm from perlpodspec
sub _infer_text {
my ( $name, $section ) = @_;
if ($name) {
return $section
? "\"$section\" in $name"
: $name;
}
return $section;
}
##############
# _PARSELINK #
##############
# Parse the content of L<...> and return
# The text label
# The name or URL
# The section (if relevant)
# The type of link discovered: url, man or pod
sub _parselink {
my $link = shift;
my $text;
# Squeeze out multiple spaces
$link =~ s{\s+}{$SPACE}gsm;
if ( $link =~ m{\|}smx ) {
# Link is in the form "L<Foo|Foo::Bar>"
( $text, $link ) = split m{\|}sm, $link, 2;
}
# Check for a generalized URL. The regex is defined in perlpodspec.
# Quoting perlpodspec: "Authors wanting to link to a particular (absolute) URL, must do so
# only with "L<scheme:...>" codes and must not attempt "L<Some Site Name|scheme:...>"
# Consequently, although $text might be nonempty, we ignore it.
if ($link =~ m{
\A # The beginning of the string
\w+ # followed by some alphanumerics, which would be the protocol (or scheme)
: # literal ":"
[^:\s] # one char that is neither a ":" or whitespace
\S* # maybe some non-whitespace
\z # the end of the string
}smx
)
{
return ( $link, $link, undef, q{url} );
}
# OK, we've eliminated URLs, so we must be dealing with something else
my ( $name, $section ) = _parse_section($link);
if ( not defined $text ) { $text = _infer_text( $name, $section ); }
# A link with parenthesized non-whitespace is assumed to be a manpage reference
# (per perlpodspec))
my $type =
( $name && $name =~ m{\(\S*\)}smx )
? q{man}
: q{pod};
return ( $text, $name, $section, $type );
}
###################
# _ADD_TREE_POINT #
###################
sub _add_tree_point {
my ( $parser, $name, $level ) = @_;
$level ||= 1;
if ( $level == 1 ) {
$parser->{POD_HTMLEASY}->{INDEX}{p}
= $parser->{POD_HTMLEASY}->{INDEX}{tree};
}
else {
if ( exists $parser->{POD_HTMLEASY}->{INDEX}{p} ) {
while ( $parser->{POD_HTMLEASY}
->{INDEX}{l}{ $parser->{POD_HTMLEASY}->{INDEX}{p} }
> ( $level - 1 ) )
{
last
if !$parser->{POD_HTMLEASY}
->{INDEX}{b}{ $parser->{POD_HTMLEASY}->{INDEX}{p} };
$parser->{POD_HTMLEASY}->{INDEX}{p} = $parser->{POD_HTMLEASY}
->{INDEX}{b}{ $parser->{POD_HTMLEASY}->{INDEX}{p} };
}
}
}
my $array = [];
$parser->{POD_HTMLEASY}->{INDEX}{l}{$array} = $level;
$parser->{POD_HTMLEASY}->{INDEX}{b}{$array}
= $parser->{POD_HTMLEASY}->{INDEX}{p};
push @{ $parser->{POD_HTMLEASY}->{INDEX}{p} }, $name, $array;
$parser->{POD_HTMLEASY}->{INDEX}{p} = $array;
return;
}
#############
# BEGIN_POD #
#############
# Overrides begin_pod() provided by base class in Pod::Parser
sub begin_pod {
my ($parser) = @_;
if ( $parser->{POD_HTMLEASY_INCLUDE} ) { return; }
delete $parser->{POD_HTMLEASY}->{INDEX};
$parser->{POD_HTMLEASY}->{INDEX} = { tree => [] };
return 1;
}
###########
# END_POD #
###########
# Overrides end_pod() provided by base class in Pod::Parser
sub end_pod {
my ($parser) = @_;
if ( $parser->{POD_HTMLEASY_INCLUDE} ) { return; }
if ( defined $parser->{POD_HTMLEASY}->{VERBATIM_BUFFER} ) {
_verbatim($parser);
}
my $tree = $parser->{POD_HTMLEASY}->{INDEX}{tree};
delete $parser->{POD_HTMLEASY}->{INDEX};
$parser->{POD_HTMLEASY}->{INDEX} = $tree;
return 1;
}
###########
# _ERRORS #
###########
sub _errors {
my ( $parser, $error ) = @_;
carp "$error";
$error =~ s{^\s*\**\s*errors?:?\s*}{}ismx;
$error =~ s{\s+$}{}smx;
my $html = $parser->{POD_HTMLEASY}
->{ON_ERROR}( $parser->{POD_HTMLEASY}, $error );
if ( $html ne $EMPTY ) {
print { $parser->output_handle() } $html, $NL;
}
return 1;
}
###########
# DESTROY #
###########
sub DESTROY { }
#######
# END #
#######
1;
#############################################################################
## Name: HtmlEasy.pm
## Purpose: Pod::HtmlEasy
## Author: Graciliano M. P.
## Modified by: Geoffrey Leach
## Created: 2004-01-11
## Updated: 2007-02-28
## Copyright: (c) 2004 Graciliano M. P.
## Licence: This program is free software; you can redistribute it and/or
## modify it under the same terms as Perl itself
#############################################################################
package Pod::HtmlEasy;
use 5.008;
use Carp;
use English qw{ -no_match_vars };
use strict;
use warnings;
our $VERSION = 0.09; # Also appears in "=head1 VERSION" in the POD below
our $EMPTY = q{};
our $NL = qq{\n};
our $NUL = qq{\0};
our $SPACE = q{ };
########
# VARS #
########
my %BODY_DEF = (
bgcolor => '#FFFFFF',
text => '#000000',
link => '#000000',
vlink => '#000066',
alink => '#FF0000',
);
# This keeps track of valid options
my %OPTS = (
basic_entities => 1,
body => 1,
common_entities => 1,
css => 1,
faq_page => 0,
function_page => 0,
index => 1,
index_item => 1,
no_css => 1,
no_generator => 1,
no_index => 1,
only_content => 1,
parserwarn => 1,
title => 1,
top => 1,
);
my $output_file;
#######
# CSS #
#######
my $CSS_DEF = q`
/*
** HTML elements
*/
body {
margin: 10px;
padding: 0;
text-align: center;
font-size: 0.8em;
font-family: "Bitstream Vera Sans", "Lucida Grande", "Trebuchet MS", sans-serif;
color: #535353;
background: #ffffff;
}
/*
** HTML Tags
*/
h1, h2, h3, h4
{
padding: 0;
text-align: left;
font-weight: bold;
color: #f7800a;
background: transparent;
}
h1 {
margin: 0 0 0.3em 0;
font-size: 1.7em;
}
h1.name + p {
font-size: larger;
font-style: oblique;
}
h2, h3, h4 {
margin: 1.3em 0 0 0.3em
}
h2 {
font-size: 1.5em;
}
h3 {
font-size: 1.4em;
}
h4 {
font-size: 1.3em;
}
h5 {
font-size: 1.2em;
}
a:link {
padding-bottom: 0;
text-decoration: none;
color: #0057ae;
}
a:visited {
padding-bottom: 0;
text-decoration: none;
color: #644A9B;
}
a[href]:hover {
text-decoration: underline;
}
hr {
margin: 0.3em 1em 0.3em 1em;
height: 1px;
border: #bcbcbc dashed;
border-width: 0 0 1px 0;
}
pre {
display: block;
margin: 0.3em;
padding: 0.3em;
font-size: 1em;
color: #000000;
text-align: left;
background: #f9f9f9;
border: #2f6fab dashed;
border-width: 1px;
overflow: auto;
line-height: 1.1em;
}
input, textarea, select {
margin: 0.2em;
padding: 0.1em;
color: #888888;
background: #ffffff;
border: 1px solid;
}
blockquote {
margin: 0.3em;
padding-left: 2.5em;
background: transparent;
}
del {
color: #800000;
text-decoration: line-through;
}
dt {
font-weight: bold;
font-size: 1.05em;
color: #0057ae;
}
dd {
margin-left: 1em;
}
p {
margin-top: 0.5em;
margin-bottom: 0.9em;
text-align: justify;
}
fieldset {
border: #cccccc 1px solid;
}
li {
text-align: left;
}
fieldset {
margin-bottom: 1em;
padding: .5em;
}
form {
margin: 0;
padding: 0;
}
hr {
height: 1px;
border: #888888 1px solid;
background: #888888;
margin: 0.5em 0 0.5em 0 ;
}
.toc a {
text-decoration: none;
}
.toc li {
list-style-type: none;
line-height: larger;
}
img {
border: 0;
}
table {
border-collapse: collapse;
font-size: 1em;
}
th {
text-align: left;
padding-right: 1em;
border: #cccccc solid;
border-width: 0 0 3px 0;
}
`;
###############
# DEFAULT_CSS #
###############
sub default_css {
return $CSS_DEF;
}
#######################
# _ORGANIZE_CALLBACKS #
#######################
sub _organize_callbacks {
my $this = shift;
$this->{ON_B} = \&evt_on_B;
$this->{ON_C} = \&evt_on_C;
$this->{ON_E} = \&evt_on_E;
$this->{ON_F} = \&evt_on_F;
$this->{ON_I} = \&evt_on_I;
$this->{ON_L} = \&evt_on_L;
$this->{ON_S} = \&evt_on_S;
$this->{ON_X} = \&evt_on_X; # [20078]
$this->{ON_Z} = \&evt_on_Z;
$this->{ON_HEAD1} = \&evt_on_head1;
$this->{ON_HEAD2} = \&evt_on_head2;
$this->{ON_HEAD3} = \&evt_on_head3;
$this->{ON_HEAD4} = \&evt_on_head4;
$this->{ON_VERBATIM} = \&evt_on_verbatim;
$this->{ON_TEXTBLOCK} = \&evt_on_textblock;
$this->{ON_OVER} = \&evt_on_over;
$this->{ON_ITEM} = \&evt_on_item;
$this->{ON_BACK} = \&evt_on_back;
$this->{ON_FOR} = \&evt_on_for;
$this->{ON_BEGIN} = \&evt_on_begin;
$this->{ON_END} = \&evt_on_end;
$this->{ON_INDEX_NODE_START} = \&evt_on_index_node_start;
$this->{ON_INDEX_NODE_END} = \&evt_on_index_node_end;
$this->{ON_INCLUDE} = \&evt_on_include;
$this->{ON_URI} = \&evt_on_uri;
$this->{ON_ERROR} = \&evt_on_error;
return;
}
#######
# NEW #
#######
sub new {
my $this = shift;
return $this if ref $this;
my $class = $this || __PACKAGE__;
$this = bless {}, $class;
my (%args) = @_;
_organize_callbacks($this);
# Backwards compatibility
if ( exists $args{on_verbatin} ) {
$this->{ON_VERBATIM} = $args{on_verbatin};
}
foreach my $key ( keys %args ) {
# Add in any ON_ callbacks
if ( $key =~ m{^on_(\w+)$}ismx ) {
my $cmd = uc $1;
$this->{qq{ON_$cmd}} = $args{$key};
}
elsif ( $key =~ m{^(?:=(\w+)|(\w)<>)$}smx ) {
my $cmd = uc $1 || $2;
$this->{$cmd} = $args{$key};
}
}
return $this;
}
############
# POD2HTML #
############
sub pod2html {
my $this = shift;
my $file = shift;
# Assume a non-option second arg is a file name
my $save = (exists $OPTS{ $_[0] } ? undef: shift) if defined $_[0];
my %args = @_;
# Check options for validity
foreach my $key ( keys %args ) {
if ( not exists $OPTS{$key} ) {
carp qq{option $key is not supported};
}
}
# No /x please
if ( defined $save && $save =~ m{$NL}sm ) {
# Is this a M$ way of saying "nothing there"?
$save = undef;
}
# This will fall through to Pod::Parser::new
# which is the base for Pod::HtmlEasy::Parser
# and Pod::HtmlEasy::Parser does not implement new()
my $parser = Pod::HtmlEasy::Parser->new();
$parser->errorsub( sub { Pod::HtmlEasy::Parser::errors( $parser, @_ ); }
);
# Pod::Parser wiii complain about multiple blank lines in the input
# which is moderately annoying
if ( exists $args{parserwarn} ) { $parser->parseopts( -warnings => 1 ); }
# This allows us to search for non-POD stuff is preprocess_paragraph
$parser->parseopts( -want_nonPODs => 1 );
if (exists $args{'function_page'}) { $parser->setFunctionPage($args{'function_page'}); }
# This puts a subsection in the $parser hash that will record data
# that is "local" to this code. Throughout, $parser will refer to
# Pod::Parser and $this to Pod::HtmlEasy
$parser->{POD_HTMLEASY} = $this;
if ( exists $args{index_item} ) { $parser->{INDEX_ITEM} = 1; }
if ( exists $args{basic_entities} ) {
carp q{"basic_entities" is deprecated.};
}
if ( exists $args{common_entities} ) {
carp q{"common_entities" is deprecated.};
}
# *HTML supplies a PRINT method that's used by the parser to do output
# It gets accumulated into HTML, which is tied to $output.
# You'll also see calls to print {$parser->output_handle()} ...
# which accomplishes the same thing. When all is said and done, the output
# of the parse winds up in $output declared below, and used in the construction
# of @html.
my $output = [];
local *HTML;
tie *HTML => 'Pod::HtmlEasy::TieHandler', $output;
my $html = \*HTML;
$this->{TIEDOUTPUT} = $html;
my $title = $args{title};
if ( ref $file eq q{GLOB} ) { # $file is an open filehandle
if ( not defined $title ) { $title = q{<DATA>}; }
}
else {
if ( !-e $file ) {
carp qq{No file $file};
return;
}
if ( not defined $title ) { $title = $file; }
}
# Build the header to the HTML file
my @html;
push @html,
qq{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">$NL};
push @html, qq{<html><head>$NL};
push @html,
qq{<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">$NL};
if ( not exists $args{no_generator} ) {
push @html,
qq{<meta name="GENERATOR" content="kio_perldoc Pod::HtmlEasy/$VERSION Pod::Parser/$Pod::Parser::VERSION Perl/$] [$^O]">$NL};
}
push @html, qq{<title>$title</title>$NL};
my $title_line_ref = \$html[-1];
push @html, _organize_css( \%args );
push @html, qq{</head>$NL};
if ( not exists $args{only_content} ) {
push @html, _organize_body( \%args );
}
delete $this->{UPARROW};
delete $this->{UPARROW_FILE};
push @html, qq{<div id="header"><div id="header_top"><div><div>$NL};
push @html, qq{<img src="help:/kdoctools5-common/part_of_the_kde_family_horizontal_190.png" alt="Part of the KDE family"> $title - KDE Perldoc Viewer</div></div></div></div>};
push @html, q{<div class="pod">};
if ( exists $args{top} ) {
push @html, qq{$NL<a name='_top'></a>$NL};
if ( -e $args{top} ) {
$this->{UPARROW_FILE} = $args{top};
}
else {
$this->{UPARROW} = $args{top};
}
}
if ($args{'faq_page'}) {
push @html, qq{$NL<p>The following FAQ results were found:</p>$NL};
}
# Avoid carry-over on multiple files
delete $this->{IN_BEGIN};
delete $this->{PACKAGE};
delete $this->{TITLE};
delete $this->{VERSION};
$this->{INFO_COUNT} = 0;
# A filehandle as both args is not documented, but is supported
# Everything that Pod::Parser prints winds up in $output
$parser->parse_from_file( $file, $html );
# If there's a head1 NAME, we've picked this up during processing
if ( defined $this->{TITLE} && length $this->{TITLE} > 0 ) {
${$title_line_ref} = qq{<title>$this->{TITLE}</title>$NL};
}
# Note conflict here: user can specify an index, and no_index; no_index wins
if ( not exists $args{index} ) { $args{index} = $this->build_index(); }
if ( exists $args{no_index} ) { $args{index} = $EMPTY; }
if ( $args{'faq_page'} && not @{$output} ) {
@{$output} = ("<b>None</b>");
}
my $kio_perldoc_version = $ENV{'KIO_PERLDOC_VERSION'} || "Unknown";
push @html, qq{$args{index}$NL};
push @html, @{$output}; # The pod converted to HTML
push @html, qq{</div><div id="footer"><div id="footer_text">Generated by kio_perldoc, version $kio_perldoc_version</div></div>};
push @html, qq{</body></html>$NL};
delete $this->{TIEDOUTPUT};
close $html or carp q{Could not close html};
untie $html or carp q{Could not untie html};
if ( defined $save ) {
open my $out, q{>}, $save or croak qq{Unable to open $save - $!};
print {$out} @html;
close $out;
}
return wantarray ? @html : join $EMPTY, @html;
}
#################
# PARSE_INCLUDE #
#################
sub parse_include {
my $this = shift;
my $file = shift;
my $parser = Pod::HtmlEasy::Parser->new();
$parser->errorsub( sub { Pod::HtmlEasy::Parser::errors( $parser, @_ ); }
);
$parser->{POD_HTMLEASY} = $this;
$parser->{POD_HTMLEASY_INCLUDE} = 1;
$parser->parse_from_file( $file, $this->{TIEDOUTPUT} );
return 1;
}
##############
# WALK_INDEX #
##############
sub walk_index {
my ( $this, $tree, $on_open, $on_close, $output ) = @_;
my $i = 0;
while ( $i < @{$tree} ) {
my $nk =
ref( ${$tree}[ $i + 1 ] ) eq q{ARRAY}
? @{ ${$tree}[ $i + 1 ] }
: undef;
$nk = $nk >= 1 ? 1 : undef;
my $a_name = ${$tree}[$i];
$a_name =~ s{<.*?>}{}gsmx;
#$a_name =~ s{&\w+;}{}gsmx;
#$a_name =~ s{\W+}{-}gsmx;
if ($on_open) {
my $ret = $on_open->( $this, ${$tree}[$i], $a_name, $nk );
if ( $output and defined $ret ) {
${$output} .= $ret;
} # [6062]
}
if ($nk) {
walk_index( $this, ${$tree}[ $i + 1 ],
$on_open, $on_close, $output );
}
if ($on_close) {
my $ret = $on_close->( $this, ${$tree}[$i], $a_name, $nk );
if ( $output and defined $ret ) {
${$output} .= $ret;
} # [6062]
}
$i += 2;
}
return;
}
###############
# BUILD_INDEX #
###############
sub build_index {
my $this = shift;
my $index = $EMPTY; # [6062]
$this->walk_index(
$this->{INDEX},
$this->{ON_INDEX_NODE_START},
$this->{ON_INDEX_NODE_END}, \$index
);
return qq{<div class="toc">$NL<ul>$NL$index</ul>$NL</div>$NL};
}
#################
# _ORGANIZE_BODY #
#################
sub _organize_body {
my $args_ref = shift;
my ( $body, %body );
$body = $EMPTY;
if ( ref $args_ref->{body} eq q{HASH} ) {
%body = %BODY_DEF;
my %body_attr = %{ $args_ref->{body} };
foreach my $key ( keys %body_attr ) {
$body{$key} = $body_attr{$key};
}
}
elsif ( !exists $args_ref->{body} ) { %body = %BODY_DEF; }
if (%body) {
foreach my $key ( sort keys %body ) {
if ( $body{$key} !~ m{\#}smx && defined $BODY_DEF{$key} ) {
$body{$key} = qq{#$body{$key}};
}
my $value =
$body{$key} !~ m{"}smx
? qq{"$body{$key}"}
: qq{'$body{$key}'};
$body .= qq{ $key=$value};
}
}
else { $body = $args_ref->{body}; }
return qq{<body $body>};
}
################
# ORGANIZE_CSS #
################
sub _organize_css {
my $perldoc_css = $ENV{'KIO_PERLDOC_CSSLOCATION'};
chomp $perldoc_css;
return <<"EOL";
<link rel="stylesheet" href="help:/kdoctools5-common/kde-default.css" type="text/css">
<link rel="stylesheet" href="file://$perldoc_css" type="text/css">
<style>
#header_top {
background-image: url("help:/kdoctools5-common/top.jpg");
}
#header_top div {
background-image: url("help:/kdoctools5-common/top-left.jpg");
}
#header_top div div {
background-image: url("help:/kdoctools5-common/top-right.jpg");
}
div.pod {
margin-left: 5em;
margin-right: 5em;
}
</style>
EOL
}
##################
# EVENT SUPPORT #
##################
sub do_title {
my $this = shift;
my ( $txt, $a_name ) = @_;
# This happens only on the _first_ head1 NAME
if ( ( not exists $this->{TITLE} ) and ( $txt =~ m{\ANAME}smx ) ) {
my ($title) = $txt =~ m{\ANAME\s+(.*)}smx;
if ( defined $title ) {
# Oh, goody
$title =~ s{^\s*}{}gsmx; # delete surrounding whitespace
$title =~ s{\s*$}{}gsmx; # delete surrounding whitespace
$this->{TITLE} = $title;
}
else {
# If we don't get anything off of NAME, it will be filled in by preprocess_paragraph()
$this->{TITLE} = undef;
}
}
return;
}
##################
# DEFAULT EVENTS #
##################
sub evt_on_head1 {
my $this = shift;
my ( $txt, $a_name ) = @_;
if ( not defined $txt ) { $txt = $EMPTY; }
do_title( $this, $txt, $a_name );
if ( exists $this->{UPARROW_FILE} ) {
return "<h1><a href='#_top'
title='click to go to top of document'
name='$a_name'>$txt<img src='$this->{UPARROW_FILE}'
alt=⇑></a></h1>$NL";
}
elsif ( exists $this->{UPARROW} ) {
return qq{<h1><a href='#_top'
title='click to go to top of document'
name='$a_name'>$txt&$this->{UPARROW};</a></h1>$NL};
}
my $style = '';
$style = 'class="name"' if $txt =~ m{\ANAME};
return qq{<a name='$a_name'></a><h1 $style>$txt</h1>$NL};
}
sub evt_on_head2 {
my $this = shift;
my ( $txt, $a_name ) = @_;
return qq{<a name='$a_name'></a><h2>$txt</h2>$NL$NL};
}
sub evt_on_head3 {
my $this = shift;
my ( $txt, $a_name ) = @_;
return qq{<a name='$a_name'></a><h3>$txt</h3>$NL$NL};
}
sub evt_on_head4 {
my $this = shift;
my ( $txt, $a_name ) = @_;
return qq{<a name='$a_name'></a><h4>$txt</h4>$NL$NL};
}
sub evt_on_begin {
my $this = shift;
my ( $txt, $a_name ) = @_;
$this->{IN_BEGIN} = 1;
return $EMPTY;
}
sub evt_on_end {
my $this = shift;
my ( $txt, $a_name ) = @_;
delete $this->{IN_BEGIN};
return $EMPTY;
}
sub evt_on_L {
my ($this, $L, $text, $page, $section, $type, $fnPage) = @_;
Pod::HtmlEasy::Parser::_encode_entities(\$page);
if($type eq 'pod') {
$page = '' unless defined $page;
if($fnPage and not $page) {
$page = "functions/";
$section = "" unless defined $section;
}
else {
$section = defined $section ? "#$section" : "";
}
# Keep later escaping functions from incorrectly messing this up.
$section =~ s/^(.)/$1$NUL/;
# The browser knows what to do for simple links in the same page,
# and knows how to do it better than we do.
return "<a href=\"$section\">$text</a>" unless $page;
$page =~ s/^(.)/$1$NUL/;
return "<a href=\"perldoc:$page$section\">$text</a>";
}
elsif($type eq 'man') {
return "<a href=\"man:/$page\">$text</a>";
}
elsif($type eq 'url') {
# Keep later escaping functions from incorrectly messing this up.
$page =~ s/^(.)/$1$NUL/;
$text =~ s/^(.)/$1$NUL/;
return "<a href=\"$page\" target=\"_blank\">$text</a>";
}
}
sub evt_on_B {
my $this = shift;
my $txt = shift;
return qq{<b>$txt</b>};
}
sub evt_on_I {
my $this = shift;
my $txt = shift;
return qq{<i>$txt</i>};
}
sub evt_on_C {
my $this = shift;
my $txt = shift;
# Who would put IMG tags in this?
return $EMPTY if $txt =~ m{<IMG}i;
return "<tt>$txt</tt>";
}
sub evt_on_E {
my $this = shift;
my $txt = shift;
# Hey guess what, not all &foo; entities are part of HTML! So don't go
# throwing them out without checking.
return "/" if $txt eq '/';
$txt =~ s{^&}{}smx;
$txt =~ s{;$}{}smx;
if ( $txt =~ m{^\d+$}smx ) { $txt = qq{#$txt}; }
return qq{$NUL&$txt;};
}
sub evt_on_F {
my $this = shift;
my $txt = shift;
# Some pod encoders put hyperlinks in F<>??
return qq{<a href="$txt">$txt</a>} if $txt =~ m'^http://';
return qq{<b><i>$txt</i></b>};
}
sub evt_on_S {
my $this = shift;
my $txt = shift;
$txt =~ s{$SPACE}{ }gs;
return $txt;
}
sub evt_on_X { return $EMPTY; } # [20078]
sub evt_on_Z { return $EMPTY; }
sub evt_on_verbatim {
my $this = shift;
my $txt = shift;
return if exists $this->{IN_BEGIN};
# Multiple empty lines are parsed as verbatim text by Pod::Parser
# And will show up as empty <pre> blocks, which is mucho messy
{
local $RS = $EMPTY;
chomp $txt;
}
if ( not length $txt ) { return $EMPTY; }
return qq{<pre>$txt</pre>$NL};
}
sub evt_on_textblock {
my $this = shift;
my $txt = shift;
return if exists $this->{IN_BEGIN};
return qq{<p>$txt</p>$NL};
}
sub evt_on_over {
my $this = shift;
my $level = shift;
return qq{<ul>$NL};
}
sub evt_on_item {
my $this = shift;
my ( $txt, $a_name ) = @_;
# POD has no list item tag, so most authors simulate it, breaking the HTML.
# So, strip out most bullet characters.
$txt =~ s/^\s*[\*oO\+\-\.](?!\S)//;
# If POD authors are going so far as to number the list, it's already too
# late to fix it by using <ol> tag, but we can change the CSS style.
my $style = '';
if ($txt =~ m/^\d+\.?/) {
$style = qq{ style="list-style-type:decimal;"};
$txt =~ s/^\d+\.?\s*//;
}
return qq{<li$style>$NL} if $txt =~ /^\s*$/;
return qq{<li$style><a name='$a_name'></a><b>$txt</b></li>$NL};
}
sub evt_on_back {
my $this = shift;
return qq{</ul>$NL};
}
sub evt_on_for { return $EMPTY; }
sub evt_on_error {
my $this = shift;
my $txt = shift;
return qq{<!-- POD_ERROR: $txt -->};
}
sub evt_on_include {
my $this = shift;
my $file = shift;
return $file;
}
sub evt_on_uri {
my $this = shift;
my $uri = shift;
my $target =
$uri !~ m{^(?:mailto|telnet|ssh|irc):}ismx
? q{ target='_blank'}
: $EMPTY; # [6062]
my $txt = $uri;
$txt =~ s{^mailto:}{}ismx;
return qq{<a href='$uri'$target>$txt</a>};
}
sub evt_on_index_node_start {
my $this = shift;
my ( $txt, $a_name, $has_children ) = @_;
my $ret = qq{<li><a href='#$a_name'>$txt</a>$NL};
if ($has_children) {
$ret .= qq{$NL<ul>$NL};
}
return $ret;
}
sub evt_on_index_node_end {
my $this = shift;
my ( $txt, $a_name, $has_children ) = @_;
my $ret = $has_children ? q{</ul>} : undef;
return $ret;
}
##############
# PM_VERSION #
##############
sub pm_version {
my $this = ref( $_[0] ) ? shift: undef;
if ( not defined $this ) {
carp q{pm_version must be referenced through Pod::HtmlEasy};
return;
}
return $this->{VERSION};
}
##############
# PM_PACKAGE #
##############
sub pm_package {
my $this = ref( $_[0] ) ? shift: undef;
if ( not defined $this ) {
carp q{pm_package must be referenced through Pod::HtmlEasy};
return;
}
return $this->{PACKAGE};
}
###########
# PM_NAME #
###########
sub pm_name {
my $this = ref( $_[0] ) ? shift: undef;
if ( not defined $this ) {
carp q{pm_name must be referenced through Pod::HtmlEasy};
return;
}
return $this->{TITLE};
}
###########################
# PM_PACKAGE_VERSION_NAME #
###########################
sub pm_package_version_name {
my $this = ref( $_[0] ) ? shift: undef;
if ( not defined $this ) {
carp
q{pm_package_version_name must be referenced through Pod::HtmlEasy};
return;
}
return ( $this->pm_package(), $this->pm_version(), $this->pm_name() );
}
#######
# END #
#######
1;
package main;
# Pass argv to perldoc, which we will redirect the output of perldoc to this
# process. This syntax only works in Perl 5.8 and higher, but that's OK, the
# rest of the code also requires Perl 5.8.
open my $perlDocInput, "-|", qw/perldoc -u -T/, @ARGV
or die "Unable to open pipe: $!";
my $usingFunctionPage = 0;
if(exists $ARGV[0] and $ARGV[0] eq '-f')
{
# Looking for a function, rewrite some URLs that refer to other functions
# on the same page.
$usingFunctionPage = 1;
}
my $podhtml = Pod::HtmlEasy->new();
print $podhtml->pod2html($perlDocInput,
'function_page'=>$usingFunctionPage,
'faq_page' => exists $ARGV[0] && $ARGV[0] eq '-q',
title=>"$ARGV[-1]"), "\n";
|