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 | const emd = require("ecmarkdown");
|
14 | const utils = require("./utils");
|
15 |
|
16 | class Eqn extends Builder_1.default {
|
17 |
|
18 | constructor() {
|
19 | throw new Error('not actually constructible');
|
20 | }
|
21 | static enter(context) {
|
22 | return __awaiter(this, void 0, void 0, function* () {
|
23 | const { spec, node, clauseStack } = context;
|
24 | const aoid = node.getAttribute('aoid');
|
25 | if (aoid) {
|
26 | const existing = spec.biblio.keysForNamespace(spec.namespace);
|
27 | if (existing.has(aoid)) {
|
28 | spec.warn({
|
29 | type: 'attr-value',
|
30 | attr: 'aoid',
|
31 | node,
|
32 | ruleId: 'duplicate-definition',
|
33 | message: `duplicate definition ${JSON.stringify(aoid)}`,
|
34 | });
|
35 | }
|
36 | const id = node.getAttribute('id');
|
37 | if (id) {
|
38 | spec.biblio.add({
|
39 | type: 'op',
|
40 | aoid,
|
41 | id,
|
42 | });
|
43 | }
|
44 | else {
|
45 | const clause = clauseStack[clauseStack.length - 1];
|
46 | const clauseId = clause ? clause.id : '';
|
47 | spec.biblio.add({
|
48 | type: 'op',
|
49 | aoid,
|
50 | refId: clauseId,
|
51 | });
|
52 | }
|
53 | }
|
54 | let contents;
|
55 | try {
|
56 | contents = emd.fragment(node.innerHTML);
|
57 | }
|
58 | catch (e) {
|
59 | utils.warnEmdFailure(spec.warn, node, e);
|
60 | node.innerHTML = utils.wrapEmdFailure(node.innerHTML);
|
61 | return;
|
62 | }
|
63 | if (utils.shouldInline(node)) {
|
64 | const classString = node.getAttribute('class');
|
65 | let classes;
|
66 | if (classString) {
|
67 | classes = classString.split(' ');
|
68 | }
|
69 | else {
|
70 | classes = [];
|
71 | }
|
72 | if (classes.indexOf('inline') === -1) {
|
73 | node.setAttribute('class', classes.concat(['inline']).join(' '));
|
74 | }
|
75 | }
|
76 | else {
|
77 | contents =
|
78 | '<div>' +
|
79 | contents
|
80 | .split(/\r?\n/g)
|
81 | .filter(s => s.trim().length > 0)
|
82 | .join('</div><div>') +
|
83 | '</div>';
|
84 | }
|
85 | node.innerHTML = contents;
|
86 | });
|
87 | }
|
88 | }
|
89 | exports.default = Eqn;
|
90 | Eqn.elements = ['EMU-EQN'];
|