Commits

Anonymous committed 47d218f

[XML-G-Fiction] Add support for the <b> and <i> tags.

Also fixed many tests due to the behaviour of $xpc->find().

  • Participants
  • Parent commits 96a97a1

Comments (0)

Files changed (5)

perl/modules/XML-Grammar-Fiction/MANIFEST

 t/data/xml/nested-s.xml
 t/data/xml/scenes-with-titles.xml
 t/data/xml/sections-and-paras.xml
+t/data/xml/sections-p-b-i.xml
 t/data/xml/two-nested-s.xml
 t/data/xml/with-brs.xml
 t/data/xml/with-comments.xml

perl/modules/XML-Grammar-Fiction/extradata/fiction-xml-to-html.xslt

         <xsl:element name="h{count(ancestor-or-self::fic:scene)}">
             <xsl:value-of select="title" />
         </xsl:element>
-        <xsl:apply-templates select="fic:scene|fic:p" />
+        <xsl:apply-templates select="fic:section|fic:p" />
     </div>
 </xsl:template>
 
     </p>
 </xsl:template>
 
+<xsl:template match="fic:b">
+    <b>
+        <xsl:apply-templates/>
+    </b>
+</xsl:template>
+
+<xsl:template match="fic:i">
+    <i>
+        <xsl:apply-templates/>
+    </i>
+</xsl:template>
+
 </xsl:stylesheet>

perl/modules/XML-Grammar-Fiction/extradata/fiction-xml.rng

     </define>
     <define name="para">
         <element name="fic:p">
+            <zeroOrMore>
+                <choice>
+                    <ref name="b" />
+                    <ref name="i" />
+                    <text />
+                </choice>
+            </zeroOrMore>
+        </element>
+    </define>
+    <define name="b">
+        <element name="fic:b">
+            <text />
+        </element>
+    </define>
+    <define name="i">
+        <element name="fic:i">
             <text />
         </element>
     </define>

perl/modules/XML-Grammar-Fiction/t/data/xml/sections-p-b-i.xml

+<?xml version='1.0' encoding='utf-8'?>
+<document xmlns="http://web-cpan.berlios.de/modules/XML-Grammar-Fortune/fiction-xml-0.2/">
+    <head>
+    </head>
+    <body xml:id="index">
+    <section xml:id="top">
+    <p>
+    David and Goliath were standing by each other.    
+    </p>
+    <p>
+    David said unto Goliath: "I will shoot you. I <b>swear</b> I will"
+    </p>
+    <section xml:id="goliath">
+    <p>
+    Goliath was not amused.
+    </p>
+    <p>
+    He said to David: "Oh, really. <i>David</i>, the red-headed!".
+    </p>
+    </section>
+    </section>
+</body>
+</document>

perl/modules/XML-Grammar-Fiction/t/to-xhtml.t

 use strict;
 use warnings;
 
-use Test::More tests => 3;
+use Test::More tests => 8;
 
 use File::Spec;
 
 
 my @tests = (qw(
         sections-and-paras
+        sections-p-b-i
     ));
 
 sub load_xml
     return $contents;
 }
 
-# TEST:$num_texts=1
+# TEST:$num_texts=2
 
 my $converter = XML::Grammar::Fiction::ToHTML->new({
         data_dir => File::Spec->catdir(File::Spec->curdir(), "extradata"),
     $xpc->registerNs('x', q{http://www.w3.org/1999/xhtml});
     # TEST*$num_texts
     is (
-        scalar(() = $xpc->find(q{//x:html}, $doc)),
+        scalar(() = $xpc->findnodes(q{//x:html}, $doc)),
         1,
         "Found one article with id index",
     );
 
     # TEST*$num_texts
     ok (
-        (scalar(() = $xpc->find(q{//x:div[@class='saying']}, $doc))
+        (scalar(() = $xpc->findnodes(q{//x:div}, $doc))
             >=
             1
         ),
         "Found role=description sections",
     );
 
-    # TEST*$num_texts
-    ok (
-        (scalar(() = $xpc->find(q{//x:div[@class='saying']/x:p/x:strong[@class='sayer']}, $doc))
-            >=
-            1
-        ),
-        "Found role=description sections",
-    );
 
+    # TEST:$num_with_styles=1;
+    if ($fn eq "sections-p-b-i")
+    {
+        my @elems;
+
+        @elems = $xpc->findnodes(q{//x:div/x:p/x:b}, $doc);
+        # TEST*$num_with_styles
+        is (
+            scalar(@elems),
+            1,
+            "Found bold tag",
+        );
+
+        # TEST*$num_with_styles
+        like ($elems[0]->toString(), qr{swear}, 
+            "Elem[0] is the right <b> tag."
+        );
+        
+        @elems = $xpc->findnodes(q{//x:div/x:p/x:i}, $doc);
+        # TEST*$num_with_styles
+        is (
+            scalar(@elems),
+            1,
+            "Found italic tag",
+        );
+
+        # TEST*$num_with_styles
+        like ($elems[0]->toString(), qr{David}, 
+            "<i>[0] contains the right contents."
+        );
+    }
 }
 
 1;