Skip to content

Commit

Permalink
Merge pull request #4890 from vincent/bufgix-ebook-toc-nested-chapters
Browse files Browse the repository at this point in the history
Show nested chapters in bookplayer TOC
  • Loading branch information
thornbill authored Nov 8, 2023
2 parents 0c6afd1 + 55f5a78 commit 7df0ffc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/plugins/bookPlayer/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@
margin-bottom: 5px;

list-style-type: none;
font-size: 120%;
font-size: 1.2rem;
font-weight: bold;

ul {
padding-left: 1.5rem;

li {
font-weight: normal;
}
}

a:link {
color: #000;
Expand Down
27 changes: 21 additions & 6 deletions src/plugins/bookPlayer/tableOfContents.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import escapeHTML from 'escape-html';
import dialogHelper from '../../components/dialogHelper/dialogHelper';

export default class TableOfContents {
Expand Down Expand Up @@ -51,6 +52,25 @@ export default class TableOfContents {
});
}

chapterTocItem(book, chapter) {
let itemHtml = '<li>';

// remove parent directory reference from href to fix certain books
const link = chapter.href.startsWith('../') ? chapter.href.slice(3) : chapter.href;
itemHtml += `<a href="${escapeHTML(book.path.directory + link)}">${escapeHTML(chapter.label)}</a>`;

if (chapter.subitems?.length) {
const subHtml = chapter.subitems
.map((nestedChapter) => this.chapterTocItem(book, nestedChapter))
.join('');

itemHtml += `<ul>${subHtml}</ul>`;
}

itemHtml += '</li>';
return itemHtml;
}

createMediaElement() {
const rendition = this.rendition;

Expand All @@ -67,12 +87,7 @@ export default class TableOfContents {
tocHtml += '</div>';
tocHtml += '<ul class="toc">';
rendition.book.navigation.forEach((chapter) => {
tocHtml += '<li>';

// remove parent directory reference from href to fix certain books
const link = chapter.href.startsWith('../') ? chapter.href.slice(3) : chapter.href;
tocHtml += `<a href="${rendition.book.path.directory + link}">${chapter.label}</a>`;
tocHtml += '</li>';
tocHtml += this.chapterTocItem(rendition.book, chapter);
});

tocHtml += '</ul>';
Expand Down

0 comments on commit 7df0ffc

Please sign in to comment.