--- ./s5_original/s5_book.module	2008-01-12 09:33:24.000000000 -0200
+++ ./s5/s5_book.module	2008-06-04 18:10:39.000000000 -0300
@@ -84,7 +84,11 @@ function s5_book_settings_form() {
       '#options' => drupal_map_assoc($themes),
       '#description' => t('Choose your theme from this list.  You can also add more themes to S5.'),
     );
-
+    $form['s5_book_break_paragraphs'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Break paragraphs into sequence of slides.'),
+      '#default_value' => variable_get('s5_book_break_paragraphs', FALSE),
+    );
   }
   else {
     $form['s5_error_message'] = array(
@@ -150,8 +154,30 @@ function s5_book_node_display($node, $de
 
   // Enclose slide in wrapper (you can have handout info on slide)
   if ($node->body) {
-    return '<div class="slide"><h1>'. check_plain($node->title) ."</h1>\n".
-              $node->body .'</div>'; 
+
+// Check if paragraphs should stay intact or be broken into a sequence of slides
+    if (!variable_get('s5_book_break_paragraphs', FALSE))
+       return '<div class="slide"><h1>'. check_plain($node->title) ."</h1>\n". $node->body .'</div>';
+
+    // Create sequence of slides by inserting breaks at the end of each paragraph
+    $sequence = "";
+    $slides = $node->body;
+    $slides = preg_replace("(<\/p>)","</p><!--pagebreak-->",$slides);
+    $slides = explode("<!--pagebreak-->",$slides);
+    
+    // Iterate through the slides
+    foreach($slides as $slide) {
+       // Remove empty slides
+       $slide = rtrim($slide);
+
+       // Add the valid slides to the sequence
+       if ($slide != "")
+           $sequence .= '<div class="slide"><h1>'. check_plain($node->title) ."</h1>\n". check_markup($slide, $node->format, FALSE) .'</div>';
+    }
+
+    // Return sequence of slides
+    return $sequence;
+
   }
 }
 
