UNPKG

2.6 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12const Builder_1 = require("./Builder");
13class Figure extends Builder_1.default {
14 constructor(spec, node) {
15 super(spec, node);
16 this.type = node.nodeName.split('-')[1].toLowerCase();
17 this.number = ++spec._figureCounts[this.type];
18 this.id = node.getAttribute('id');
19 this.isInformative = node.hasAttribute('informative');
20 this.captionElem = node.querySelector('emu-caption');
21 this.caption = this.type.charAt(0).toUpperCase() + this.type.slice(1) + ' ' + this.number;
22 if (this.isInformative) {
23 this.caption += ' (Informative)';
24 }
25 if (this.captionElem) {
26 this.caption += ': ' + this.captionElem.innerHTML;
27 }
28 else if (node.getAttribute('caption')) {
29 this.caption += ': ' + node.getAttribute('caption');
30 }
31 if (this.id) {
32 spec.biblio.add({
33 type: this.type,
34 id: this.id,
35 node: this.node,
36 number: this.number,
37 caption: this.caption,
38 });
39 }
40 }
41 static enter({ spec, node }) {
42 return __awaiter(this, void 0, void 0, function* () {
43 const figure = new Figure(spec, node);
44 if (figure.captionElem && figure.captionElem.parentNode) {
45 figure.captionElem.parentNode.removeChild(figure.captionElem);
46 }
47 const ele = spec.doc.createElement('figure');
48 ele.append(...node.childNodes);
49 node.append(ele);
50 const captionElem = spec.doc.createElement('figcaption');
51 captionElem.innerHTML = figure.caption;
52 node.childNodes[0].insertBefore(captionElem, node.childNodes[0].firstChild);
53 });
54 }
55}
56exports.default = Figure;
57Figure.elements = ['EMU-FIGURE', 'EMU-TABLE'];