Commits

Anonymous committed 9163241

Add the <span> tag.

  • Participants
  • Parent commits 7c01d8a

Comments (0)

Files changed (9)

File perl/modules/XML-Grammar-Fiction/Changes

     would be translated to <body xml:lang=".."> attribute in Fiction-XML (and
     eventually to DocBook 5/XML).
     * Add support for the lang="..." attribute in <section>/<s>.
+    * Add the <span> tag for Fiction-Text (already exists in Fiction-XML).
+        - supports two attributes - lang -> xml:lang and id -> xml:id.
 
 0.6.0      Mon May 23 22:59:05 IDT 2011
     * Add the version="5.0" attribute to the top-level tag of the

File perl/modules/XML-Grammar-Fiction/MANIFEST

 t/fiction/data/docbook/with-blockquote.docbook.xml
 t/fiction/data/docbook/with-internal-description.docbook.xml
 t/fiction/data/docbook/with-programlisting.docbook.xml
+t/fiction/data/docbook/with-span.docbook.xml
 t/fiction/data/docbook/with-ul-ol-li.docbook.xml
 t/fiction/data/docbook/with-xml-lang-attribute.docbook.xml
 t/fiction/data/docbook/with-xml-lang-attr-in-section.docbook.xml
 t/fiction/data/proto-text/with-blockquote.txt
 t/fiction/data/proto-text/with-internal-description.txt
 t/fiction/data/proto-text/with-programlisting.txt
+t/fiction/data/proto-text/with-span.txt
 t/fiction/data/proto-text/with-ul-ol-li.txt
 t/fiction/data/proto-text/with-xml-lang-attribute.txt
 t/fiction/data/proto-text/with-xml-lang-attr-in-section.txt
 t/fiction/data/xml/sections-p-b-i.xml
 t/fiction/data/xml/with-blockquote.xml
 t/fiction/data/xml/with-programlisting.xml
+t/fiction/data/xml/with-span.xml
 t/fiction/data/xml/with-ul-ol-li.xml
 t/fiction/data/xml/with-xml-lang-attribute.xml
 t/fiction/data/xml/with-xml-lang-attr-in-section.xml

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

             </link>
         </xsl:when>
         <xsl:otherwise>
-            <xsl:apply-templates/>
+            <phrase>
+                <xsl:if test="@xml:lang">
+                    <xsl:attribute name="xml:lang">
+                        <xsl:value-of select="@xml:lang" />
+                    </xsl:attribute>
+                </xsl:if>
+                <xsl:if test="@xml:id">
+                    <xsl:attribute name="xml:id">
+                        <xsl:value-of select="@xml:id" />
+                    </xsl:attribute>
+                </xsl:if>
+                <xsl:apply-templates/>
+            </phrase>
         </xsl:otherwise>
     </xsl:choose>
 </xsl:template>

File perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/Fiction/FromProto.pm

 
     my $id = $elem->lookup_attr("id");
     my $lang = $elem->lookup_attr("lang");
+    my $href = $elem->lookup_attr("href");
+
+    my @attr;
 
     if (!defined($id))
     {
-        Carp::confess($args->{missing_id_msg} || "Unspecified id!");
+        if (! $args->{optional_id} )
+        {
+            Carp::confess($args->{missing_id_msg} || "Unspecified id!");
+        }
     }
-
-    my @lang_attr;
+    else
+    {
+        push @attr, ([$xml_ns, "id"] => $id);
+    }
 
     if (defined($lang))
     {
-        push @lang_attr, ([$xml_ns, 'lang'] => $lang);
+        push @attr, ([$xml_ns, 'lang'] => $lang);
+    }
+
+    if (defined($href))
+    {
+        push @attr, ([$xml_ns, 'href'] => $href);
     }
 
     return $self->_output_tag_with_childs(
         {
-            'start' => [$tag_name, [$xml_ns, "id"] => $id, @lang_attr,],
+            'start' => [$tag_name, @attr,],
             elem => $elem,
         }
     );
     return;
 }
 
