common: replace html links by common function
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 23 Apr 2017 01:02:31 +0000 (03:02 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 25 May 2017 20:13:05 +0000 (22:13 +0200)
browser.plp
digits.plp
emoji.plp
sc.plp
source.plp
writing.plp

index 0d4d4e7c8ed17e7da6e8567f41db20164ac0af84..a78e0ecab8f37c178bfa300ecc6b9a58b7473879 100644 (file)
@@ -107,7 +107,7 @@ given ($get{usage} // 'wm') {
        };
        $usage = $_;
        my $ref = $canihas->{-title} || 'unknown';
-       $ref = sprintf '<a href="%s">%s</a>', $_, $ref
+       $ref = showlink($ref, $_)
                for $canihas->{-site} || $canihas->{-source} || ();
        $ref .= " $_" for $canihas->{-date} || ();
        print "\nwith $ref browser usage statistics";
@@ -339,10 +339,10 @@ sub saytitlecol {
                say '</p>';
        }
        printf 'Resources: %s.', join(', ', map {
-               sprintf '<a href="%s">%s</a>', EscapeHTML($_->{url}), EscapeHTML($_->{title})
+               showlink($_->{title}, $_->{url})
        } @$_) for grep { @$_ } $row->{links} // ();
        printf '<br>Parent feature: %s.', join(', ', map {
-               sprintf '<a href="%s">%s</a>', EscapeHTML("#$_"), $caniuse->{data}->{$_}->{title}
+               showlink($caniuse->{data}->{$_}->{title}, "#$_")
        } $_) for $row->{parent} || ();
        print '</div>';
 }
@@ -353,7 +353,7 @@ sub saystatuscol {
 
        for ($row->{status}) {
                my $cell = $_ // '-';
-               $cell = sprintf '<a href="%s">%s</a>', $_, $cell for $row->{spec} // ();
+               $cell = showlink($cell, $_) for $row->{spec} // ();
                printf '<td title="%s" class="l %s">%s',
                        $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $cell;
        }
index 2bef8f3cfe2ba7db7375700a19fe671877fe1895..2f95616e0df3a1806b9dd6d7f7d3116ffa48aeb6 100644 (file)
@@ -38,7 +38,7 @@ unless (exists $get{v}) {
 }
 
 my $scriptname = do 'writing-script.inc.pl';
-$_ = qq{<a href="/latin">$_</a>} for $scriptname->{latn} || ();
+$_ = showlink($_, "/latin") for $scriptname->{latn} || ();
 
 my $table = do "writing-digits.inc.pl";
 die "Table data not found: $_\n" for $@ || $! || ();
index ac3be58a841a93def0e8c03a1cc70e5ae2f5c79b..2a546b406efe045351345a9e558852ba7735861a 100644 (file)
--- a/emoji.plp
+++ b/emoji.plp
@@ -25,7 +25,7 @@ for my $system (qw'gmail msn yahoo') {
        my $meta = shift @info or die $@;
        ref $meta eq 'HASH' or die "invalid $system definitions";
        my $title = $meta->{name} // $system;
-       $title = qq{<a href="$_">$title</a>} for $meta->{source} || ();
+       $title = showlink($title, $_) for $meta->{source} || ();
 
        say sprintf '<div class="section"><h2>%s</h2>', $meta->{name} // $system;
        say '<table><tbody>';
diff --git a/sc.plp b/sc.plp
index b5d81ecd47684c90a7bdd64932ebd355e6e4fef9..3437f8f4aca51ce2da337d4f36f10682a47a93ab 100644 (file)
--- a/sc.plp
+++ b/sc.plp
@@ -49,8 +49,8 @@ my $patch = shift @{$units}
 
 say "<p>Unit properties as seen or measured in $scver{name}\n$patch.";
 say "Also see the $_ table." for join(', ',
-       ('<a href="/sc/2">StarCraft 2: HotS</a>')    x ($scver{major} < 2),
-       ('<a href="/sc">original SC: Brood War</a>') x ($scver{major} > 1),
+       (showlink('StarCraft 2: HotS', '/sc/2'))    x ($scver{major} < 2),
+       (showlink('original SC: Brood War', '/sc')) x ($scver{major} > 1),
 );
 say "</p>\n";
 
@@ -85,11 +85,9 @@ for my $unit (@{$units}) {
 
 sub coltoggle {
        my ($name, $id, $nolink) = @_;
-       return sprintf(
-               (defined $get{order} ? $get{order} eq $id : !$id) ? '%2$s ▼'
-                       : $nolink ? '%2$s' : '<a href="?%s">%s</a>',
-               $id && "order=$id", $name
-       );
+       return "$name ▼" if defined $get{order} ? $get{order} eq $id : !$id;
+       return $name if $nolink;
+       return showlink($name, '?'.($id && "order=$id"));
 }
 :><table class="units">
 <thead><tr>
index 56193fb95853a7a47a5ab98e18203fdfa9d82ffc..2b133712c6a0659b16da51b75ff0e564a6337df4 100644 (file)
@@ -47,7 +47,7 @@ if (not $source) {
        say '<ul>';
        for (glob '*.plp') {
                chomp;
-               say sprintf '<li><a href="/source/%s">%1$s</a></li>', EscapeHTML($_);
+               say '<li>', showlink($_, "/source/$_");
        }
        say "</ul>\n";
 }
@@ -90,16 +90,16 @@ else {
                        if (!$type || $type eq 'Constant'
                        and $contents =~ s{^(['"]?)(/?[a-z0-9_.]+\.(?:plp?|css|js))(?=\1$)}{}) {
                                # link other page sources, stylesheets, and javascript
-                               printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
+                               print $1 . showlink($2, "/source/$2");
                        }
                        if (!$type and $contents =~ s/^(\s*)([A-Z]\w+(?:::\w+)+)(?![^;\s])//) {
                                # link perl module names (Xx::Xx...)
-                               printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
+                               print $1 . showlink($2, "/source/$2");
                        }
                        if ($type && $type eq 'Comment'
                        and $contents =~ s{^(.*? by )(tools/\S+)}{}) {
                                # link generator scripts (by tools/...)
-                               printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
+                               print $1 . showlink($2, "/source/$2");
                        }
                        print Text::VimColor::_xml_escape($contents);
                        print "</$tag>" if $tag;
index a718c884bd6a1c8ffab718bc7107a32d3a793c73..ee2d825e153f83203acaf74c49d7861a24557c28 100644 (file)
@@ -36,7 +36,7 @@ unless (exists $get{v}) {
 }
 
 my $scriptname = do 'writing-script.inc.pl';
-$_ = qq{<a href="/latin">$_</a>} for $scriptname->{latn} || ();
+$_ = showlink($_, "/latin") for $scriptname->{latn} || ();
 
 for (
        [phnx => 'Phoenician'],