1 | "use strict";
|
2 | var __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 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const Builder_1 = require("./Builder");
|
13 |
|
14 | class Example extends Builder_1.default {
|
15 | constructor(spec, node, clause) {
|
16 | super(spec, node);
|
17 | this.clause = clause;
|
18 | this.caption = this.node.getAttribute('caption');
|
19 | if (this.node.hasAttribute('id')) {
|
20 | this.id = this.node.getAttribute('id');
|
21 | }
|
22 | }
|
23 | static enter({ spec, node, clauseStack }) {
|
24 | return __awaiter(this, void 0, void 0, function* () {
|
25 | const clause = clauseStack[clauseStack.length - 1];
|
26 | if (!clause)
|
27 | return;
|
28 | clause.examples.push(new Example(spec, node, clause));
|
29 | });
|
30 | }
|
31 | build(number) {
|
32 | if (this.id) {
|
33 |
|
34 |
|
35 | this.spec.biblio.add({
|
36 | type: 'example',
|
37 | id: this.id,
|
38 | node: this.node,
|
39 | number: number || 1,
|
40 | clauseId: this.clause.id,
|
41 | });
|
42 | }
|
43 | const ele = this.spec.doc.createElement('figure');
|
44 | ele.append(...this.node.childNodes);
|
45 | this.node.append(ele);
|
46 | let caption = 'Example';
|
47 | if (number) {
|
48 | caption += ' ' + number;
|
49 | }
|
50 | caption += ' (Informative)';
|
51 | if (this.caption) {
|
52 | caption += ': ' + this.caption;
|
53 | }
|
54 | const captionElem = this.spec.doc.createElement('figcaption');
|
55 | captionElem.textContent = caption;
|
56 | this.node.childNodes[0].insertBefore(captionElem, this.node.childNodes[0].firstChild);
|
57 | }
|
58 | }
|
59 | exports.default = Example;
|
60 | Example.elements = ['EMU-EXAMPLE'];
|