Better coding style

This commit is contained in:
2020-05-10 12:37:22 +02:00
parent aa4600b588
commit 8ca55cb710
3 changed files with 20 additions and 22 deletions

View File

@@ -30,7 +30,7 @@ Future<void> wrapTables() async {
}
// All images that are not nested inside a link will be linkified to themselves.
void linkifyImg() {
Future<void> linkifyImg() async {
querySelectorAll('img').forEach((img) {
if (img.parent.tagName == 'P') {
final link = Element.a()..attributes['href'] = img.attributes['src'];
@@ -41,34 +41,31 @@ void linkifyImg() {
}
Future<void> reorganizeHtml() async {
final content = querySelector('#content');
// Make navbar
await makeNavbar().then((navbar) {
querySelector('body').insertAdjacentElement('afterBegin', navbar);
});
final navbar = await makeNavbar();
// Make header
await makeHeader().then((header) {
content.insertAdjacentElement('beforeBegin', header);
final subtitle = querySelector('.subtitle');
if (subtitle != null) {
header.append(subtitle);
}
});
final header = await makeHeader();
// wrap tables in container for better SCSS display
await wrapTables();
linkifyImg();
// Make images not linking somewhere link to themselves
await linkifyImg();
// Add navbar to page
querySelector('body').insertAdjacentElement('afterBegin', navbar);
// Add headet to page
querySelector('#content').insertAdjacentElement('beforeBegin', header);
// Add correct class to TOC
final toc = (querySelector('#table-of-contents') ??
(Element.div()
..attributes['id'] = 'table-of-contents'
..innerText = "Table of Contents Unavailable"))
..innerText = 'Table of Contents Unavailable'))
..classes.add('dropdown');
querySelector('#toc-drop').append(toc);
navbar.querySelector('#toc-drop').append(toc);
// Remove all <br> tags from HTML
querySelectorAll('br').forEach((br) => br.remove());