X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/01d61f72fed7ac041786ea69d1b080f45a4c49d1..ff4a38aff3e2d22ef34e33cd5df7a16d8ceeb196:/browser.plp diff --git a/browser.plp b/browser.plp index 0fc1627..de245b8 100644 --- a/browser.plp +++ b/browser.plp @@ -1,6 +1,4 @@ <(common.inc.plp)><: -use 5.010; -use utf8; use List::Util qw(sum max first); no if $] >= 5.018, warnings => 'experimental::smartmatch'; @@ -92,22 +90,24 @@ print <<'';

Alternate rendition of Fyrd's when can I use... page my ($canihas, $usage); -my $minusage = $get{threshold} // .7; +my $minusage = $get{threshold} // 1; given ($get{usage} // 'wm') { when (!$_) { # none } when (!m{ \A [a-z]\w+ (?:/\d[\d-]*\d)? \z }x) { - printf "

Invalid browser usage data request: %s", - 'identifier must be alphanumeric name or 0'; + Alert([ + 'Invalid browser usage data request', + 'Identifier must be alphanumeric name or 0.', + ]); } $canihas = do "data/browser/usage-$_.inc.pl" or do { - printf "

Browser usage data not found: %s", $@ || $!; + Alert('Browser usage data not found', $@ || $!); break; }; $usage = $_; my $ref = $canihas->{-title} || 'unknown'; - $ref = sprintf '%s', $_, $ref + $ref = showlink($ref, $_) for $canihas->{-site} || $canihas->{-source} || (); $ref .= " $_" for $canihas->{-date} || (); print "\nwith $ref browser usage statistics"; @@ -311,6 +311,15 @@ sub formatnotes { return @html; } +sub notestotitle { + my @notes = @_; + for (@notes) { + EscapeHTML($_); + s{ \[ ([^]]*) \] \( [^)]* \) }{$1}gx; # strip link urls + } + return @notes; +} + sub saytitlecol { my ($id) = @_; my $row = $caniuse->{data}->{$id}; @@ -339,10 +348,10 @@ sub saytitlecol { say '

'; } printf 'Resources: %s.', join(', ', map { - sprintf '%s', EscapeHTML($_->{url}), EscapeHTML($_->{title}) + showlink($_->{title}, $_->{url}) } @$_) for grep { @$_ } $row->{links} // (); printf '
Parent feature: %s.', join(', ', map { - sprintf '%s', EscapeHTML("#$_"), $caniuse->{data}->{$_}->{title} + showlink($caniuse->{data}->{$_}->{title}, "#$_") } $_) for $row->{parent} || (); print ''; } @@ -353,7 +362,7 @@ sub saystatuscol { for ($row->{status}) { my $cell = $_ // '-'; - $cell = sprintf '%s', $_, $cell for $row->{spec} // (); + $cell = showlink($cell, $_) for $row->{spec} // (); printf '%s', $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $cell; } @@ -396,7 +405,7 @@ sub saybrowsercols { map { split / /, $_ } $prev )); - $title .= "\n".EscapeHTML($_) for @notes; + $title .= "\n$_" for notestotitle(@notes); printf('%s', join(' ',