browser: minor html validation fixes
[sheet.git] / browser.plp
index 9adf10ef5a53437b81f9d282c524abea3fcb6acb..13e6b5e1ac7f30f6d3e97091a5d344436172db31 100644 (file)
@@ -39,7 +39,6 @@ given ($get{usage} // 'wm') {
 :>.
 </p>
 
-<div id="browser">
 <:
 my $caniuse = do 'browser-support.inc.pl' or die $! || $@;
 $_->{verrelease} = {
@@ -131,11 +130,12 @@ for my $browser (@browsers) {
        ) for @{ $versions{$browser} };
 }
 print '<td>' x 1;
-print "</thead>\n";
+say '</thead>';
+say '<tfoot>', $header, '</tfoot>';
 
 sub featurescore {
        # relative amount of support for given feature
-       state $statspts = { y=>10, 'y x'=>10, a=>5, 'a x'=>5, j=>2, 'p j'=>2, p=>1 };
+       state $statspts = { y=>10, 'y x'=>10, a=>5, 'a x'=>5, j=>2, 'p j'=>2, 'p p'=>2, p=>1 };
        my $rank = 0;
        if (my $row = shift) {
                if ($canihas) {
@@ -172,7 +172,7 @@ sub saytitlecol {
 
        for ($row->{categories}) {
                my $cell = $_ ? lc $_->[0] : '-';
-               print '<th>', $cell;
+               printf '<th title="%s">%s', join(' + ', @$_), $cell;
        }
 
        print '<td>', map {
@@ -181,15 +181,15 @@ sub saytitlecol {
                        sprintf("try { %s; return false } catch(err) { return true }",
                                "document.getElementById('$id').classList.toggle('target')",
                        ),
-                       $_,
+                       Entity($_),
                );
        } $row->{title};
        print '<div class=aside>';
        s/\.?$/./, print "<p>$_</p>" for map { ref $_ ? @$_ : $_ || () }
-               $row->{description}, $row->{notes};
-       printf 'Resources: %s.', join(', ',
-               map { qq(<a href="$_->{url}">$_->{title}</a>) } @$_
-       ) for grep { @$_ } $row->{links} // ();
+               Entity($row->{description}), formathtml($row->{notes});  # sic
+       printf 'Resources: %s.', join(', ', map {
+               sprintf '<a href="%s">%s</a>', EscapeHTML($_->{url}), $_->{title}
+       } @$_) for grep { @$_ } $row->{links} // ();
        print '</div>';
 }
 
@@ -242,6 +242,7 @@ sub sayusagecol {
        print '<td>', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100;
 }
 
+say '<tbody>';
 for my $id (sort {
            featurescore($caniuse->{data}->{$b}->{stats})
        <=> featurescore($caniuse->{data}->{$a}->{stats})
@@ -254,8 +255,18 @@ for my $id (sort {
        sayusagecol($id);
        say '</tr>';
 }
-print '<tfoot>', $header;
-print '</table>';
+say '</tbody>';
+say '</table>';
+
+sub formathtml {
+       my $ref = defined wantarray ? [@_] : \@_;
+       for (@$ref) {
+               s/& (?!\w)/&amp;/gx;
+               s/< \s/&lt;/gx;
+               s/\n\K\n/<br>/g;
+       }
+       return @$ref;
+}
 
 sub paddedver {
        # normalised version number comparable as string (cmp)
@@ -272,8 +283,7 @@ sub showversions {
        return join('‒', @span);
 }
 
-:></div>
-
+:>
 <hr>
 
 <div class="legend">
@@ -313,6 +323,6 @@ sub showversions {
        </div>
 </div>
 
-<script src="/searchlocal.js"></script>
-<script> prependsearch(document.getElementById('intro')) </script>
+<script type="text/javascript" src="/searchlocal.js"></script>
+<script type="text/javascript"> prependsearch(document.getElementById('intro')) </script>