Skip to content

Commit

Permalink
Added legacy folder for easy import for older projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Grandt committed Sep 8, 2015
1 parent e0cb810 commit b13b5a1
Show file tree
Hide file tree
Showing 6 changed files with 394 additions and 12 deletions.
354 changes: 354 additions & 0 deletions legacy/EPub.Test.Example.php

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions legacy/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"require": {
"phpzip/phpzip": ">=2.0.6",
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {
"PHPePub\\": "../src/PHPePub"
}
}
}
Binary file added legacy/composer.phar
Binary file not shown.
3 changes: 3 additions & 0 deletions legacy/install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
php composer.phar self-update
php composer.phar install
php EPub.Test.Example.php
4 changes: 4 additions & 0 deletions legacy/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
php composer.phar self-update
php composer.phar install
php EPub.Test.Example.php
34 changes: 22 additions & 12 deletions tests/EPub.Example1.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,28 +213,38 @@
* "Chapter " is '#^<.+?>Chapter #'
* Essentially, the search string is looking for lines starting with...
*/
$log->logLine("Add Chapter 5");
$html2 = $splitter->splitChapter($chapter5, true, "Chapter ");/* '#^<.+?>Chapter \d*#i'); */

$log->logLine("Split chapter 5");
// $html2 = $splitter->splitChapter($chapter5, true, "#^\<.+?\>Chapter \d*#i");
// $html2 = $splitter->splitChapter($chapter5, true, "Chapter ");
$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

$log->logLine("Add Chapter 5");

$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.

// find the text inside the tags
preg_match('#^<(\w+)\ *.*?>(.+)</\ *\1>$#i', $k, $cName);
// 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);

// because of the back reference, the tag name is in $cName[1], and the content is in $cName[2]
// Change any line breaks in the chapter name to " - "
$cName = preg_replace('#<br.+?>#i', " - ", $cName[2]);
// Remove any other tags
$cName = preg_replace('#<.+?>#i', " ", $cName);
// clean the chapter name by removing any double spaces left behind to single space.
$cName = preg_replace('#\s+#i', " ", $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($cName, "Chapter005_" . $idx . ".html", $v, true);
$book->addChapter(trim($cName), "Chapter005_" . $idx . ".html", $v, true);
}

// Notice that Chapter 1 have an image reference in paragraph 2?
Expand Down

0 comments on commit b13b5a1

Please sign in to comment.