allow "class[foo|class[bar|text]]" class to be promoted to paragraph
authorTony Cook <tony@develop-help.com>
Fri, 16 May 2014 01:12:43 +0000 (11:12 +1000)
committerTony Cook <tony@develop-help.com>
Fri, 16 May 2014 01:12:43 +0000 (11:12 +1000)
this (still) doesn't require strict nesting of spans

site/cgi-bin/modules/DevHelp/Formatter.pm
t/010-modules/050-format.t

index 04b7767..9a4191e 100644 (file)
@@ -438,12 +438,10 @@ sub format {
       $part =~ s!(</(?:table|ol|ul|center|h[1-6])>)</p>!$1!g;
       # attempts to convert class[name|paragraph] into <p class="name">...
       # tried to use a negative lookahead but it wouldn't work
-      $part =~ s#(<p><span class="([^"<>]+)">(.*?)</span></p>)#
-        my ($one, $two, $three)= ($1, $2, $3); 
-        $3 =~ /<span/ ? $one : qq!<p class="$two">$three</p>!#ge;
-      $part =~ s#(<p><span style="([^"<>]+)">(.*?)</span></p>)#
-        my ($one, $two, $three)= ($1, $2, $3); 
-        $3 =~ /<span/ ? $one : qq!<p style="$two">$three</p>!#ge;
+      $part =~ s#<(p\b[^>]*)><span\ class="([^"<>]+)">(.*?)</span></p>
+               #<$1 class="$2">$3</p>#xg;
+      $part =~ s#<(p\b[^>]*)><span\ style="([^"<>]+)">(.*?)</span></p>
+               #<$1 style="$2">$3</p>#xg;
       if (my $p_class = $self->tag_class('p')) {
        $part =~ s!(<p(?: style="[^"<>]+")?)>!$1 class="$p_class">!g;
       }
index baf3c18..d20a0c5 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
-use Test::More tests => 151;
+use Test::More tests => 153;
 
 sub format_test($$$;$);
 sub noformat_test($$$;$);
@@ -633,6 +633,10 @@ OUT
 <p class="xxx">yy</p>
 <p class="xxx">zz</p>
 EOS
+  format_test "class[xxx|class[yyy|text]]",
+    '<p class="xxx"><span class="yyy">text</span></p>', "more class";
+  format_test "style[font-size: 18px|class[yyy|text]]",
+    '<p style="font-size: 18px"><span class="yyy">text</span></p>', "more class";
   format_test 'div[someclass|h1[|foo]barh2[|quux]]', <<EOS, 'divblock', 'out';
 <div class="someclass">
 <h1>foo</h1>