forked from speced/respec
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathabstract.js
More file actions
43 lines (39 loc) · 1.31 KB
/
abstract.js
File metadata and controls
43 lines (39 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// @ts-check
// Module 1edtech/abstract
// Handle the abstract section properly.
import { html } from "../core/import-maps.js";
import { getIntlData, showWarning } from "../core/utils.js";
export const name = "1edtech/abstract";
import localizationStrings from "./translations/abstract.js";
const l10n = getIntlData(localizationStrings);
/**
* Handles checking for the abstract, and inserts a temp one if not present.
*/
export async function run() {
let abstract = document.getElementById("abstract");
if (!abstract) {
showWarning("Document should have one element with 'abstract'", name);
// insert a temp abstract
abstract = html`<section id="abstract" class="introductory remove">
<h2>${l10n.to_be_removed}</h2>
</section>`;
document.body.prepend(abstract);
}
if (abstract.tagName.startsWith("H")) {
abstract.removeAttribute("id");
abstract = abstract.parentElement;
abstract.id = "abstract";
}
if (abstract.tagName === "SECTION") {
if (!abstract.classList.contains("introductory")) {
abstract.classList.add("introductory");
}
}
let abstractHeading = document.querySelector("#abstract>h2");
if (abstractHeading) {
return;
}
abstractHeading = document.createElement("h2");
abstractHeading.textContent = l10n.abstract;
abstract.prepend(abstractHeading);
}