2020-05-05 12:49:26 +00:00
|
|
|
import 'dart:html';
|
|
|
|
|
|
|
|
import './navbar.dart' show makeNavbar;
|
|
|
|
|
2020-05-05 17:33:57 +00:00
|
|
|
const image_header = 'https://cdn.phundrak.com/img/mahakala-monochrome.png';
|
2020-05-05 17:20:28 +00:00
|
|
|
|
2020-05-05 12:49:26 +00:00
|
|
|
Future<Element> makeHeader() async {
|
|
|
|
var header = Element.tag('header');
|
|
|
|
header
|
|
|
|
..append(Element.img()
|
2020-05-05 17:20:28 +00:00
|
|
|
..attributes['src'] = image_header
|
|
|
|
..attributes['alt'] = 'Logo'
|
2020-05-05 12:49:26 +00:00
|
|
|
..attributes['heigh'] = '150px'
|
|
|
|
..attributes['width'] = '150px')
|
|
|
|
..append(querySelector('h1'));
|
|
|
|
var subt = querySelector('.subtitle');
|
|
|
|
if (subt != null) {
|
|
|
|
header.append(subt);
|
|
|
|
}
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> wrapTables() async {
|
|
|
|
for (var table in querySelectorAll('table')) {
|
|
|
|
var largetable = DivElement()..className = 'largetable';
|
|
|
|
table.before(largetable);
|
|
|
|
largetable.children.add(table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
link.append(img);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> reorganizeHtml() async {
|
|
|
|
final content = querySelector('#content');
|
|
|
|
|
|
|
|
// Make navbar
|
|
|
|
await makeNavbar().then((navbar) {
|
|
|
|
querySelector('body').insertAdjacentElement('afterBegin', navbar);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Make header
|
|
|
|
await makeHeader().then((header) {
|
|
|
|
content.insertAdjacentElement('beforeBegin', header);
|
|
|
|
final subtitle = querySelector('.subtitle');
|
|
|
|
if (subtitle != null) {
|
|
|
|
header.append(subtitle);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// wrap tables in container for better SCSS display
|
|
|
|
await wrapTables();
|
|
|
|
|
|
|
|
linkifyImg();
|
|
|
|
|
|
|
|
// Add correct class to TOC
|
|
|
|
querySelector('#toc-drop')
|
|
|
|
.append(querySelector('#table-of-contents')..classes.add('dropdown'));
|
|
|
|
|
|
|
|
// Remove all <br> tags from HTML
|
|
|
|
querySelectorAll('br').forEach((br) => br.remove());
|
|
|
|
}
|