Subject: | links in generated markdown |
This is partially a wish and partially a bug.
1) Pod::Markdown does not parse internal links: L</foo>
2) Pod::Markdown does not parse links with text: L<text|foo>
3) It has some weird formatting for external links
I think the attached patch can fix both of the issues.
Note: The reason why i use <a name="..."> instead of <h1 id="..."> is
that it seems like github is stripping of the "id" part of the markup.
Subject: | links.patch |
--- Markdown.pm 2010-03-27 15:40:50.000000000 +0100
+++ Markdown.jhthorsen 2010-05-23 10:14:49.000000000 +0200
@@ -90,7 +90,7 @@
my $level = $1;
# the headers never are indented
- $parser->_save(sprintf '%s %s', '#' x $level, $paragraph);
+ $parser->_save(sprintf '<h%i><a name="pod_%s">%s</a></h%i>', $level, $paragraph, $paragraph, $level);
if ($level == 1) {
if ($paragraph =~ m{NAME}xmsi) {
$data->{searching} = 'title';
@@ -178,12 +178,18 @@
sub _resolv_link {
my ($cmd, $arg, $pod_seq) = @_;
- if ($arg =~ m{^http|ftp}xms) {
+ my $text = $arg =~ s"^(.+?)\|"" ? $1 : '';
- # direct link to a URL
- return sprintf '<%s>', $arg;
- } elsif ($arg =~ m{^(\w+(::\w+)*)$}) {
- return "[$1](http://search.cpan.org/perldoc?$1)";
+ if ($arg =~ m{^http|ftp}xms) { # direct link to a URL
+ $text ||= $arg;
+ return sprintf '[%s](%s)', $text, $arg;
+ } elsif ($arg =~ m{^/(.*)$}) {
+ $text ||= $1;
+ $text = $1;
+ return "[$text](\#pod_$1)";
+ } elsif ($arg =~ m{^(\w+(?:::\w+)*)$}) {
+ $text ||= $1;
+ return "[$text](http://search.cpan.org/perldoc?$1)";
} else {
return sprintf '%s<%s>', $cmd, $arg;
}