perl: optional line breaks in long code examples
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 31 Oct 2023 21:23:18 +0000 (22:23 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 4 Nov 2023 18:10:38 +0000 (19:10 +0100)
Fit mobile screen widths without indiscriminate code breaks.

perl.inc.pl
perl.plp

index 9f18c3421b6c34855e98a6a96594a1aa548787db..e26cbcd4603722a25fbc935e5469eee3ca367ec4 100644 (file)
@@ -1,6 +1,7 @@
 use utf8;
 use strict;
 
+my $wbr = "\N{ZERO WIDTH SPACE}";
 +{
        v5.004 => {
                release => '1997-05-15',
@@ -85,7 +86,7 @@ use strict;
                        ['Memoize' => 'remember function results, trading space for time', 'memoize "stat"'],
                        ['MIME::Base64' => 'base64 encoded strings as in email attachments'],
                        ['Test::More' => 'modern framework for unit testing', 'is $got, $expected'],
-                       ['Time::HiRes' => 'high resolution timers', '$μs = [gettimeofday]; sleep .1; $elapsed = tv_interval $μs'],
+                       ['Time::HiRes' => 'high resolution timers', '$μs = [gettimeofday]; sleep .1;'.$wbr.' $elapsed = tv_interval $μs'],
                ],
                release => '2002-07-18',
                distro => {
@@ -123,9 +124,9 @@ use strict;
                modules => [
                        [autodie => 'replace builtin functions to throw exceptions instead of returning failure', 'eval {open ...} or $@->matches("open") || die'],
                        # overloading
-                       ['IO::Compress::Zip' => 'various file compression standards', 'zip IO::Uncompress::Gunzip->new("test.gz") => "recompressed.zip"'],
+                       ['IO::Compress::Zip' => 'various file compression standards', 'zip IO::Uncompress::Gunzip->new("test.gz")'.$wbr.' => "recompressed.zip"'],
                        ['Time::Piece' => 'timestamps as objects', 'localtime->year > 1900'],
-                       ['File::Fetch' => 'generic data retrieval/download', 'File::Fetch->new(uri => "http://localhost/")->fetch(to => \$slurp)'],
+                       ['File::Fetch' => 'generic data retrieval/download', 'File::Fetch->new(uri => "http://localhost/")'.$wbr.'->fetch(to => \$slurp)'],
                ],
                release => '2007-12-18',
                distro => {
index 716a1ebfcc51a40ce8554f5da32d028bd4449a9e..89b906e82b503298e009f058e67984758d9313ed 100644 (file)
--- a/perl.plp
+++ b/perl.plp
@@ -132,7 +132,9 @@ sub featattrs ($attr) {
        $title = $title ? sprintf ' <em class="ex">(%s)</em>', $title : '';
 
        if (my $eg = $attr->{eg}) {
-               my $pre = sprintf ' <small>{<code>%s</code>}</small>', Entity($eg);
+               my $pre = Entity($eg);
+               $pre =~ s<\N{ZERO WIDTH SPACE}>{</code><wbr/><code>}g;
+               $pre = " <small>{<code>$pre</code>}</small>";
                $title = $pre . $title;
        }
        return $title;