highmark-markdown 1.0.152 → 1.0.154
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example.js +153 -68
- package/lib/mixins/element.js +2 -3
- package/lib/mixins/node.js +67 -2
- package/lib/node/markdown/blockListing.js +5 -4
- package/lib/node/markdown/blockListingStart.js +10 -9
- package/lib/node/markdown/className.js +5 -4
- package/lib/node/markdown/directives.js +5 -4
- package/lib/node/markdown/division.js +3 -3
- package/lib/node/markdown/emailLink.js +17 -13
- package/lib/node/markdown/emphasisedText.js +5 -4
- package/lib/node/markdown/footnote.js +5 -2
- package/lib/node/markdown/footnoteLink.js +5 -2
- package/lib/node/markdown/heading.js +5 -2
- package/lib/node/markdown/hyperlink.js +18 -12
- package/lib/node/markdown/image.js +6 -3
- package/lib/node/markdown.js +4 -5
- package/lib/utilities/node.js +89 -0
- package/package.json +3 -3
- package/src/mixins/element.js +1 -3
- package/src/mixins/node.js +98 -1
- package/src/node/markdown/blockListing.js +6 -8
- package/src/node/markdown/blockListingStart.js +10 -12
- package/src/node/markdown/className.js +7 -9
- package/src/node/markdown/directives.js +5 -7
- package/src/node/markdown/division.js +2 -3
- package/src/node/markdown/emailLink.js +18 -19
- package/src/node/markdown/emphasisedText.js +8 -10
- package/src/node/markdown/footnote.js +6 -4
- package/src/node/markdown/footnoteLink.js +6 -4
- package/src/node/markdown/heading.js +5 -3
- package/src/node/markdown/hyperlink.js +19 -16
- package/src/node/markdown/image.js +8 -6
- package/src/node/markdown.js +3 -7
- package/src/utilities/node.js +93 -0
package/src/mixins/node.js
CHANGED
|
@@ -122,6 +122,98 @@ function retrieveParentNode(childNode, node = this) {
|
|
|
122
122
|
return parentNode;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
function fromFirstChildNode(callback) {
|
|
126
|
+
let result;
|
|
127
|
+
|
|
128
|
+
const firstIndex = 0;
|
|
129
|
+
|
|
130
|
+
this.forwardsSomeChildNode((childNode, index) => {
|
|
131
|
+
if (index === firstIndex) {
|
|
132
|
+
const firstChildNode = childNode; ///
|
|
133
|
+
|
|
134
|
+
result = callback(firstChildNode);
|
|
135
|
+
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function fromSecondChildNode(callback) {
|
|
144
|
+
let result;
|
|
145
|
+
|
|
146
|
+
const secondIndex = 1;
|
|
147
|
+
|
|
148
|
+
this.forwardsSomeChildNode((childNode, index) => {
|
|
149
|
+
if (index === secondIndex) {
|
|
150
|
+
const firstChildNode = childNode; ///
|
|
151
|
+
|
|
152
|
+
result = callback(firstChildNode);
|
|
153
|
+
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function fromThirdChildNode(callback) {
|
|
162
|
+
let result;
|
|
163
|
+
|
|
164
|
+
const thirdIndex = 2;
|
|
165
|
+
|
|
166
|
+
this.forwardsSomeChildNode((childNode, index) => {
|
|
167
|
+
if (index === thirdIndex) {
|
|
168
|
+
const thirdChildNode = childNode; ///
|
|
169
|
+
|
|
170
|
+
result = callback(thirdChildNode);
|
|
171
|
+
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function fromFirstLastChildNode(callback) {
|
|
180
|
+
let result;
|
|
181
|
+
|
|
182
|
+
const multiplicity = this.getMultiplicity(),
|
|
183
|
+
firstLastIndex = multiplicity - 1;
|
|
184
|
+
|
|
185
|
+
this.backwardsSomeChildNode((childNode, index) => {
|
|
186
|
+
if (index === firstLastIndex) {
|
|
187
|
+
const thirdChildNode = childNode; ///
|
|
188
|
+
|
|
189
|
+
result = callback(thirdChildNode);
|
|
190
|
+
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function fromSecondLastChildNode(callback) {
|
|
199
|
+
let result;
|
|
200
|
+
|
|
201
|
+
const multiplicity = this.getMultiplicity(),
|
|
202
|
+
secondLastIndex = multiplicity - 2;
|
|
203
|
+
|
|
204
|
+
this.backwardsSomeChildNode((childNode, index) => {
|
|
205
|
+
if (index === secondLastIndex) {
|
|
206
|
+
const thirdChildNode = childNode; ///
|
|
207
|
+
|
|
208
|
+
result = callback(thirdChildNode);
|
|
209
|
+
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
|
|
125
217
|
const nodeMixins = {
|
|
126
218
|
removeChildNodes,
|
|
127
219
|
removeChildNode,
|
|
@@ -132,7 +224,12 @@ const nodeMixins = {
|
|
|
132
224
|
addChildNodeAfter,
|
|
133
225
|
addChildNodesAfter,
|
|
134
226
|
getDescendantNodes,
|
|
135
|
-
retrieveParentNode
|
|
227
|
+
retrieveParentNode,
|
|
228
|
+
fromFirstChildNode,
|
|
229
|
+
fromSecondChildNode,
|
|
230
|
+
fromThirdChildNode,
|
|
231
|
+
fromFirstLastChildNode,
|
|
232
|
+
fromSecondLastChildNode
|
|
136
233
|
};
|
|
137
234
|
|
|
138
235
|
export default nodeMixins;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { arrayUtilities } from "necessary";
|
|
4
|
-
|
|
5
3
|
import MarkdownNode from "../../node/markdown";
|
|
6
4
|
|
|
7
|
-
const { first } = arrayUtilities;
|
|
8
|
-
|
|
9
5
|
export default class BlockListingMarkdownNode extends MarkdownNode {
|
|
10
6
|
asHTML(indent, context) {
|
|
11
7
|
const childNodesHTML = this.childNodesAsHTML(indent, context),
|
|
@@ -19,10 +15,12 @@ export default class BlockListingMarkdownNode extends MarkdownNode {
|
|
|
19
15
|
className(context) {
|
|
20
16
|
let className = super.className(context);
|
|
21
17
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
const blockListingStartMarkdownNodeClassName = this.fromFirstChildNode((firstChildNode) => {
|
|
19
|
+
const blockListingStartMarkdownNode = firstChildNode, ///
|
|
20
|
+
blockListingStartMarkdownNodeClassName = blockListingStartMarkdownNode.className(context);
|
|
21
|
+
|
|
22
|
+
return blockListingStartMarkdownNodeClassName;
|
|
23
|
+
});
|
|
26
24
|
|
|
27
25
|
if (blockListingStartMarkdownNodeClassName !== null) {
|
|
28
26
|
className = `${className} ${blockListingStartMarkdownNodeClassName}`;
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { arrayUtilities } from "necessary";
|
|
4
|
-
|
|
5
3
|
import MarkdownNode from "../../node/markdown";
|
|
6
4
|
import ClassNameMarkdownNode from "./className";
|
|
7
5
|
|
|
8
|
-
const { second } = arrayUtilities;
|
|
9
|
-
|
|
10
6
|
export default class BlockListingStartMarkdownNode extends MarkdownNode {
|
|
11
7
|
className(context) {
|
|
12
|
-
|
|
8
|
+
const className = this.fromSecondChildNode((secondChildNode) => {
|
|
9
|
+
let className = null;
|
|
10
|
+
|
|
11
|
+
const secondChildNodeClassNameMarkdownNode = (secondChildNode instanceof ClassNameMarkdownNode)
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
secondChildNodeClassNameMarkdownNode = (secondChildNode instanceof ClassNameMarkdownNode)
|
|
13
|
+
if (secondChildNodeClassNameMarkdownNode) {
|
|
14
|
+
const classNameMarkdownNode = secondChildNode; ///
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
className = classNameMarkdownNode.className(context);
|
|
17
|
+
}
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
}
|
|
19
|
+
return className;
|
|
20
|
+
});
|
|
23
21
|
|
|
24
22
|
return className;
|
|
25
23
|
}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { arrayUtilities } from "necessary";
|
|
4
|
-
|
|
5
3
|
import MarkdownNode from "../../node/markdown";
|
|
6
4
|
|
|
7
|
-
const { second } = arrayUtilities;
|
|
8
|
-
|
|
9
5
|
export default class ClassNameMarkdownNode extends MarkdownNode {
|
|
10
6
|
className(context) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
const className = this.fromSecondChildNode((secondChildNode) => {
|
|
8
|
+
const identifierTerminalNode = secondChildNode, ///
|
|
9
|
+
identifierTerminalNodeContent = identifierTerminalNode.getContent(),
|
|
10
|
+
className = identifierTerminalNodeContent; ///
|
|
11
|
+
|
|
12
|
+
return className;
|
|
13
|
+
});
|
|
16
14
|
|
|
17
15
|
return className;
|
|
18
16
|
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { arrayUtilities } from "necessary";
|
|
4
|
-
|
|
5
3
|
import MarkdownNode from "../../node/markdown";
|
|
6
4
|
|
|
7
|
-
const { first } = arrayUtilities;
|
|
8
|
-
|
|
9
5
|
export default class DirectivesMarkdownNode extends MarkdownNode {
|
|
10
6
|
asHTML(indent, context) {
|
|
11
7
|
const firstDirectiveMarkdownNode = this.getFirstDirectiveMarkdownNode(),
|
|
@@ -16,9 +12,11 @@ export default class DirectivesMarkdownNode extends MarkdownNode {
|
|
|
16
12
|
}
|
|
17
13
|
|
|
18
14
|
getFirstDirectiveMarkdownNode() {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
const firstDirectiveMarkdownNode = this.fromFirstChildNode((firstChildNode) => {
|
|
16
|
+
const firstDirectiveMarkdownNode = firstChildNode; ///
|
|
17
|
+
|
|
18
|
+
return firstDirectiveMarkdownNode;
|
|
19
|
+
});
|
|
22
20
|
|
|
23
21
|
return firstDirectiveMarkdownNode;
|
|
24
22
|
}
|
|
@@ -91,13 +91,12 @@ export default class DivisionMarkdownNode extends MarkdownNode {
|
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
const { linesPerPage } = context,
|
|
94
|
-
paginatedChildNodes = []
|
|
95
|
-
childNodes = this.getChildNodes();
|
|
94
|
+
paginatedChildNodes = [];
|
|
96
95
|
|
|
97
96
|
let { pageNumber } = context,
|
|
98
97
|
totalLines = 0;
|
|
99
98
|
|
|
100
|
-
|
|
99
|
+
this.forEachChildNode((childNode) => {
|
|
101
100
|
const lines = childNode.lines(context);
|
|
102
101
|
|
|
103
102
|
if ((totalLines + lines) > linesPerPage) {
|
|
@@ -1,47 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { arrayUtilities } from "necessary";
|
|
4
|
-
|
|
5
3
|
import MarkdownNode from "../../node/markdown";
|
|
6
4
|
import contentMixins from "../../mixins/content";
|
|
7
5
|
|
|
8
6
|
import { HREF_ATTRIBUTE_NAME } from "../../attributeNames";
|
|
9
7
|
|
|
10
|
-
const { first, second, secondLast } = arrayUtilities;
|
|
11
|
-
|
|
12
8
|
class EmailLinkMarkdownNode extends MarkdownNode {
|
|
13
9
|
inlineText(context) {
|
|
14
10
|
let inlineText = null;
|
|
15
11
|
|
|
16
|
-
const
|
|
17
|
-
childNodesLength = childNodes.length;
|
|
12
|
+
const multiplicity = this.getMultiplicity();
|
|
18
13
|
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
if (multiplicity > 1) {
|
|
15
|
+
inlineText = this.fromSecondChildNode((secondChildNode) => {
|
|
16
|
+
const indent = null,
|
|
17
|
+
inlineTextMarkdownNode = secondChildNode, ///
|
|
18
|
+
inlineTextMarkdownNodeHTML = inlineTextMarkdownNode.asHTML(indent, context);
|
|
24
19
|
|
|
25
|
-
|
|
20
|
+
inlineText = inlineTextMarkdownNodeHTML; ///
|
|
21
|
+
});
|
|
26
22
|
}
|
|
27
23
|
|
|
28
24
|
return inlineText;
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
emailAddress(context) {
|
|
32
|
-
const
|
|
33
|
-
childNodesLength = childNodes.length;
|
|
28
|
+
const multiplicity = this.getMultiplicity();
|
|
34
29
|
|
|
35
30
|
let emailAddressTerminalNode;
|
|
36
31
|
|
|
37
|
-
if (
|
|
38
|
-
|
|
32
|
+
if (multiplicity === 1) {
|
|
33
|
+
emailAddressTerminalNode = this.fromFirstChildNode((firstChildNode) => {
|
|
34
|
+
const emailAddressTerminalNode = firstChildNode; ///
|
|
39
35
|
|
|
40
|
-
|
|
36
|
+
return emailAddressTerminalNode;
|
|
37
|
+
});
|
|
41
38
|
} else {
|
|
42
|
-
|
|
39
|
+
emailAddressTerminalNode = this.fromSecondLastChildNode((secondLastChildNode) => {
|
|
40
|
+
const emailAddressTerminalNode = secondLastChildNode; ///
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
return emailAddressTerminalNode;
|
|
43
|
+
});
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
const emailAddressTerminalNodeContent = emailAddressTerminalNode.getContent(),
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { arrayUtilities } from "necessary";
|
|
4
|
-
|
|
5
3
|
import MarkdownNode from "../../node/markdown";
|
|
6
4
|
import contentMixins from "../../mixins/content";
|
|
7
5
|
|
|
8
|
-
const { second } = arrayUtilities;
|
|
9
|
-
|
|
10
6
|
class EmphasisedTextMarkdownNode extends MarkdownNode {
|
|
11
7
|
inlineText(context) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
const inlineText = this.fromSecondChildNode((secondChildNode) => {
|
|
9
|
+
const indent = null,
|
|
10
|
+
inlineTextMarkdownNode = secondChildNode, ///
|
|
11
|
+
inlineTextMarkdownNodeHTML = inlineTextMarkdownNode.asHTML(indent, context),
|
|
12
|
+
inlineText = inlineTextMarkdownNodeHTML; ///
|
|
13
|
+
|
|
14
|
+
return inlineText;
|
|
15
|
+
});
|
|
18
16
|
|
|
19
17
|
return inlineText;
|
|
20
18
|
}
|
|
@@ -16,10 +16,12 @@ export default class FootnoteMarkdownNode extends MarkdownNode {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
identifier(context) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
const identifier = this.fromFirstChildNode((firstChildNode) => {
|
|
20
|
+
const referenceMarkdownNode = firstChildNode, ///
|
|
21
|
+
identifier = referenceMarkdownNode.identifier(context);
|
|
22
|
+
|
|
23
|
+
return identifier;
|
|
24
|
+
});
|
|
23
25
|
|
|
24
26
|
return identifier;
|
|
25
27
|
}
|
|
@@ -34,10 +34,12 @@ export default class FootnoteLinkMarkdownNode extends MarkdownNode {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
identifier(context) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const identifier = this.fromFirstChildNode((firstChildNode) => {
|
|
38
|
+
const linkTerminalNode = firstChildNode, ///
|
|
39
|
+
identifier = identifierFromLinkTerminalNode(linkTerminalNode);
|
|
40
|
+
|
|
41
|
+
return identifier;
|
|
42
|
+
});
|
|
41
43
|
|
|
42
44
|
return identifier;
|
|
43
45
|
}
|
|
@@ -34,9 +34,11 @@ export default class HeadingMarkdownNode extends MarkdownNode {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
getLineMarkdownNode() {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const lineMarkdownNode = this.fromFirstLastChildNode((firstLastChildNode) => {
|
|
38
|
+
const lineMarkdownNode = firstLastChildNode; ///
|
|
39
|
+
|
|
40
|
+
return lineMarkdownNode;
|
|
41
|
+
});
|
|
40
42
|
|
|
41
43
|
return lineMarkdownNode;
|
|
42
44
|
}
|
|
@@ -7,23 +7,26 @@ import contentMixins from "../../mixins/content";
|
|
|
7
7
|
|
|
8
8
|
import { HREF_ATTRIBUTE_NAME } from "../../attributeNames";
|
|
9
9
|
|
|
10
|
-
const {
|
|
10
|
+
const { second } = arrayUtilities;
|
|
11
11
|
|
|
12
12
|
class HyperlinkLinkMarkdownNode extends MarkdownNode {
|
|
13
13
|
url(context) {
|
|
14
|
-
const
|
|
15
|
-
childNodesLength = childNodes.length;
|
|
14
|
+
const multiplicity = this.getMultiplicity();
|
|
16
15
|
|
|
17
16
|
let urlTerminalNode;
|
|
18
17
|
|
|
19
|
-
if (
|
|
20
|
-
|
|
18
|
+
if (multiplicity === 1) {
|
|
19
|
+
urlTerminalNode = this.fromFirstChildNode((firstChildNode) => {
|
|
20
|
+
const urlTerminalNode = firstChildNode; ///
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
return urlTerminalNode;
|
|
23
|
+
});
|
|
23
24
|
} else {
|
|
24
|
-
|
|
25
|
+
urlTerminalNode = this.fromSecondLastChildNode((secondLastChildNode) => {
|
|
26
|
+
const urlTerminalNode = secondLastChildNode; ///
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
return urlTerminalNode;
|
|
29
|
+
});
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
const urlTerminalNodeContent = urlTerminalNode.getContent(),
|
|
@@ -35,16 +38,16 @@ class HyperlinkLinkMarkdownNode extends MarkdownNode {
|
|
|
35
38
|
inlineText(context) {
|
|
36
39
|
let inlineText = null;
|
|
37
40
|
|
|
38
|
-
const
|
|
39
|
-
childNodesLength = childNodes.length;
|
|
41
|
+
const multiplicity = this.getMultiplicity();
|
|
40
42
|
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (multiplicity > 1) {
|
|
44
|
+
inlineText = this.fromSecondChildNode((secondChildNode) => {
|
|
45
|
+
const indent = null,
|
|
46
|
+
inlineTextMarkdownNode = secondChildNode, ///
|
|
47
|
+
inlineTextMarkdownNodeHTML = inlineTextMarkdownNode.asHTML(indent, context);
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
inlineText = inlineTextMarkdownNodeHTML; ///
|
|
50
|
+
});
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
return inlineText;
|
|
@@ -6,15 +6,17 @@ import MarkdownNode from "../../node/markdown";
|
|
|
6
6
|
|
|
7
7
|
import { ALT_ATTRIBUTE_NAME, SRC_ATTRIBUTE_NAME} from "../../attributeNames";
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const { secondLast } = arrayUtilities;
|
|
10
10
|
|
|
11
11
|
export default class ImageMarkdownNode extends MarkdownNode {
|
|
12
12
|
alt(context) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const alt = this.fromSecondChildNode((secondChildNode) => {
|
|
14
|
+
const inlineTextMarkdownNode = secondChildNode, ///
|
|
15
|
+
inlineTextMarkdownNodeContent = inlineTextMarkdownNode.content(context),
|
|
16
|
+
alt = inlineTextMarkdownNodeContent; ///
|
|
17
|
+
|
|
18
|
+
return alt;
|
|
19
|
+
});
|
|
18
20
|
|
|
19
21
|
return alt;
|
|
20
22
|
}
|
package/src/node/markdown.js
CHANGED
|
@@ -116,9 +116,7 @@ class MarkdownNode extends NonTerminalNode {
|
|
|
116
116
|
({ lines = null } = this.constructor);
|
|
117
117
|
|
|
118
118
|
if (lines === null) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
lines = childNodes.reduce((lines, childNode) => {
|
|
119
|
+
lines = this.reduceChildNode((lines, childNode) => {
|
|
122
120
|
const childNodeMarkdownNode = (childNode instanceof MarkdownNode);
|
|
123
121
|
|
|
124
122
|
if (childNodeMarkdownNode) {
|
|
@@ -256,8 +254,7 @@ ${childNodesHTML}${indent}${closingTag}
|
|
|
256
254
|
}
|
|
257
255
|
|
|
258
256
|
childNodesAsHTML(indent, context) {
|
|
259
|
-
const
|
|
260
|
-
childNodesHTML = childNodes.reduce((childNodesHTML, childNode) => {
|
|
257
|
+
const childNodesHTML = this.reduceChildNode((childNodesHTML, childNode) => {
|
|
261
258
|
const childNodeMarkdownNode = (childNode instanceof MarkdownNode);
|
|
262
259
|
|
|
263
260
|
if (childNodeMarkdownNode) {
|
|
@@ -278,8 +275,7 @@ ${childNodesHTML}${indent}${closingTag}
|
|
|
278
275
|
}
|
|
279
276
|
|
|
280
277
|
childNodesAsPlainText(context) {
|
|
281
|
-
const
|
|
282
|
-
childNodesPlainText = childNodes.reduce((childNodesPlainText, childNode) => {
|
|
278
|
+
const childNodesPlainText = this.reduceChildNode((childNodesPlainText, childNode) => {
|
|
283
279
|
const childNodeMarkdownNode = (childNode instanceof MarkdownNode);
|
|
284
280
|
|
|
285
281
|
if (childNodeMarkdownNode) {
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export function fromFirstChildNode(nonTerminalNode, callback) {
|
|
4
|
+
let result;
|
|
5
|
+
|
|
6
|
+
const firstIndex = 0;
|
|
7
|
+
|
|
8
|
+
nonTerminalNode.forwardsSomeChildNode((childNode, index) => {
|
|
9
|
+
if (index === firstIndex) {
|
|
10
|
+
const firstChildNode = childNode; ///
|
|
11
|
+
|
|
12
|
+
result = callback(firstChildNode);
|
|
13
|
+
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function fromSecondChildNode(nonTerminalNode, callback) {
|
|
22
|
+
let result;
|
|
23
|
+
|
|
24
|
+
const secondIndex = 1;
|
|
25
|
+
|
|
26
|
+
nonTerminalNode.forwardsSomeChildNode((childNode, index) => {
|
|
27
|
+
if (index === secondIndex) {
|
|
28
|
+
const firstChildNode = childNode; ///
|
|
29
|
+
|
|
30
|
+
result = callback(firstChildNode);
|
|
31
|
+
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function fromThirdChildNode(nonTerminalNode, callback) {
|
|
40
|
+
let result;
|
|
41
|
+
|
|
42
|
+
const thirdIndex = 2;
|
|
43
|
+
|
|
44
|
+
nonTerminalNode.forwardsSomeChildNode((childNode, index) => {
|
|
45
|
+
if (index === thirdIndex) {
|
|
46
|
+
const thirdChildNode = childNode; ///
|
|
47
|
+
|
|
48
|
+
result = callback(thirdChildNode);
|
|
49
|
+
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function fromFirstLastChildNode(nonTerminalNode, callback) {
|
|
58
|
+
let result;
|
|
59
|
+
|
|
60
|
+
const multiplicity = nonTerminalNode.getMultiplicity(),
|
|
61
|
+
firstLastIndex = multiplicity - 1;
|
|
62
|
+
|
|
63
|
+
nonTerminalNode.backwardsSomeChildNode((childNode, index) => {
|
|
64
|
+
if (index === firstLastIndex) {
|
|
65
|
+
const thirdChildNode = childNode; ///
|
|
66
|
+
|
|
67
|
+
result = callback(thirdChildNode);
|
|
68
|
+
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function fromSecondLastChildNode(nonTerminalNode, callback) {
|
|
77
|
+
let result;
|
|
78
|
+
|
|
79
|
+
const multiplicity = nonTerminalNode.getMultiplicity(),
|
|
80
|
+
secondLastIndex = multiplicity - 2;
|
|
81
|
+
|
|
82
|
+
nonTerminalNode.backwardsSomeChildNode((childNode, index) => {
|
|
83
|
+
if (index === secondLastIndex) {
|
|
84
|
+
const thirdChildNode = childNode; ///
|
|
85
|
+
|
|
86
|
+
result = callback(thirdChildNode);
|
|
87
|
+
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return result;
|
|
93
|
+
}
|