Browse Source

Markdown.pl: tidy up bare-bones wiki code

Move all the special cases to the top of the _ProcessWikiLink
function.

Add an exception to handle a fragment-only location.

All unhandled wiki style links now fall out the bottom of
the function.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
master
Kyle J. McKay 6 years ago
parent
commit
19766850b9
  1. 15
      Markdown.pl

15
Markdown.pl

@ -792,17 +792,16 @@ sub _EscapeSpecialChars {
sub _ProcessWikiLink { sub _ProcessWikiLink {
my ($link_text, $link_loc) = @_; my ($link_text, $link_loc) = @_;
if (defined($link_loc) && $link_loc =~ m{^(?:http|ftp)s?://\S+$}i) { if (defined($link_loc) &&
($link_loc =~ m{^#\S*$} || $link_loc =~ m{^(?:http|ftp)s?://\S+$}i)) {
# Just rewrite it to [...](...) form # Just rewrite it to [...](...) form
return "[".$link_text."](".$link_loc.")"; return "[".$link_text."](".$link_loc.")";
} }
if (defined($link_loc)) { my $sloc;
# We don't handle any other kind of "bar" links yet if (!defined($link_loc) &&
return undef; ($sloc = _strip($link_text)) =~ m{^(?:http|ftp)s?://\S+$}i) {
}
if ($link_text =~ m{^(?:http|ftp)s?://\S+$}i) {
# Just rewrite it to [...](...) form # Just rewrite it to [...](...) form
return "[".$link_text."](".$link_text.")"; return "[".$link_text."](".$sloc.")";
} }
# We don't handle any other wiki-style links yet # We don't handle any other wiki-style links yet
return undef; return undef;
@ -850,7 +849,7 @@ sub _DoAnchors {
if ($link_text =~ /^(.*)\|(.*)$/s) { if ($link_text =~ /^(.*)\|(.*)$/s) {
$link_text = $1; $link_text = $1;
$link_loc = $2; $link_loc = _strip($2);
} }
$result = _ProcessWikiLink($link_text, $link_loc); $result = _ProcessWikiLink($link_text, $link_loc);

Loading…
Cancel
Save