1. Shlomi Fish
  2. Fiction-XML

Commits

shl...@52c325ad-5fd0-0310-8a0f-c43feede02cc  committed af0693a

Implement the xml:lang attribute for the <section>|<s> element.

  • Participants
  • Parent commits c25482c
  • Branches default

Comments (0)

Files changed (9)

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

View file
  • Ignore whitespace
     * Add support for the lang="..." attribute of <body> in Fiction-Text which
     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>.
 
 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

View file
  • Ignore whitespace
 t/fiction/data/docbook/with-programlisting.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-invalid/inner-desc-inside-char-addressing.txt
 t/fiction/data/proto-text-invalid/leading-space-at-para-start.txt
 t/fiction/data/proto-text-invalid/leading-space.txt
 t/fiction/data/proto-text/with-programlisting.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/paras-with-entities-at-start-of-line.xml
 t/fiction/data/xml/sections-a-href.xml
 t/fiction/data/xml/sections-and-paras.xml
 t/fiction/data/xml/with-programlisting.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
 t/fiction/proto-text-invalid.t
 t/fiction/proto-text-to-xml-using-custom-parser.t
 t/fiction/qnd-parser-unit.t

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

View file
  • Ignore whitespace
         <xsl:attribute name="xml:id">
             <xsl:value-of select="@xml:id" />
         </xsl:attribute>
+        <xsl:if test="@xml:lang">
+            <xsl:attribute name="xml:lang">
+                <xsl:value-of select="@xml:lang" />
+            </xsl:attribute>
+        </xsl:if>
         <!-- Make the title the title attribute or "ID" if does not exist. -->
         <info>
         <title>

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

View file
  • Ignore whitespace
     
     if (($tag eq "s") || ($tag eq "scene"))
     {
+        # TODO : abstract with _write_body.
         my $id = $scene->lookup_attr("id");
+        my $lang = $scene->lookup_attr("lang");
 
         if (!defined($id))
         {
             Carp::confess("Unspecified id for scene!");
         }
 
+        my @lang_attr;
+
+        if (defined($lang))
+        {
+            push @lang_attr, ([$xml_ns, 'lang'] => $lang);
+        }
+
         $self->_output_tag_with_childs(
             {
-                'start' => ["section", [$xml_ns, "id"] => $id],
+                'start' => ["section", [$xml_ns, "id"] => $id, @lang_attr,],
                 elem => $scene,
             }
         );
         confess "Improper body tag - should be '<body>'!";
     }
 
+    # TODO : abstract with _write_scene.
     my $id = $body->lookup_attr("id");
     my $lang = $body->lookup_attr("lang");
 =begin foo
     {
         push @lang_attr, ([$xml_ns, 'lang'] => $lang);
     }
+
     $self->_output_tag_with_childs(
         {
             'start' => ["body", [$xml_ns, "id"] => $id, @lang_attr,],

File perl/modules/XML-Grammar-Fiction/t/fiction/data/docbook/with-xml-lang-attr-in-section.docbook.xml

View file
  • Ignore whitespace
+<?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="en-US" version="5.0">
+  <info>
+    <title>David vs. Goliath - Part I</title>
+  </info>
+  <section xml:id="top">
+    <info>
+      <title>The Top Section</title>
+    </info>
+    <para>
+    David 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>
+  <section xml:id="french" xml:lang="fr-FR">
+    <info>
+       <title>In French</title>
+    </info>
+    <para>
+    Je ne parle pas Français bien.
+    </para>
+  </section>
+</article>

File perl/modules/XML-Grammar-Fiction/t/fiction/data/proto-text/with-xml-lang-attr-in-section.txt

View file
  • Ignore whitespace
+<body id="index" lang="en-US">
+
+<title>David vs. Goliath - Part I</title>
+
+<s id="top">
+
+<title>The Top Section</title>
+
+David 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 was not amused.
+
+He said to David: "Oh, really. <i>David</i>, the red-headed!".
+
+</s>
+
+</s>
+
+<s id="french" lang="fr-FR">
+
+<title>In French</title>
+
+Je ne parle pas Français bien.
+
+</s>
+
+</body>
+

File perl/modules/XML-Grammar-Fiction/t/fiction/data/xml/with-xml-lang-attr-in-section.xml

View file
  • Ignore whitespace
+<?xml version='1.0' encoding='utf-8'?>
+<document xmlns="http://web-cpan.berlios.de/modules/XML-Grammar-Fortune/fiction-xml-0.2/" version="0.2">
+    <head>
+    </head>
+    <body xml:id="index" xml:lang="en-US">
+    <title>David vs. Goliath - Part I</title>
+    <section xml:id="top">
+    <title>The Top Section</title>
+    <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">
+    <title>Goliath's Response</title>
+    <p>
+    Goliath was not amused.
+    </p>
+    <p>
+    He said to David: "Oh, really. <i>David</i>, the red-headed!".
+    </p>
+    </section>
+    </section>
+    <section xml:id="french" xml:lang="fr-FR">
+    <title>In French</title>
+    <p>
+    Je ne parle pas Français bien.
+    </p>
+    </section>
+</body>
+</document>

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

View file
  • Ignore whitespace
 use strict;
 use warnings;
 
-use Test::More tests => 19;
+use Test::More tests => 21;
 
 use Test::XML;
 
     with-programlisting
     paras-with-entities-at-start-of-line
     with-xml-lang-attribute
+    with-xml-lang-attr-in-section
     ));
 
-# TEST:$num_texts=9
+# TEST:$num_texts=10
 
 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

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