Commits

Anonymous committed 5d0ba8a

Add support for \n\n+<b>Style here</b> Rest of paragraph.

Opening line at the beginning .

  • Participants
  • Parent commits 688557f

Comments (0)

Files changed (9)

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

 Revision history for XML-Grammar-Fiction.
 
     * <blockquote> now supports xml:id and xml:lang.
+    * Fiction-Text: a plus sign ( + ) at the starting line of the paragraph
+    now indicates that the following tag is a style tag.
 
 0.7.0       Wed May 25 12:47:13 IDT 2011
     * Add support for the lang="..." attribute of <body> in Fiction-Text which

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

 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-style-tag-at-start-of-paragraph.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/with-blockquote.xml
 t/fiction/data/xml/with-programlisting.xml
 t/fiction/data/xml/with-span.xml
+t/fiction/data/xml/with-style-tag-at-start-of-paragraph.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/lib/XML/Grammar/Fiction.pm

 =head3 Paragraphs
 
 These are not delimited by anything - just a paragraph of text not containing
-an empty line.
+an empty line. If a paragraph starts with a Plus sign ( C<+> ) then it is 
+immediately expected to be followed by a styling tag (as opposed to a 
 
 =head3 <ol>
 

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

         "XML::Grammar::Fiction::Err::Parse::ProgramListingContainsTags" =>
         {
             isa => "XML::Grammar::Fiction::Err::Parse::LineError",
-        }
+        },
+        "XML::Grammar::Fiction::Err::Parse::ParaOpenPlusNotFollowedByTag" =>
+        {
+            isa => "XML::Grammar::Fiction::Err::Parse::LineError",
+        },
     )
     ;
 1;

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

 
 extends("XML::Grammar::Fiction::FromProto::Node::WithContent");
 
+sub get_text
+{
+    my ($self, $re) = @_;
+
+    return $self->children->contents->[0];
+}
+
 package XML::Grammar::Fiction::FromProto::Node::Saying;
 
 use Moose;

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

         $in_para = 1;
     }
 
-    $self->_enqueue_event(
-        XML::Grammar::FictionBase::Event->new(
-            {type => "elem", elem => $elem}
-        )
-    );
+    if (my ($rest) = $elem->get_text() =~ m{\A\+(.*)}ms)
+    {
+        if ( length($rest) )
+        {
+            $self->throw_text_error(
+                'XML::Grammar::Fiction::Err::Parse::ParaOpenPlusNotFollowedByTag',
+                "Got a paragraph opening plus sign not followed by a tag.",
+            );
+        }
+        # Else - do nothing - just ignore the + sign before the
+        # style tag.
+    }
+    else
+    {
+        $self->_enqueue_event(
+            XML::Grammar::FictionBase::Event->new(
+                {type => "elem", elem => $elem}
+            )
+        );
+    }
 
     if ($is_para_end && $in_para)
     {

File perl/modules/XML-Grammar-Fiction/t/fiction/data/proto-text/with-style-tag-at-start-of-paragraph.txt

+<body id="index">
+
+<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.
+
++<b>He</b> said to David: "Oh, really. <i>David</i>, the red-headed!".
+And Goliath was lying.
+
+</s>
+
+</s>
+
+</body>
+

File perl/modules/XML-Grammar-Fiction/t/fiction/data/xml/with-style-tag-at-start-of-paragraph.xml

+<?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">
+    <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>
+    <b>He</b> said to David: "Oh, really. <i>David</i>, the red-headed!".
+    And Goliath was lying.
+    </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 => 27;
+use Test::More tests => 29;
 
 use Test::XML;
 
     with-span
     a-href-with-id-and-lang
     with-blockquote-with-lang-and-id
+    with-style-tag-at-start-of-paragraph
     ));
 
-# TEST:$num_texts=13
+# TEST:$num_texts=14
 
 my $grammar = XML::Grammar::Fiction::FromProto->new({
         parser_class => "XML::Grammar::Fiction::FromProto::Parser::QnD",