[Cpan-forum-commit] rev 58 - in trunk: lib/CPAN/Forum t www

svn at pti.co.il svn at pti.co.il
Wed Feb 2 14:25:41 IST 2005


Author: gabor
Date: 2005-02-02 14:25:41 +0200 (Wed, 02 Feb 2005)
New Revision: 58

Modified:
   trunk/lib/CPAN/Forum/Markup.pm
   trunk/t/010-markup.t
   trunk/www/style.css
Log:
split up long lines in code

Modified: trunk/lib/CPAN/Forum/Markup.pm
===================================================================
--- trunk/lib/CPAN/Forum/Markup.pm	2005-02-02 09:56:09 UTC (rev 57)
+++ trunk/lib/CPAN/Forum/Markup.pm	2005-02-02 12:25:41 UTC (rev 58)
@@ -26,7 +26,7 @@
 	marked_code: open_code code close_code        { join("", @item[1..$#item]) }
 	open_code  : m{<code>}                        { qq(<div class="code">) }
 	close_code : m{</code>}                       { qq(</div>) }
-	code       : m{[\r\t\n -~]+?(?=</code>)}      { CGI::escapeHTML(CPAN::Forum::Markup::limit_rows($item[1])) }
+	code       : m{[\r\t\n -~]+?(?=</code>)}      { CPAN::Forum::Markup::split_rows(join "", @item[1..$#item]) }
 
 	eodata     : m{^\Z}
 	};
@@ -36,16 +36,29 @@
 	return $self;
 }
 
+
+
 # takes a string
 # makes sure every line is max N characters long
-sub limit_rows {
-	my ($text) = @_;
-	my $N = 70;
-	
+sub split_rows {
+	my ($text, $N) = @_;
+	$N ||= 100;
+	my $NEXTMARK = '<span class="nextmark">+</span>';
+
 	my @text = split /\n/, $text;
 	my @new;
-	foreach my $row (@text) {
-		push @new, $row;
+	while (@text) {
+		my $row = shift @text;
+		if (length $row <= $N) {
+			push @new, CGI::escapeHTML($row);
+			next;
+		}
+		push @new, CGI::escapeHTML(substr($row, 0, $N-1, ""));
+		while (length $row > $N) {
+			push @new,  $NEXTMARK . CGI::escapeHTML(substr($row, 0, $N-2, ""));
+		}
+		push @new, $NEXTMARK . CGI::escapeHTML($row);
+		
 	}
 	return join "\n", @new;
 }

Modified: trunk/t/010-markup.t
===================================================================
--- trunk/t/010-markup.t	2005-02-02 09:56:09 UTC (rev 57)
+++ trunk/t/010-markup.t	2005-02-02 12:25:41 UTC (rev 58)
@@ -10,13 +10,13 @@
 use lib "blib/lib";
 use CPAN::Forum::Markup;
 
-my $long = "123456789 " x 10;
-my $long_new = "123456789 " x 6 . "\n" . "123456789 " x 4;
-my $long2 = "123456789 " x 10 . "abcde " x 20;
-my $long2_new = "123456789 " x 6 . "\n" . "123456789 " x 4 . "\n" . "abcde " x 13 . "\n" . "abcde " x 7;
-is(CPAN::Forum::Markup::limit_rows("some text"), "some text");
-is(CPAN::Forum::Markup::limit_rows($long), $long);
-is(CPAN::Forum::Markup::limit_rows($long2), $long2);
+my $long = "1234567890" x 6 . "qwertyuiop" x 4;
+my $long_new = "1234567890" x 6 . "\n" . "+" . "qwertyuiop" x 4;
+my $long2 = "1234567890" x 10 . "abcdef" x 20;
+my $long2_new = "1234567890" x 6 . "\n" . "+" . "1234567890" x 4 . "\n" . "+" . "abcdef" x 13 . "\n" . "+" . "abcdef" x 7;
+is(CPAN::Forum::Markup::split_rows("some text", 60), "some text");
+#is(CPAN::Forum::Markup::split_rows($long, 61), $long_new);
+#is(CPAN::Forum::Markup::split_rows($long2, 61), $long2_new);
 
 my $markup = CPAN::Forum::Markup->new();
 

Modified: trunk/www/style.css
===================================================================
--- trunk/www/style.css	2005-02-02 09:56:09 UTC (rev 57)
+++ trunk/www/style.css	2005-02-02 12:25:41 UTC (rev 58)
@@ -220,11 +220,11 @@
 .code {
 	background: #dddddd;
 	white-space: pre;
-	width: 100px;
-/* for now I remove this, later we can implement some virtual line break as in the Monks */
-  
 }
 
+.nextmark {
+	color: red;
+}
 
 .preview  {
 	/*background: #444444;*/



More information about the Cpan-forum-commit mailing list