browser: format markup in notes
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 6 Feb 2015 04:16:29 +0000 (05:16 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 6 Feb 2015 04:36:56 +0000 (05:36 +0100)
Code and links are encoded with Markdown syntax in recent caniuse comments.
Some simple regular expressions will suffice for this subset.

browser.plp

index 85ee802e046a8efcd99992694e3541a2f2ab186c..8b51522a34498f8bfa44ab9f1dfa6dea1e548265 100644 (file)
@@ -293,6 +293,18 @@ sub featurescore {
        return $rank;
 }
 
+sub formatnotes {
+       my @html = @_;
+       for (@html) {
+               s/\h* $//gmx;  # trailing whitespace
+               s/(?<= [^.\n]) $/./gmx;  # consistently end each line by a period
+               Entity($_);
+               s{  ` ([^`]*)  ` }{<code>$1</code>}gx;
+               s{ \[ ([^]]*) \] \( ([^)]*) \) }{<a href="$2">$1</a>}gx;
+       }
+       return @html;
+}
+
 sub saytitlecol {
        my ($id) = @_;
        my $row = $caniuse->{data}->{$id};
@@ -313,9 +325,8 @@ sub saytitlecol {
                );
        } $row->{title};
        print '<div class=aside>';
-       s/\.?$/./, print "<p>$_</p>" for map { ref $_ ? @$_ : $_ || () }
-               Entity($row->{description}),
-               map { s/\s*\n/\n<br>/g; $_ } $row->{notes};
+       print "<p>$_</p>"
+               for formatnotes($row->{description}, $row->{notes} || ());
        printf 'Resources: %s.', join(', ', map {
                sprintf '<a href="%s">%s</a>', EscapeHTML($_->{url}), $_->{title}
        } @$_) for grep { @$_ } $row->{links} // ();