[MKDoc-commit] [MKDoc-Text-Structured] fix for <pre> indenting bug when first line is

bruno at mkdoc.demon.co.uk bruno at mkdoc.demon.co.uk
Wed Apr 20 17:43:32 BST 2005


Log Message:
-----------
[MKDoc-Text-Structured] fix for <pre> indenting bug when first line is more indented than second

Modified Files:
--------------
    MKDoc-Text-Structured:
        Changes
    MKDoc-Text-Structured/lib/MKDoc/Text/Structured:
        PRE.pm

Added Files:
-----------
    MKDoc-Text-Structured/t:
        018_pre_indented.t

-------------- next part --------------
Index: Changes
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/Changes,v
retrieving revision 1.21
retrieving revision 1.22
diff -LChanges -LChanges -u -r1.21 -r1.22
--- Changes
+++ Changes
@@ -1,6 +1,7 @@
 Revision history for MKDoc::Text::Structured
 
 0.83
+    - fix for <pre> indenting bug when first line is more indented than second
 
 0.82 Thu Mar 31 13:45:00 2005
     - fixed failure to change " to &quot; bug
Index: PRE.pm
===================================================================
RCS file: /var/spool/cvs/MKDoc-Text-Structured/lib/MKDoc/Text/Structured/PRE.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -Llib/MKDoc/Text/Structured/PRE.pm -Llib/MKDoc/Text/Structured/PRE.pm -u -r1.3 -r1.4
--- lib/MKDoc/Text/Structured/PRE.pm
+++ lib/MKDoc/Text/Structured/PRE.pm
@@ -25,8 +25,7 @@
 {
     my $self = shift;
     my $line = shift;
-    my $indent = $self->{indent};
-    return $line =~ /^$indent/;
+    return $line =~ /^\s/;
 }
 
 
@@ -35,6 +34,11 @@
     my $self   = shift;
     my @lines  = @{$self->{lines}};
     my $indent = $self->{indent};
+    for (@lines)
+    {
+        my ($_indent) = $_ =~ /^(\s+)/;
+        $indent = $_indent if (length ($_indent) lt length ($indent));
+    }
     my $text   = join "\n", map { s/^$indent//; $_ } @lines;
 
     # minimal encoding since we don't want all
--- /dev/null
+++ t/018_pre_indented.t
@@ -0,0 +1,57 @@
+use warnings;
+use strict;
+use Test::More 'no_plan';
+use lib ('lib', '../lib');
+use MKDoc::Text::Structured;
+
+my $text = <<EOF;
+     test
+   test
+EOF
+
+my $res = MKDoc::Text::Structured::process ($text);
+my @stuff = $res =~ /pre/g;
+ok (2 == scalar @stuff);
+
+
+$text = <<EOF;
+1. test
+     test
+
+   test
+EOF
+$res = MKDoc::Text::Structured::process ($text);
+ at stuff = $res =~ /pre/g;
+ok (2 == scalar @stuff);
+
+$text = <<EOF;
+1. test
+
+     test
+
+   test
+EOF
+$res = MKDoc::Text::Structured::process ($text);
+ at stuff = $res =~ /pre/g;
+ok (2 == scalar @stuff);
+
+$text = <<EOF;
+       b
+ a = -----
+       c
+
+>        b
+>  a = -----
+>        c
+
+1. some stuff
+
+     some pre stuff
+
+   2. some other stuff
+
+EOF
+$res = MKDoc::Text::Structured::process ($text);
+1;
+
+__END__


More information about the MKDoc-commit mailing list