Splitting Chapters of Drupal Books

Recommend this page to a friend!

      EPub  >  All threads  >  Splitting Chapters of Drupal Books  >  (Un) Subscribe thread alerts  
Subject:Splitting Chapters of Drupal Books
Summary:Drupal books don't split on child pages
Messages:5
Author:Jim Burke
Date:2015-08-28 19:58:27
 

  1. Splitting Chapters of Drupal Books   Reply   Report abuse  
Picture of Jim Burke Jim Burke - 2015-08-28 19:58:27
I've installed on a Drupal 7 site. A book will generate an epub including all the child pages, but I can't get it to split the child pages as chapters - it ends up with a sungle chapter. I have set $searchString = '/<h1/i' in EPubChapter.php along with a couple of other iterations but I'm missing something. Any suggestions would be appreciated.
Jim

  2. Re: Splitting Chapters of Drupal Books   Reply   Report abuse  
Picture of Asbjorn Grandt Asbjorn Grandt - 2015-08-28 22:24:15 - In reply to message 1 from Jim Burke
Du you have a link to the drupal plug-in?

EpubChapter.php isn't my class, but if I recall it does use my ePub library.

  3. Re: Splitting Chapters of Drupal Books   Reply   Report abuse  
Picture of Jim Burke Jim Burke - 2015-08-31 15:51:44 - In reply to message 2 from Asbjorn Grandt
Asbjorn,
Not sure what you mean for the Drupal plugin. I have the module "Printer, email and PDF versions"(https://www.drupal.org/project/print) which say it needs your PHPEpub.This is installed in /sites/all/libraries/PHPePub-master/ That directory is where EpubChapterSplitter.php lives. I suspect I am missing something major but would appreciate any guidance.
Jim

  4. Re: Splitting Chapters of Drupal Books   Reply   Report abuse  
Picture of Asbjorn Grandt Asbjorn Grandt - 2015-09-01 18:31:54 - In reply to message 3 from Jim Burke
I'll have a look at how the module works. The thing is, my PHPePub class have been massively updated since that Drupal module were made. I recall helping the author of it a few years ago.

I'll see if I can get back to you within the next 24 hours or so, preferably with a solution.

Cheers.

  5. Re: Splitting Chapters of Drupal Books   Reply   Report abuse  
Picture of Asbjorn Grandt Asbjorn Grandt - 2015-09-01 19:40:05 - In reply to message 4 from Asbjorn Grandt
When you say EPubChapter.php I assume you mean EPubChapterSplitter.php

I just tested it on the current version of PHPePUB, and it detected my headers, and returned an array with the parts.


$splitter = new EPubChapterSplitter();

$searchString = '/<h1/i';
$html2 = $splitter->splitChapter($chapter5, true, $searchString);

// $html2 is an array where the keys are the entire line, including start and end tags of the hit.
// and the value is the segment for the match.
// The returned array can just be parsed to the addChapter like this:
// $book->addChapter($cName, "Chapter005.html", $html2, true);
// and EPub will add the parts automatically.
// However, often you'd want to try to get a measure of control over the process

$idx = 0;
while (list($k, $v) = each($html2)) {
$idx++;
// Because we used a string search in the splitter, the returned hits are put in the key part of the array.
// The entire HTML tag of the line matching the chapter search.

// Strip start and end tags. This Regexp will keep the tag name as well as the data between them.
preg_match('#^<(\w+)\s*.*?>(.+)</\s*\1>$#i', $k, $cName);

// This is simply to clean up the chapter name, it can't contain any HTML.
// Because of the back reference, the tag name is in $cName[1], and the content is in $cName[2], this is to be the chapter name in the TOC.
$cName = preg_replace('#<br.+?>#i', " - ", $cName[2]); // Change any line breaks in the chapter name to " - "
$cName = preg_replace('#<.+?>#i', " ", $cName); // Remove any other tags
$cName = preg_replace('#\s+#i', " ", $cName); // clean the chapter name by removing any double spaces left behind to single space.

$book->addChapter(trim($cName), "Chapter005_" . $idx . ".html", $v, true);
}

 

For more information send a message to info at phpclasses dot org.