Skip to content

Commit

Permalink
Fixed an error with headers for books published as 1-page-per-chapter
Browse files Browse the repository at this point in the history
When the chunk_level of a book published as a website is 1, each chapter
is published in one page. <h1> and <h2> headers were correctly published
but <h3> .. <h6> headers weren't properly published because they lacked
the `id` attribute.

Now all the headers are correctly generated regardless of their level.
  • Loading branch information
javiereguiluz committed May 11, 2014
1 parent 0954249 commit 9046ace
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Easybook/Publishers/HtmlChunkedPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,30 @@ private function flattenToc()
foreach ($bookItems as $item) {
$itemToc = array();
foreach ($item['toc'] as $chunk) {
// first-level headers
if (isset($chunk['level']) && 1 == $chunk['level']) {
$chunk['url'] = sprintf('%s.html', $item['page_name']);
$chunk['parent'] = null;
$chunk['config'] = $item['config']; // needed for templates

$parentChunk = $chunk;
// second-level headers
} elseif (isset($chunk['level']) && 2 == $chunk['level']) {
if (1 == $this->app->edition('chunk_level')) {
$chunk['url'] = sprintf('%s.html#%s', $item['page_name'], $chunk['slug']);
} elseif (2 == $this->app->edition('chunk_level')) {
$chunk['url'] = sprintf('%s/%s.html', $item['page_name'], $chunk['slug']);
}

$chunk['parent'] = $parentChunk;
// third to sixth level headers
} elseif (isset($chunk['level'])) {
if (1 == $this->app->edition('chunk_level')) {
$chunk['url'] = sprintf('%s.html#%s', $item['page_name'], $chunk['slug']);
} elseif (2 == $this->app->edition('chunk_level')) {
$chunk['url'] = sprintf('%s/%s.html#%s', $item['page_name'], $parentChunk['slug'], $chunk['slug']);
}

$chunk['parent'] = $parentChunk;
}

Expand Down

0 comments on commit 9046ace

Please sign in to comment.