From e81986683c33093c49114ad17941c72e0c15f4aa Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Thu, 7 May 2020 15:36:50 +0200 Subject: [PATCH] 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. --- web/dart/reorganize_html.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/web/dart/reorganize_html.dart b/web/dart/reorganize_html.dart index d3a4021..0f45114 100644 --- a/web/dart/reorganize_html.dart +++ b/web/dart/reorganize_html.dart @@ -32,8 +32,6 @@ Future 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 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
tags from HTML querySelectorAll('br').forEach((br) => br.remove());