Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

how to do perldoc links with special characters

by Lotus1 (Vicar)
on Apr 20, 2013 at 16:32 UTC ( [id://1029658]=monkdiscuss: print w/replies, xml ) Need Help??

When I use perlmonks shortcuts to the perldocs it goes to the page but not down to the anchor location on the page like the full link does. The apostrophe and the percent symbol are being replaced with things like '%27' and '%25'.

If I link with the full url like this it works. http://perldoc.perl.org/perlfaq5.html#How-can-I-use-Perl's--i-option-from-within-a-program%3f

However, this goes to the page but not the anchor. The text below shows what I have in the link at the word 'this'.

[doc://perlfaq5#How-can-I-use-Perl's--i-option-from-within-a-program%3f|this]

Update: Interesting; the full link doesn't go to the anchor with an actual question mark in it. http://perldoc.perl.org/perlfaq5.html#How-can-I-use-Perl's--i-option-from-within-a-program?

Replies are listed 'Best First'.
Re: how to do perldoc links with special characters
by LanX (Saint) on Apr 20, 2013 at 16:42 UTC
    This works cause I translated the '?' back.

    [doc://perlfaq5#How-can-I-use-Perl's--i-option-from-within-a-program?|this]

    Don't know if there is any ambiguity, otherwise I would pray to the gods humbly asking for a fix! =)

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      This works cause I translated the '?' back.

      Actually it doesn't. It still goes to the page but not the anchor.

      Update: I am using IE8 but I went ahead and tested your link on Chrome. So the '?' part is solved but the question of the apostrophe remains.

        Well works for me in FF!

        Which browser do you use?

        Maybe it's a FF DWIM feature. I'm too lazy to look up the specs now...

        Cheers Rolf

        ( addicted to the Perl Programming Language)

        That link works for me using firefox 20 on Linux. Maybe a browser/OS thing ?

Re: how to do perldoc links with special characters (perlmonks faq2doclink.pl)
by Anonymous Monk on Apr 20, 2013 at 17:02 UTC
     [doc://perlfaq5#How-can-I-use-Perl's--i-option-from-within-a-program?] How can I use Perl's i option from within a program?
    die fudge(q{http://perldoc.perl.org/perlfaq5.html#How-can-I-use-Perl%2 +7s--i-option-from-within-a-program%3f}); sub fudge { local $_ = shift ; return $_ if not m{\Qhttp://perldoc.perl.org/\E|\Qdoc://\E}si; # d +on't deal return $_ if m{\Qhttp://perldoc.perl.org/5.\E}si; # don't deal s/^\[//; s/\]$//; my $right = ""; s{\|(.*)}{} and $right.= $1; s{^\Qhref://\E}{}si; s{^\Qhttp://perldoc.perl.org/\E}{}si; s{^\Qdoc://\E}{}si; s{\Q.html\E}{}si; my( $left, $anchor ) = split '#', $_, 2; $left =~ s{/}{::}g; if( m{%[a-zA-Z0-9]{2}}si ){ $_ = unescape( $anchor ) ; s/ /-/; $anchor = $_; } if( $anchor ){ $anchor =~ s{\[}{%5b}g; $anchor =~ s{\]}{%5d}g; $left .= '#' . $anchor ; } if( length $right ){ $right =~ s{\[}{[}g; $right =~ s{\]}{]}g; return "[doc://$left|$right]" ; } return "[doc://$left]"; } sub Main { for my $file ( ( glob 'perlfaq*.html' ), (glob 'perlpod*html' ), ( +'perlintro.html', 'perlop.html') ){ ( my $name = $file ) =~ s/\.html//; #~ dd [ $file => $name ]; my $tree = HTML::TreeBuilder->new; $tree->parse_file( $file ); $tree->look_down( _tag => "a", name => qr/./, sub { my $question = $_[0]->attr('name'); return if $question =~ m{ ^\s* (?: AUTHOR.AND.COPYRIGHT | NAME | DESCRIPTION | CREDITS | THE.QUESTIONS | TABLE.OF.CONTENTS ) \s*$}xs; print fudge("[doc://$name#$question]"), "\n"; 0; }, ); } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-18 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found