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:
parent
cc6519c302
commit
e81986683c
@ -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());
|
||||
|
Reference in New Issue
Block a user