+sub _handle_elem_of_name_span
+{
+    my ($self, $elem) = @_;
+
+    $self->_output_tag_with_childs_and_common_attributes(
+        $elem,
+        'span',
+        {
+            optional_id => 1,
+            missing_id_msg => "Unspecified id for span!",
+        },
+    );
+
+    return;
+}
+
 sub _handle_elem_of_name_ul
 {
     my ($self, $elem) = @_;

File perl/modules/XML-Grammar-Fiction/t/fiction/data/docbook/with-span.docbook.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<article xmlns="http://docbook.org/ns/docbook" xmlns:fic="http://web-cpan.berlios.de/modules/XML-Grammar-Fortune/fiction-xml-0.2/" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="index" xml:lang="" version="5.0">
+  <info>
+    <title>David vs. Goliath - Part I</title>
+  </info>
+  <section xml:id="top">
+    <info>
+      <title>The Top Section</title>
+    </info>
+    <para>
+        King <phrase xml:lang="he-IL">דוד</phrase> and <phrase xml:id="foobar">Foobar Anchor</phrase> and <phrase xml:id="peter" xml:lang="fr-FR">Pierre</phrase> and Goliath were standing by each other.    
+    </para>
+    <para>
+    David said unto Goliath: "I will shoot you. I <emphasis role="bold">swear</emphasis> I will"
+    </para>
+    <section xml:id="goliath">
+      <info>
+        <title>Goliath's Response</title>
+      </info>
+      <para>
+    Goliath was not amused.
+    </para>
+      <para>
+    He said to David: "Oh, really. <emphasis>David</emphasis>, the red-headed!".
+    </para>
+    </section>
+  </section>
+</article>

File perl/modules/XML-Grammar-Fiction/t/fiction/data/proto-text/with-span.txt

+<body id="index">
+
+<title>David vs. Goliath - Part I</title>
+
+<s id="top">
+
+<title>The Top Section</title>
+
+<!-- David has Green hair here -->
+
+King <span lang="he-IL">דוד</span> and <span id="foobar">Foobar Anchor</span> and <span id="peter" lang="fr-FR">Pierre</span> and Goliath were standing by each other.
+
+David said unto Goliath: "I will shoot you. I <b>swear</b> I will"
+
+<s id="goliath">
+
+<title>Goliath's Response</title>
+
+<!-- Goliath has to reply to that. -->
+
+Goliath was not amused.
+
+He said to David: "Oh, really. <i>David</i>, the red-headed!".
+
+</s>
+
+</s>
+
+</body>
+

File perl/modules/XML-Grammar-Fiction/t/fiction/data/xml/with-span.xml

+<?xml version='1.0' encoding='utf-8'?>
+<document xmlns="http://web-cpan.berlios.de/modules/XML-Grammar-Fortune/fiction-xml-0.2/" xmlns:xlink="http://www.w3.org/1999/xlink" version="0.2">
+    <head>
+    </head>
+    <body xml:id="index">
+    <title>David vs. Goliath - Part I</title>
+    <section xml:id="top">
+    <title>The Top Section</title>
+    <!-- David has Green hair here -->
+    <p>
+    King <span xml:lang="he-IL">דוד</span> and <span xml:id="foobar">Foobar Anchor</span> and <span xml:id="peter" xml:lang="fr-FR">Pierre</span> 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">
+    <title>Goliath's Response</title>
+    <!-- Goliath has to reply to that. -->
+    <p>
+    Goliath was not amused.
+    </p>
+    <p>
+    He said to David: "Oh, really. <i>David</i>, the red-headed!".
+    </p>
+    </section>
+    </section>
+</body>
+</document>

File perl/modules/XML-Grammar-Fiction/t/fiction/proto-text-to-xml-using-custom-parser.t

 use strict;
 use warnings;
 
-use Test::More tests => 21;
+use Test::More tests => 23;
 
 use Test::XML;
 
     paras-with-entities-at-start-of-line
     with-xml-lang-attribute
     with-xml-lang-attr-in-section
+    with-span
     ));
 
-# TEST:$num_texts=10
+# TEST:$num_texts=11
 
 my $grammar = XML::Grammar::Fiction::FromProto->new({
         parser_class => "XML::Grammar::Fiction::FromProto::Parser::QnD",

File perl/modules/XML-Grammar-Fiction/t/fiction/to-docbook.t

 
 use Test::More;
 
-use Test::XML tests => 24;
+use Test::XML tests => 27;
 
 use File::Spec;
 
         with-programlisting
         with-xml-lang-attribute
         with-xml-lang-attr-in-section
+        with-span
     ));
 
 sub load_xml
     return $contents;
 }
 
-# TEST:$num_texts=8
+# TEST:$num_texts=9
 
 my $converter = XML::Grammar::Fiction::ToDocBook->new({
         data_dir => File::Spec->catdir(File::Spec->curdir(), "extradata"),