Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Error/Limitation: with anchor-links into functions like [doc://function#anchor]

by LanX (Archbishop)
on Jun 24, 2019 at 13:35 UTC ( #11101810=monkdiscuss: print w/replies, xml ) Need Help??

Hi

I noticed a limitation in the [doc://...] parser for Perl documentation

According to What shortcuts can I use for linking to other information?

  • Link directly to a the doc of a function or variable: [doc://name] e.g. [doc://-X|file test ops]
  • Link directly to a specific document by name: [doc://name] e.g. [doc://perlipc]
  • Link to a section internal to a doc: [doc://name#anchor] e.g. [doc://perlfaq2#Perl-Books]

  • but while

    works is
    • [doc://split#split] -> split
    failing

    Looks like the automatic detection to add functions/ into the URL is failing because the #anchor part is taken into the check, and there is no "split#split" in the lookup hash.

    I tried to find the responsible code to be able to fix it but couldn't identify it yet.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

    Replies are listed 'Best First'.
    Re: Error/Limitation: with anchor-links into functions like [doc://function#anchor] (updated)
    by LanX (Archbishop) on Jun 24, 2019 at 13:58 UTC
      seems to be done in one of those two hashes holding callbacks to handle [doc://...] links
      update

      ironically it's the first one

      return( "http://perldoc.perl.org/", 'Perl documentation' ) unless $suf +fix; my $func= getVars(getNode('perl keyword list setting','setting')); if( $func->{$suffix} ) { "http://perldoc.perl.org/functions/$escsuffix.html" } elsif( $suffix =~ /^[\$\@%]/ ) { "http://perldoc.perl.org/perlvar.html#$escsuffix" } else { my ( $page, $anchor ) = split '#', $suffix, 2; my ( $uri, $title ) = ( "http://perldoc.perl.org/" ); $uri .= join '/', map $q->escape( $_ ), split /::/, $page; $uri .= '.html'; if( defined $anchor ) { $uri .= '#' . $q->escape( $anchor ); ( $title = $q->escapeHTML( $q->unescape( $anchor ) ) ) =~ y/-/ +/; } ( $uri, ( $title ) x!! defined $title ); }

      update

      a fix might look like (untested)

      return( "http://perldoc.perl.org/", 'Perl documentation' ) unless $suf +fix; if( $suffix =~ /^[\$\@%]/ ) { "http://perldoc.perl.org/perlvar.html#$escsuffix" } else { my ( $page, $anchor ) = split '#', $suffix, 2; my ( $uri, $title ) = ( "http://perldoc.perl.org/" ); my $func= getVars(getNode('perl keyword list setting','setting')); $uri .= "functions/$page" if( $func->{$page} ); # handle functions $uri .= join '/', map $q->escape( $_ ), split /::/, $page; $uri .= '.html'; if( defined $anchor ) { $uri .= '#' . $q->escape( $anchor ); ( $title = $q->escapeHTML( $q->unescape( $anchor ) ) ) =~ y/-/ +/; } ( $uri, ( $title ) x!! defined $title ); }

      update
      maybe better like this
      return( "http://perldoc.perl.org/", 'Perl documentation' ) unless $suf +fix; if( $suffix =~ /^[\$\@%]/ ) { "http://perldoc.perl.org/perlvar.html#$escsuffix" } else { my ( $page, $anchor ) = split '#', $suffix, 2; my ( $uri, $title ) = ( "http://perldoc.perl.org/" ); my $func= getVars(getNode('perl keyword list setting','setting')); if( $func->{$page} ) { # LanX: handle functions $uri .= "functions/$page"; # ??? do functions need to escaped? } else { # LanX: handle core modules and pragmas $uri .= join '/', map $q->escape( $_ ), split /::/, $page; } $uri .= '.html'; if( defined $anchor ) { $uri .= '#' . $q->escape( $anchor ); ( $title = $q->escapeHTML( $q->unescape( $anchor ) ) ) =~ y/-/ +/; } ( $uri, ( $title ) x!! defined $title ); }

      update
      regarding  $uri .= "functions/$page";  # ??? do functions need to escaped?

      none of the functions listed in perl keyword list setting needs to be escaped. even -X works fine

      comments???

      Is there a test suite?

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        ironically it's the first one

        FYI, in general (though I think there is an exception, maybe two), infrastructure nodes with names like "new ..." are not operational; they were testbeds for radical changes; once fully tested, their code was migrated into the regular code node.

        One way to tell (for... 90% sure) is to search code for the node name,and see if it's used. You'll find that new handlelinks settings isn't used, whereas handlelinks settings is referenced quite a bit.

        I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: monkdiscuss [id://11101810]
    Approved by Eily
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (4)
    As of 2019-09-20 19:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The room is dark, and your next move is ...












      Results (268 votes). Check out past polls.

      Notices?