ysth has asked for the wisdom of the Perl Monks concerning the following question:

pod2html seems to create correct links to =item sections if the section name is mentioned in a C<>, but not L<>. Is there a way to get it to do so? Using C won't work if I want the text to be different from the section name.

Sample pod and resulting html:

=head1 NAME foo - the foo page. =head1 DESCRIPTION The place for all things foo, L<"bar">, or L</"baz">. =over =item bar A link to C<baz>. And L<another|/baz>. =item baz Baz. =back
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w +3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>foo - the foo page.</title> <link rev="made" href="mailto:gp@familiehaase.de" /> </head> <body style="background-color: white"> <p><a name="__index__"></a></p> <!-- INDEX BEGIN --> <ul> <li><a href="#name">NAME</a></li> <li><a href="#description">DESCRIPTION</a></li> </ul> <!-- INDEX END --> <hr /> <p> </p> <h1><a name="name">NAME</a></h1> <p>foo - the foo page, place for all things.</p> <p> </p> <hr /> <h1><a name="description">DESCRIPTION</a></h1> <p>The place for all things foo, <a href="#bar">bar</a>, or <a href="# +baz">baz</a>.</p> <dl> <dt><strong><a name="item_bar">bar</a></strong><br /> </dt> <dd> A link to <a href="#item_baz"><code>baz</code></a>. And <a href="#baz +">another</a>. </dd> <p></p> <dt><strong><a name="item_baz">baz</a></strong><br /> </dt> <dd> Baz. </dd> <p></p></dl> </body> </html>

Replies are listed 'Best First'.
Re: creating links to an =item in the same page via pod2html
by themage (Friar) on Jul 01, 2005 at 13:55 UTC
    Hi, I thought that was weird, and was digging a bit in the Pod::HTML module, and I think there is a small bug in process_text1, that can be corrected with this small patch:
    --- Html.pm 2005-07-01 14:48:23.000000000 +0100 +++ Html.pm.new 2005-07-01 14:48:52.000000000 +0100 @@ -1549,7 +1549,7 @@ my( $page, $section, $ident ); # check for link patterns - if( $par =~ m{^([^/]+?)/(?!")(.*?)$} ){ # name/ident + if( $par =~ m{^([^/]+)?/(?!")(.*?)$} ){ # name/ident # we've got a name/ident (no quotes) ( $page, $ident ) = ( $1, $2 ); ### print STDERR "--> L<$par> to page $page, ident $ident +\n";
    This is based in the version I have installed:
    $VERSION = 1.0503;
      Thanks a lot for taking a look at this; if you get a change to dig more before I do, that would be wonderful.

      It looks to me like the patch leaves $page false and $ident = "bar", which is exactly what the following elseif should come up with.

        That's looks correct for me.

        They are there for two diferente ends:

        case 1: name/ident
        In this situation is expected L<page/itemname> where page can be empty (which is the case)

        case 2: name/"section name"
        In this case it is expected a sectionname, quoted. for some reason (because if there isn't a item with a given name Pod::Html will look for a section with the same name, the author (in his own comments) even though this should be a "section", we go for ident first. It works, as well as using a section name without quotes, that would in the previous case, and is treated as a ident, and then as a section if there is no ident with such name.

        case 3: something that have a space
        In this case Pod::Html assumes that we are looking for a section, as pages don't have whitespaces in names.

        case 4: everything else
        A link to anything that don't have spaces, nor a slash is a link to a page.

        I think that is missing a case, that could be managed before case 3 with:
        } elsif ($par=~m{"(.*)"}) { ($page,$section)=('',$1); #In this case, it looks to me # that the pod author forgot the initial / but is # trying to link to a section in corrent page # (quoted name).
        I'm also not seeing why the quotes in the second case are optional. Without garantees, my final patch would look like this:
        --- Html.pm 2005-07-01 14:48:23.000000000 +0100 +++ Html.pm.new 2005-07-01 23:07:35.000000000 +0100 @@ -1549,15 +1549,20 @@ my( $page, $section, $ident ); # check for link patterns - if( $par =~ m{^([^/]+?)/(?!")(.*?)$} ){ # name/ident + if( $par =~ m{^([^/]+)?/(?!")(.*?)$} ){ # name/ident # we've got a name/ident (no quotes) ( $page, $ident ) = ( $1, $2 ); ### print STDERR "--> L<$par> to page $page, ident $ident +\n"; - } elsif( $par =~ m{^(.*?)/"?(.*?)"?$} ){ # [name]/"section" - # even though this should be a "section", we go for ident + first - ( $page, $ident ) = ( $1, $2 ); + } elsif( $par =~ m{^(.*)?/"(.*?)"$} ){ # [name]/"section" + # we've got a name/"section" + ( $page, $section ) = ( $1, $2 ); ### print STDERR "--> L<$par> to page $page, section $sec +tion\n"; + + } elsif ( $par =~ m{^"(.*?)"$} ){ # "section" + # we've got a section without a pagename + ( $page, $section ) = ('',$1); + ### print STDERR "--> L<$par> to void page, section $sect +ion\n"; } elsif( $par =~ /\s/ ){ # this must be a section with missin +g quotes ( $page, $section ) = ( '', $par );
        But, maybe I'm missing something that Tom Christiansen found. I don't know.
Re: creating links to an =item in the same page via pod2html
by anonymized user 468275 (Curate) on Jul 01, 2005 at 08:43 UTC
    In the particular example above, 'bar' doesn't resolve, which might explain why no link is generated. Have you tried it for valid references too?

    One world, one people

      I misspoke; there are obviously links created, but not correct ones. pod2html knows to turn C<bar> into a link to #item_bar, but I want to get it to make a link to #item_bar using L<> as well. Obviously I could just put item_bar as the section to link to, but I'd be worried that a future change to pod2html would break that. I shouldn't have to know the implementation detail that it prepends =item sections with item_.