highmark-markdown 0.0.334 → 0.0.336
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 +128 -100
- package/lib/example/view.js +2 -2
- package/lib/markdown/bnf.js +2 -2
- package/lib/mixins/content.js +2 -5
- package/lib/node/markdown/blockLine.js +23 -5
- package/lib/node/markdown/directive/contents.js +1 -15
- package/lib/node/markdown/directive/footnotes.js +2 -17
- package/lib/node/markdown/error.js +1 -1
- package/lib/node/markdown/heading.js +18 -2
- package/lib/node/markdown/line.js +23 -5
- package/lib/node/markdown/verticalSpace.js +3 -3
- package/lib/utilities/childNodes.js +37 -46
- package/lib/utilities/content.js +23 -8
- package/package.json +1 -1
- package/src/example/view.js +3 -1
- package/src/markdown/bnf.js +3 -3
- package/src/mixins/content.js +4 -7
- package/src/node/markdown/blockLine.js +32 -4
- package/src/node/markdown/directive/contents.js +0 -12
- package/src/node/markdown/directive/footnotes.js +0 -12
- package/src/node/markdown/error.js +2 -2
- package/src/node/markdown/heading.js +25 -2
- package/src/node/markdown/line.js +32 -4
- package/src/node/markdown/verticalSpace.js +3 -3
- package/src/utilities/childNodes.js +45 -57
- package/src/utilities/content.js +35 -14
|
@@ -4,14 +4,12 @@ import { arrayUtilities } from "necessary";
|
|
|
4
4
|
|
|
5
5
|
import PlainTextMarkdownNode from "../node/markdown/plainText";
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { EMPTY_STRING } from "../constants";
|
|
8
|
+
import { contentFromNodes } from "./content";
|
|
9
9
|
|
|
10
|
-
const { push, clear } = arrayUtilities;
|
|
11
|
-
|
|
12
|
-
export function htmlFromChildNodes(childNodes, context, leftTrimmed) {
|
|
13
|
-
let html;
|
|
10
|
+
const { first, last, push, clear } = arrayUtilities;
|
|
14
11
|
|
|
12
|
+
export function htmlFromChildNodes(childNodes, context) {
|
|
15
13
|
const htmls = [],
|
|
16
14
|
plainTextMarkdownNodes = [];
|
|
17
15
|
|
|
@@ -28,10 +26,10 @@ export function htmlFromChildNodes(childNodes, context, leftTrimmed) {
|
|
|
28
26
|
|
|
29
27
|
plainTextMarkdownNodes.push(plainTextMarkdownNode);
|
|
30
28
|
} else {
|
|
31
|
-
const
|
|
29
|
+
const content = contentFromPlainTextMarkdownNodes(plainTextMarkdownNodes, childNodes, context);
|
|
32
30
|
|
|
33
|
-
if (
|
|
34
|
-
const html =
|
|
31
|
+
if (content !== null) {
|
|
32
|
+
const html = content; ///
|
|
35
33
|
|
|
36
34
|
htmls.push(html);
|
|
37
35
|
}
|
|
@@ -44,26 +42,22 @@ export function htmlFromChildNodes(childNodes, context, leftTrimmed) {
|
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
|
-
|
|
48
|
-
leftTrimmed = false;
|
|
49
45
|
});
|
|
50
46
|
|
|
51
|
-
const
|
|
47
|
+
const content = contentFromPlainTextMarkdownNodes(plainTextMarkdownNodes, childNodes, context);
|
|
52
48
|
|
|
53
|
-
if (
|
|
54
|
-
const html =
|
|
49
|
+
if (content !== null) {
|
|
50
|
+
const html = content; ///
|
|
55
51
|
|
|
56
52
|
htmls.push(html);
|
|
57
53
|
}
|
|
58
54
|
|
|
59
|
-
html = htmls.join(EMPTY_STRING);
|
|
55
|
+
const html = htmls.join(EMPTY_STRING);
|
|
60
56
|
|
|
61
57
|
return html;
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
export function plainTextFromChildNodes(childNodes, context
|
|
65
|
-
let plainText;
|
|
66
|
-
|
|
60
|
+
export function plainTextFromChildNodes(childNodes, context) {
|
|
67
61
|
const plainTexts = [],
|
|
68
62
|
plainTextMarkdownNodes = [];
|
|
69
63
|
|
|
@@ -80,37 +74,38 @@ export function plainTextFromChildNodes(childNodes, context, leftTrimmed) {
|
|
|
80
74
|
|
|
81
75
|
plainTextMarkdownNodes.push(plainTextMarkdownNode);
|
|
82
76
|
} else {
|
|
83
|
-
|
|
77
|
+
const content = contentFromPlainTextMarkdownNodes(plainTextMarkdownNodes, childNodes, context);
|
|
78
|
+
|
|
79
|
+
if (content !== null) {
|
|
80
|
+
const plainText = content; ///
|
|
84
81
|
|
|
85
|
-
if (plainText !== null) {
|
|
86
82
|
plainTexts.push(plainText);
|
|
87
83
|
}
|
|
88
84
|
|
|
89
|
-
const childNodes = markdownNode.getChildNodes()
|
|
90
|
-
|
|
91
|
-
plainText = plainTextFromChildNodes(childNodes, context, leftTrimmed);
|
|
85
|
+
const childNodes = markdownNode.getChildNodes(),
|
|
86
|
+
plainText = plainTextFromChildNodes(childNodes, context);
|
|
92
87
|
|
|
93
88
|
if (plainText !== EMPTY_STRING) {
|
|
94
89
|
plainTexts.push(plainText);
|
|
95
90
|
}
|
|
96
91
|
}
|
|
97
92
|
}
|
|
98
|
-
|
|
99
|
-
leftTrimmed = false;
|
|
100
93
|
});
|
|
101
94
|
|
|
102
|
-
|
|
95
|
+
const content = contentFromPlainTextMarkdownNodes(plainTextMarkdownNodes, childNodes, context);
|
|
96
|
+
|
|
97
|
+
if (content !== null) {
|
|
98
|
+
const plainText = content; ///
|
|
103
99
|
|
|
104
|
-
if (plainText !== null) {
|
|
105
100
|
plainTexts.push(plainText);
|
|
106
101
|
}
|
|
107
102
|
|
|
108
|
-
plainText = plainTexts.join(EMPTY_STRING);
|
|
103
|
+
const plainText = plainTexts.join(EMPTY_STRING);
|
|
109
104
|
|
|
110
105
|
return plainText;
|
|
111
106
|
}
|
|
112
107
|
|
|
113
|
-
export function domElementsFromChildNodes(childNodes, context
|
|
108
|
+
export function domElementsFromChildNodes(childNodes, context) {
|
|
114
109
|
const domElements = [],
|
|
115
110
|
plainTextMarkdownNodes = [];
|
|
116
111
|
|
|
@@ -127,11 +122,10 @@ export function domElementsFromChildNodes(childNodes, context, leftTrimmed) {
|
|
|
127
122
|
|
|
128
123
|
plainTextMarkdownNodes.push(plainTextMarkdownNode);
|
|
129
124
|
} else {
|
|
130
|
-
const
|
|
125
|
+
const content = contentFromPlainTextMarkdownNodes(plainTextMarkdownNodes, childNodes, context);
|
|
131
126
|
|
|
132
|
-
if (
|
|
133
|
-
const
|
|
134
|
-
textNode = document.createTextNode(content),
|
|
127
|
+
if (content !== null) {
|
|
128
|
+
const textNode = document.createTextNode(content),
|
|
135
129
|
domElement = textNode; ///
|
|
136
130
|
|
|
137
131
|
domElements.push(domElement);
|
|
@@ -144,25 +138,12 @@ export function domElementsFromChildNodes(childNodes, context, leftTrimmed) {
|
|
|
144
138
|
push(domElements, markdownNodeDOMElements);
|
|
145
139
|
}
|
|
146
140
|
}
|
|
147
|
-
|
|
148
|
-
leftTrimmed = false;
|
|
149
141
|
});
|
|
150
142
|
|
|
151
|
-
const
|
|
143
|
+
const content = contentFromPlainTextMarkdownNodes(plainTextMarkdownNodes, childNodes, context);
|
|
152
144
|
|
|
153
|
-
if (
|
|
154
|
-
const
|
|
155
|
-
textNode = document.createTextNode(content),
|
|
156
|
-
domElement = textNode; ///
|
|
157
|
-
|
|
158
|
-
domElements.push(domElement);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const domElementsLength = domElements.length;
|
|
162
|
-
|
|
163
|
-
if (domElementsLength === 0) {
|
|
164
|
-
const content = CARRIAGE_RETURN, ///
|
|
165
|
-
textNode = document.createTextNode(content),
|
|
145
|
+
if (content !== null) {
|
|
146
|
+
const textNode = document.createTextNode(content),
|
|
166
147
|
domElement = textNode; ///
|
|
167
148
|
|
|
168
149
|
domElements.push(domElement);
|
|
@@ -171,20 +152,27 @@ export function domElementsFromChildNodes(childNodes, context, leftTrimmed) {
|
|
|
171
152
|
return domElements;
|
|
172
153
|
}
|
|
173
154
|
|
|
174
|
-
function
|
|
175
|
-
let
|
|
155
|
+
function contentFromPlainTextMarkdownNodes(plainTextMarkdownNodes, childNodes, context) {
|
|
156
|
+
let content = null;
|
|
176
157
|
|
|
177
158
|
const plainTextMarkdownNodesLength = plainTextMarkdownNodes.length;
|
|
178
159
|
|
|
179
160
|
if (plainTextMarkdownNodesLength > 0) {
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
161
|
+
const nodes = plainTextMarkdownNodes, ///
|
|
162
|
+
lastNode = last(nodes),
|
|
163
|
+
firstNode = first(nodes),
|
|
164
|
+
lastNodeIndex = childNodes.indexOf(lastNode),
|
|
165
|
+
firstNodeIndex = childNodes.indexOf(firstNode),
|
|
166
|
+
childNodesLength = childNodes.length,
|
|
167
|
+
lastChildNodeIndex = childNodesLength - 1,
|
|
168
|
+
firstChildNodeIndex = 0,
|
|
169
|
+
augmentLeft = (firstNodeIndex !== firstChildNodeIndex),
|
|
170
|
+
augmentRight = (lastNodeIndex !== lastChildNodeIndex); ///
|
|
171
|
+
|
|
172
|
+
content = contentFromNodes(nodes, augmentLeft, augmentRight, context);
|
|
185
173
|
|
|
186
174
|
clear(plainTextMarkdownNodes);
|
|
187
175
|
}
|
|
188
176
|
|
|
189
|
-
return
|
|
177
|
+
return content;
|
|
190
178
|
}
|
package/src/utilities/content.js
CHANGED
|
@@ -7,25 +7,46 @@ import { ESCAPED_TOKEN_TYPE } from "../tokenTypes";
|
|
|
7
7
|
|
|
8
8
|
const { first, last } = arrayUtilities;
|
|
9
9
|
|
|
10
|
-
export function
|
|
10
|
+
export function contentFromNode(node, context) {
|
|
11
11
|
let content = EMPTY_STRING;
|
|
12
12
|
|
|
13
13
|
let { tokens } = context;
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const lastSignificantToken = node.getLastSignificantToken(),
|
|
16
|
+
firstSignificantToken = node.getFirstSignificantToken(),
|
|
17
|
+
lastSignificantTokenIndex = tokens.indexOf(lastSignificantToken),
|
|
18
|
+
firstSignificantTokenIndex = tokens.indexOf(firstSignificantToken);
|
|
19
|
+
|
|
20
|
+
const start = firstSignificantTokenIndex, ///
|
|
21
|
+
end = lastSignificantTokenIndex + 1;
|
|
22
|
+
|
|
23
|
+
tokens = tokens.slice(start, end);
|
|
24
|
+
|
|
25
|
+
tokens.forEach((token) => {
|
|
26
|
+
const tokenContent = tokenContentFromToken(token);
|
|
27
|
+
|
|
28
|
+
content += tokenContent;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return content;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function contentFromNodes(nodes, augmentLeft, augmentRight, context) {
|
|
35
|
+
let content = EMPTY_STRING;
|
|
36
|
+
|
|
37
|
+
let { tokens } = context;
|
|
38
|
+
|
|
39
|
+
const lastNode = last(nodes),
|
|
40
|
+
firstNode = first(nodes),
|
|
41
|
+
lastSignificantToken = lastNode.getLastSignificantToken(),
|
|
42
|
+
firstSignificantToken = firstNode.getFirstSignificantToken(),
|
|
43
|
+
lastSignificantTokenIndex = tokens.indexOf(lastSignificantToken),
|
|
44
|
+
firstSignificantTokenIndex = tokens.indexOf(firstSignificantToken);
|
|
24
45
|
|
|
25
46
|
let firstTokenIndex = firstSignificantTokenIndex, ///
|
|
26
47
|
lastTokenIndex = lastSignificantTokenIndex; ///
|
|
27
48
|
|
|
28
|
-
if (
|
|
49
|
+
if (augmentLeft) {
|
|
29
50
|
const previousTokenIndex = firstTokenIndex - 1;
|
|
30
51
|
|
|
31
52
|
if (previousTokenIndex > -1) {
|
|
@@ -38,7 +59,7 @@ export function contentFromMarkdownNodes(markdownNodes, context, leftTrimmed, ri
|
|
|
38
59
|
}
|
|
39
60
|
}
|
|
40
61
|
|
|
41
|
-
if (
|
|
62
|
+
if (augmentRight) {
|
|
42
63
|
const tokensLength = tokens.length,
|
|
43
64
|
nextTokenIndex = lastTokenIndex + 1;
|
|
44
65
|
|
|
@@ -68,6 +89,8 @@ export function contentFromMarkdownNodes(markdownNodes, context, leftTrimmed, ri
|
|
|
68
89
|
}
|
|
69
90
|
|
|
70
91
|
export function contentFromNodeAndTokens(node, tokens, offset = 0) {
|
|
92
|
+
let content = EMPTY_STRING;
|
|
93
|
+
|
|
71
94
|
const firstSignificantToken = node.getFirstSignificantToken(),
|
|
72
95
|
lastSignificantToken = node.getLastSignificantToken(),
|
|
73
96
|
firstToken = firstSignificantToken, ///
|
|
@@ -75,8 +98,6 @@ export function contentFromNodeAndTokens(node, tokens, offset = 0) {
|
|
|
75
98
|
firstTokenIndex = tokens.indexOf(firstToken) + offset, ///
|
|
76
99
|
lastTokenIndex = tokens.indexOf(lastToken);
|
|
77
100
|
|
|
78
|
-
let content = EMPTY_STRING;
|
|
79
|
-
|
|
80
101
|
for (let index = firstTokenIndex; index <= lastTokenIndex; index++) {
|
|
81
102
|
const token = tokens[index],
|
|
82
103
|
tokenContent = token.getContent();
|