add numerous html5 formatter tags
authorAdrian Oldham <adriann@visualthought.com.au>
Fri, 18 Oct 2013 11:15:31 +0000 (22:15 +1100)
committerTony Cook <tony@develop-help.com>
Sun, 3 Nov 2013 23:20:21 +0000 (10:20 +1100)
site/cgi-bin/modules/DevHelp/Formatter.pm
t/010-modules/050-format.t

index 10783aa113dcace247f312c351c0be19af89ec0e..fc006ddc707a32cf479e7be9e0cf48ec74b2d0f8 100644 (file)
@@ -3,7 +3,7 @@ use strict;
 use DevHelp::HTML;
 use Carp 'confess';
 
-our $VERSION = "1.004";
+our $VERSION = "1.005";
 
 use constant DEBUG => 0;
 
@@ -188,13 +188,13 @@ sub replace_char {
   $$rpart =~ s#bdo\[(?:\r?\n)?([^|\]\[]+)\|([^\]\[]+?)(?:\r?\n)?\]#
     $self->_fix_spanned(qq/<bdo dir="$1">/, "</bdo>", $2)#egi
     and return 1;
-  $$rpart =~ s#(strong|em|samp|code|var|sub|sup|kbd|q|b|i|tt|span|small|large)\[(?:\r?\n)?([^|\]\[]+)\|([^\]\[]+?)(?:\r?\n)?\]#
+  $$rpart =~ s#(strong|em|samp|code|var|sub|sup|kbd|q|b|i|tt|span|small|large|mark)\[(?:\r?\n)?([^|\]\[]+)\|([^\]\[]+?)(?:\r?\n)?\]#
     $self->_fix_spanned(qq/<$1 class="$2">/, "</$1>", $3)#egi
     and return 1;
-  $$rpart =~ s#(strong|em|samp|code|var|sub|sup|kbd|q|b|i|tt|span|small|large)\[(?:\r?\n)?\|([^\]\[]+?)(?:\r?\n)?\]#
+  $$rpart =~ s#(strong|em|samp|code|var|sub|sup|kbd|q|b|i|tt|span|small|large|mark)\[(?:\r?\n)?\|([^\]\[]+?)(?:\r?\n)?\]#
     $self->_fix_spanned("<$1>", "</$1>", $2)#egi
     and return 1;
-  $$rpart =~ s#(strong|em|samp|code|var|sub|sup|kbd|q|b|i|tt|span|small|large)\[(?:\r?\n)?([^\]\[]+?)(?:\r?\n)?\]#
+  $$rpart =~ s#(strong|em|samp|code|var|sub|sup|kbd|q|b|i|tt|span|small|large|mark)\[(?:\r?\n)?([^\]\[]+?)(?:\r?\n)?\]#
     $self->_fix_spanned("<$1>", "</$1>", $2)#egi
     and return 1;
   $$rpart =~ s#poplink\[([^|\]\[]+)\|([^\]\[]+)\]#
@@ -345,13 +345,13 @@ sub format {
        $part =~ s#style\[([^\]\[\|]+)\|([^\]\[]+)\]#
          $self->_fix_spanned(qq/<span style="$1">/, "</span>", $2)#eig
          and next TRY;
-       $part =~ s#(div|address|blockquote)\[\n*([^\[\]\|]+)\|\n*([^\[\]]+?)\n*\]#"\n\n" . $self->_tag_with_attrs($1, $2) . "$3</$1>\n\n"#eig
+       $part =~ s#(div|address|blockquote|article|section|header|footer|aside|nav|figure|figcaption)\[\n*([^\[\]\|]+)\|\n*([^\[\]]+?)\n*\]#"\n\n" . $self->_tag_with_attrs($1, $2) . "$3</$1>\n\n"#eig
          and next TRY;
        $part =~ s#comment\[[^\[\]]*\]##ig
          and next TRY;
-       $part =~ s#(div|address|blockquote)\[\n*\|([^\[\]]+?)\n*]#\n\n<$1>$2</$1>\n\n#ig
+       $part =~ s#(div|address|blockquote|article|section|header|footer|aside|nav|figure|figcaption)\[\n*\|([^\[\]]+?)\n*]#\n\n<$1>$2</$1>\n\n#ig
          and next TRY;
-       $part =~ s#(div|address|blockquote)\[\n*([^\[\]]+?)\n*]#\n\n<$1>$2</$1>\n\n#ig
+       $part =~ s#(div|address|blockquote|article|section|header|footer|aside|nav|figure|figcaption)\[\n*([^\[\]]+?)\n*]#\n\n<$1>$2</$1>\n\n#ig
          and next TRY;
        last;
       }
@@ -360,10 +360,26 @@ sub format {
       $part = "<p>$part</p>";
       1 while $part =~ s/<p>(<div(?: [^>]*)?>)/$1<p>/g;
       1 while $part =~ s!</div></p>!</p></div>!g;
-      1 while $part =~ s/<p>(<blockquote(?: [^>]*)?>)/$1<p>/g;
-      1 while $part =~ s!</blockquote></p>!</p></blockquote>!g;
       1 while $part =~ s/<p>(<address(?: [^>]*)?>)/$1<p>/g;
       1 while $part =~ s!</address></p>!</p></address>!g;
+      1 while $part =~ s/<p>(<blockquote(?: [^>]*)?>)/$1<p>/g;
+      1 while $part =~ s!</blockquote></p>!</p></blockquote>!g;
+      1 while $part =~ s/<p>(<article(?: [^>]*)?>)/$1<p>/g;
+      1 while $part =~ s!</article></p>!</p></article>!g;
+      1 while $part =~ s/<p>(<section(?: [^>]*)?>)/$1<p>/g;
+      1 while $part =~ s!</section></p>!</p></section>!g;
+      1 while $part =~ s/<p>(<header(?: [^>]*)?>)/$1<p>/g;
+      1 while $part =~ s!</header></p>!</p></header>!g;
+      1 while $part =~ s/<p>(<footer(?: [^>]*)?>)/$1<p>/g;
+      1 while $part =~ s!</footer></p>!</p></footer>!g;
+      1 while $part =~ s/<p>(<aside(?: [^>]*)?>)/$1<p>/g;
+      1 while $part =~ s!</aside></p>!</p></aside>!g;
+      1 while $part =~ s/<p>(<nav(?: [^>]*)?>)/$1<p>/g;
+      1 while $part =~ s!</nav></p>!</p></nav>!g;
+      1 while $part =~ s/<p>(<figure(?: [^>]*)?>)/$1<p>/g;
+      1 while $part =~ s!</figure></p>!</p></figure>!g;
+      1 while $part =~ s/<p>(<figcaption(?: [^>]*)?>)/$1<p>/g;
+      1 while $part =~ s!</figcaption></p>!</p></figcaption>!g;
       $part =~ s!<p>(<hr[^>]*>)</p>!$1!g;
       $part =~ s!<p>(<(?:table|ol|ul|center|h[1-6])[^>]*>)!$1!g;
       $part =~ s!(</(?:table|ol|ul|center|h[1-6])>)</p>!$1!g;
@@ -426,13 +442,17 @@ sub remove_format {
          and next TRY;
        $part =~ s#(?:acronym|abbr|dfn|cite)\[([^|\]\[]*)\]#$1#ig
          and next TRY;
-       $part =~ s#(?:strong|em|samp|code|var|sub|sup|kbd|q|address|blockquote|b|i|tt|span|small|large)\[([^|\]\[]+)\|([^\]\[]*)\]#$2#ig
+       $part =~ s#(?:strong|em|samp|code|var|sub|sup|kbd|q|b|i|tt|span|small|large|mark)\[([^|\]\[]+)\|([^\]\[]*)\]#$2#ig
+         and next TRY;
+       $part =~ s#(?:strong|em|samp|code|var|sub|sup|kbd|q|b|i|tt|span|small|large|mark)\[\|([^\]\[]*)\]#$1#ig
+         and next TRY;
+       $part =~ s#(?:strong|em|samp|code|var|sub|sup|kbd|q|b|i|tt|span|small|large|mark)\[([^\]\[]*)\]#$1#ig
          and next TRY;
-       $part =~ s#(?:strong|em|samp|code|var|sub|sup|kbd|q|address|blockquote|b|i|tt|span|small|large)\[\|([^\]\[]*)\]#$1#ig
+       $part =~ s#(?:div|address|blockquote|article|section|header|footer|aside|nav|figure|figcaption)\[([^\[\]\|]*)\|([^\[\]]*)\](?:\r?\n)?#$2#ig
          and next TRY;
-       $part =~ s#(?:strong|em|samp|code|var|sub|sup|kbd|q|address|blockquote|b|i|tt|span|small|large)\[([^\]\[]*)\]#$1#ig
+       $part =~ s#(?:div|address|blockquote|article|section|header|footer|aside|nav|figure|figcaption)\[\|([^\[\]]*)\](?:\r?\n)?#$1#ig
          and next TRY;
-       $part =~ s#div\[([^\[\]\|]+)\|([^\[\]]*)\](?:\r?\n)?#$2#ig
+       $part =~ s#(?:div|address|blockquote|article|section|header|footer|aside|nav|figure|figcaption)\[([^\[\]]*)\](?:\r?\n)?#$1#ig
          and next TRY;
        $part =~ s#comment\[([^\[\]]*)\](?:\r?\n)?##ig
          and next TRY;
index fa1c2f3fc5d180d22d144a1f44d7f2234d63331c..da8af2b6467b6c1ecff5ac5b9f228c5cce0b4498 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
-use Test::More tests => 107;
+use Test::More tests => 134;
 
 sub format_test($$$;$);
 sub noformat_test($$$;$);
@@ -21,6 +21,30 @@ SKIP: {
   format_test 'blockquote[hello]', '<blockquote><p>hello</p></blockquote>', 'blockquote';
   format_test 'blockquote[|hello]', '<blockquote><p>hello</p></blockquote>', 'blockquote with empty class';
   format_test 'blockquote[foo|hello]', '<blockquote class="foo"><p>hello</p></blockquote>', 'blockquote with class';
+  format_test 'article[hello]', '<article><p>hello</p></article>', 'article';
+  format_test 'article[|hello]', '<article><p>hello</p></article>', 'article with empty class';
+  format_test 'article[#id foo|hello]', '<article id="id" class="foo"><p>hello</p></article>', 'article with id and class';
+  format_test 'section[hello]', '<section><p>hello</p></section>', 'section';
+  format_test 'section[|hello]', '<section><p>hello</p></section>', 'section with empty class';
+  format_test 'section[#id foo|hello]', '<section id="id" class="foo"><p>hello</p></section>', 'section with id and class';
+  format_test 'header[hello]', '<header><p>hello</p></header>', 'header';
+  format_test 'header[|hello]', '<header><p>hello</p></header>', 'header with empty class';
+  format_test 'header[#id foo|hello]', '<header id="id" class="foo"><p>hello</p></header>', 'header with id and class';
+  format_test 'footer[hello]', '<footer><p>hello</p></footer>', 'footer';
+  format_test 'footer[|hello]', '<footer><p>hello</p></footer>', 'footer with empty class';
+  format_test 'footer[#id foo|hello]', '<footer id="id" class="foo"><p>hello</p></footer>', 'footer with id and class';
+  format_test 'aside[hello]', '<aside><p>hello</p></aside>', 'aside';
+  format_test 'aside[|hello]', '<aside><p>hello</p></aside>', 'aside with empty class';
+  format_test 'aside[#id foo|hello]', '<aside id="id" class="foo"><p>hello</p></aside>', 'aside with id and class';
+  format_test 'nav[hello]', '<nav><p>hello</p></nav>', 'nav';
+  format_test 'nav[|hello]', '<nav><p>hello</p></nav>', 'nav with empty class';
+  format_test 'nav[#id foo|hello]', '<nav id="id" class="foo"><p>hello</p></nav>', 'nav with id and class';
+  format_test 'figure[hello]', '<figure><p>hello</p></figure>', 'figure';
+  format_test 'figure[|hello]', '<figure><p>hello</p></figure>', 'figure with empty class';
+  format_test 'figure[#id foo|hello]', '<figure id="id" class="foo"><p>hello</p></figure>', 'figure with id and class';
+  format_test 'figcaption[hello]', '<figcaption><p>hello</p></figcaption>', 'figcaption';
+  format_test 'figcaption[|hello]', '<figcaption><p>hello</p></figcaption>', 'figcaption with empty class';
+  format_test 'figcaption[#id foo|hello]', '<figcaption id="id" class="foo"><p>hello</p></figcaption>', 'figcaption with id and class';
   format_test 'cite[hello]', '<p><cite>hello</cite></p>', 'cite';
   format_test 'cite[|hello]', '<p><cite>hello</cite></p>', 'cite with empty title';
   format_test 'cite[foo|hello]', '<p><cite title="foo">hello</cite></p>', 'cite with title';
@@ -31,6 +55,9 @@ SKIP: {
   format_test 'large[hello]', '<p><large>hello</large></p>', 'large';
   format_test 'large[|hello]', '<p><large>hello</large></p>', 'large empty class';
   format_test 'large[foo|hello]', '<p><large class="foo">hello</large></p>', 'large with class';
+  format_test 'mark[hello]', '<p><mark>hello</mark></p>', 'mark';
+  format_test 'mark[|hello]', '<p><mark>hello</mark></p>', 'mark empty class';
+  format_test 'mark[foo|hello]', '<p><mark class="foo">hello</mark></p>', 'mark with class';
   format_test <<IN, <<OUT, 'strong over paras', 'both';
 strong[foo|hello