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