2020-04-24 16:14:52 +00:00
|
|
|
import 'dart:html';
|
|
|
|
|
2020-05-05 10:34:22 +00:00
|
|
|
import './navbar.dart' show makeNavbar;
|
2020-04-24 16:14:52 +00:00
|
|
|
|
2020-05-04 13:59:11 +00:00
|
|
|
Future<Element> makeHeader() async {
|
2020-04-28 20:32:37 +00:00
|
|
|
var header = Element.tag('header');
|
|
|
|
header
|
|
|
|
..append(Element.img()
|
|
|
|
..attributes['src'] =
|
|
|
|
'https://cdn.phundrak.com/img/mahakala-monochrome.png'
|
|
|
|
..attributes['alt'] = 'Logo de Phundrak'
|
|
|
|
..attributes['heigh'] = '150px'
|
|
|
|
..attributes['width'] = '150px')
|
|
|
|
..append(querySelector('h1'));
|
|
|
|
var subt = querySelector('.subtitle');
|
|
|
|
if (subt != null) {
|
|
|
|
header.append(subt);
|
|
|
|
}
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2020-04-24 16:14:52 +00:00
|
|
|
Future<void> wrapTables() async {
|
|
|
|
for (var table in querySelectorAll('table')) {
|
|
|
|
var largetable = DivElement()..className = 'largetable';
|
|
|
|
table.before(largetable);
|
|
|
|
largetable.children.add(table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 10:35:19 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-24 16:14:52 +00:00
|
|
|
Future<void> reorganizeHtml() async {
|
2020-05-04 13:59:11 +00:00
|
|
|
final content = querySelector('#content');
|
|
|
|
|
|
|
|
// Make navbar
|
2020-04-24 16:14:52 +00:00
|
|
|
await makeNavbar().then((navbar) {
|
|
|
|
querySelector('body').insertAdjacentElement('afterBegin', navbar);
|
2020-05-04 13:59:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Make header
|
|
|
|
await makeHeader().then((header) {
|
|
|
|
content.insertAdjacentElement('beforeBegin', header);
|
2020-05-02 17:23:06 +00:00
|
|
|
final subtitle = querySelector('.subtitle');
|
|
|
|
if (subtitle != null) {
|
2020-05-04 14:06:53 +00:00
|
|
|
header.append(subtitle);
|
2020-05-02 17:23:06 +00:00
|
|
|
}
|
2020-04-24 16:14:52 +00:00
|
|
|
});
|
|
|
|
|
2020-04-28 20:32:37 +00:00
|
|
|
// wrap tables in container for better SCSS display
|
|
|
|
await wrapTables();
|
2020-05-04 13:59:11 +00:00
|
|
|
|
2020-05-05 10:35:19 +00:00
|
|
|
linkifyImg();
|
|
|
|
|
2020-05-04 13:59:11 +00:00
|
|
|
// Add correct class to TOC
|
|
|
|
querySelector('#toc-drop')
|
|
|
|
.append(querySelector('#table-of-contents')..classes.add('dropdown'));
|
2020-05-04 14:06:53 +00:00
|
|
|
|
|
|
|
// Remove all <br> tags from HTML
|
|
|
|
querySelectorAll('br').forEach((br) => br.remove());
|
2020-04-24 16:14:52 +00:00
|
|
|
}
|