Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show nested chapters in bookplayer TOC #4890

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading