Fixes issue #5

The absence of a table of contents made the Dart code crash. This commit
adds a default TOC if non already exists.
This commit is contained in:
Lucien Cartier-Tilet 2020-05-07 15:36:50 +02:00
parent cc6519c302
commit e81986683c
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
1 changed files with 5 additions and 4 deletions

View File

@ -32,8 +32,6 @@ Future<void> wrapTables() async {
// All images that are not nested inside a link will be linkified to themselves.
void linkifyImg() {
querySelectorAll('img').forEach((img) {
print(img.attributes['src']);
print(img.parent.tagName);
if (img.parent.tagName == 'P') {
final link = Element.a()..attributes['href'] = img.attributes['src'];
img.insertAdjacentElement('beforeBegin', link);
@ -65,8 +63,11 @@ Future<void> reorganizeHtml() async {
linkifyImg();
// Add correct class to TOC
querySelector('#toc-drop')
.append(querySelector('#table-of-contents')..classes.add('dropdown'));
final toc = (querySelector('#table-of-contents') ?? Element.div()
..attributes['id'] = 'table-of-contents')
..classes.add('dropdown')
..innerText = "Table of Contents Unavailable";
querySelector('#toc-drop').append(toc);
// Remove all <br> tags from HTML
querySelectorAll('br').forEach((br) => br.remove());