Linkified all images

This commit is contained in:
2020-05-05 12:35:19 +02:00
parent 282aea97a0
commit d800e05179
7 changed files with 22 additions and 7 deletions

View File

@@ -27,6 +27,19 @@ 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);
link.append(img);
}
});
}
Future<void> reorganizeHtml() async {
final content = querySelector('#content');
@@ -47,6 +60,8 @@ Future<void> reorganizeHtml() async {
// 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'));