Browse Source

Markdown.pl: handle some limited [[wiki style links]]

The double bracket links are pervasive in source documents.

Recognize them and process them.  At this point only links
that reference an absolute URL are recognized and turned
into clickable links.

Everything else is passed on through unchanged.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
master
Kyle J. McKay 7 years ago
parent
commit
a3dd70b967
  1. 48
      Markdown.pl

48
Markdown.pl

@ -730,6 +730,25 @@ sub _EscapeSpecialChars {
}
sub _ProcessWikiLink {
my ($link_text, $link_loc) = @_;
if (defined($link_loc) && $link_loc =~ m{^(?:http|ftp)s?://\S+$}i) {
# Just rewrite it to [...](...) form
return "[".$link_text."](".$link_loc.")";
}
if (defined($link_loc)) {
# We don't handle any other kind of "bar" links yet
return undef;
}
if ($link_text =~ m{^(?:http|ftp)s?://\S+$}i) {
# Just rewrite it to [...](...) form
return "[".$link_text."](".$link_text.")";
}
# We don't handle any other wiki-style links yet
return undef;
}
sub _DoAnchors {
#
# Turn Markdown link shortcuts into XHTML <a> tags.
@ -737,7 +756,32 @@ sub _DoAnchors {
my $text = shift;
#
# First, handle reference-style links: [link text] [id]
# First, handle wiki-style links: [[wiki style link]]
#
$text =~ s{
( # wrap whole match in $1
\[\[
($g_nested_brackets) # link text and id = $2
\]\]
)
}{
my $result;
my $whole_match = $1;
my $link_text = $2;
my $link_loc = undef;
if ($link_text =~ /^(.*)\|(.*)$/s) {
$link_text = $1;
$link_loc = $2;
}
$result = _ProcessWikiLink($link_text, $link_loc);
defined($result) or $result = $whole_match;
$result;
}xsge;
#
# Next, handle reference-style links: [link text] [id]
#
$text =~ s{
( # wrap whole match in $1
@ -783,7 +827,7 @@ sub _DoAnchors {
}xsge;
#
# Next, inline-style links: [link text](url "optional title")
# Finally, inline-style links: [link text](url "optional title")
#
$text =~ s{
( # wrap whole match in $1

Loading…
Cancel
Save