highmark-markdown 0.0.426 → 0.0.430

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.
Files changed (102) hide show
  1. package/example.js +4002 -1871
  2. package/lib/constants.js +17 -1
  3. package/lib/defaultMarkdownStyle.js +2 -2
  4. package/lib/elementMap.js +20 -5
  5. package/lib/example/importer.js +5 -5
  6. package/lib/example/indexOptions.js +143 -0
  7. package/lib/example/view/div/sizeable/right.js +2 -2
  8. package/lib/example/view.js +14 -2
  9. package/lib/example.js +3 -3
  10. package/lib/index/phraseMatcher.js +76 -0
  11. package/lib/markdown/bnf.js +2 -2
  12. package/lib/markdown/lexer.js +11 -11
  13. package/lib/markdown/parser.js +12 -12
  14. package/lib/node/markdown/anchor.js +15 -8
  15. package/lib/node/markdown/comma.js +144 -0
  16. package/lib/node/markdown/contentsLink.js +3 -2
  17. package/lib/node/markdown/contentsList.js +10 -2
  18. package/lib/node/markdown/directive/index.js +120 -0
  19. package/lib/node/markdown/directive.js +10 -2
  20. package/lib/node/markdown/division.js +49 -9
  21. package/lib/node/markdown/{link.js → footnoteLink.js} +14 -13
  22. package/lib/node/markdown/footnotesItem.js +5 -12
  23. package/lib/node/markdown/heading.js +10 -2
  24. package/lib/node/markdown/indexItem.js +120 -0
  25. package/lib/node/markdown/indexLink.js +168 -0
  26. package/lib/node/markdown/indexList.js +138 -0
  27. package/lib/node/markdown/line.js +16 -2
  28. package/lib/node/markdown/subDivision.js +21 -2
  29. package/lib/node/markdown/verticalSpace.js +12 -1
  30. package/lib/node/markdown.js +32 -2
  31. package/lib/nodeMap.js +8 -3
  32. package/lib/prepends.js +26 -0
  33. package/lib/replacement/contentsList.js +3 -2
  34. package/lib/replacement/footnotesList.js +8 -8
  35. package/lib/replacement/indexItem.js +131 -0
  36. package/lib/replacement/indexList.js +166 -0
  37. package/lib/replacement/subDivision/footnotesDirective.js +2 -33
  38. package/lib/replacement/subDivision/indexAnchor.js +124 -0
  39. package/lib/replacement/subDivision/indexDirective.js +126 -0
  40. package/lib/replacement/subDivision/pageNumberDirective.js +2 -33
  41. package/lib/replacement/subDivision.js +15 -1
  42. package/lib/replacement.js +22 -45
  43. package/lib/ruleNames.js +31 -6
  44. package/lib/styleElement/markdown/default.js +4 -4
  45. package/lib/styleElement/markdown.js +3 -3
  46. package/lib/utilities/footnotes.js +10 -10
  47. package/lib/utilities/index.js +246 -0
  48. package/lib/utilities/object.js +59 -0
  49. package/lib/utilities/processing.js +10 -1
  50. package/lib/utilities/query.js +26 -18
  51. package/lib/utilities/replacement.js +67 -1
  52. package/package.json +3 -3
  53. package/src/constants.js +4 -0
  54. package/src/defaultMarkdownStyle.js +13 -1
  55. package/src/elementMap.js +30 -5
  56. package/src/example/importer.js +21 -5
  57. package/src/example/indexOptions.js +134 -0
  58. package/src/example/view/div/sizeable/right.js +1 -1
  59. package/src/example/view.js +20 -1
  60. package/src/example.js +2 -2
  61. package/src/index/phraseMatcher.js +38 -0
  62. package/src/markdown/bnf.js +21 -5
  63. package/src/markdown/lexer.js +10 -10
  64. package/src/markdown/parser.js +12 -12
  65. package/src/node/markdown/anchor.js +11 -6
  66. package/src/node/markdown/comma.js +32 -0
  67. package/src/node/markdown/contentsLink.js +3 -1
  68. package/src/node/markdown/contentsList.js +6 -0
  69. package/src/node/markdown/directive/index.js +7 -0
  70. package/src/node/markdown/directive.js +6 -0
  71. package/src/node/markdown/division.js +60 -9
  72. package/src/node/markdown/{link.js → footnoteLink.js} +7 -5
  73. package/src/node/markdown/footnotesItem.js +4 -11
  74. package/src/node/markdown/heading.js +11 -2
  75. package/src/node/markdown/indexItem.js +7 -0
  76. package/src/node/markdown/indexLink.js +63 -0
  77. package/src/node/markdown/indexList.js +34 -0
  78. package/src/node/markdown/line.js +15 -2
  79. package/src/node/markdown/subDivision.js +25 -2
  80. package/src/node/markdown/verticalSpace.js +15 -0
  81. package/src/node/markdown.js +44 -2
  82. package/src/nodeMap.js +18 -3
  83. package/src/prepends.js +5 -0
  84. package/src/replacement/contentsList.js +3 -1
  85. package/src/replacement/footnotesList.js +9 -7
  86. package/src/replacement/indexItem.js +28 -0
  87. package/src/replacement/indexList.js +45 -0
  88. package/src/replacement/subDivision/footnotesDirective.js +0 -6
  89. package/src/replacement/subDivision/indexAnchor.js +20 -0
  90. package/src/replacement/subDivision/indexDirective.js +20 -0
  91. package/src/replacement/subDivision/pageNumberDirective.js +0 -6
  92. package/src/replacement/subDivision.js +12 -0
  93. package/src/replacement.js +41 -68
  94. package/src/ruleNames.js +12 -2
  95. package/src/styleElement/markdown/default.js +2 -2
  96. package/src/styleElement/markdown.js +1 -1
  97. package/src/utilities/footnotes.js +8 -8
  98. package/src/utilities/index.js +335 -0
  99. package/src/utilities/object.js +50 -0
  100. package/src/utilities/processing.js +12 -0
  101. package/src/utilities/query.js +21 -13
  102. package/src/utilities/replacement.js +81 -0
@@ -0,0 +1,335 @@
1
+ "use strict";
2
+
3
+ import { arrayUtilities } from "necessary";
4
+
5
+ import PhraseMatcher from "../index/phraseMatcher";
6
+
7
+ import { EMPTY_STRING, SINGLE_SPACE } from "../constants";
8
+ import { forEach, mapValues, mapKeys } from "../utilities/object";
9
+
10
+ const { compress } = arrayUtilities;
11
+
12
+ export function indexMapFromDivisionMarkdownNodes(divisionMarkdownNodes, context) {
13
+ const indexMap = createIndexMap(divisionMarkdownNodes, context);
14
+
15
+ removeIgnoredWords(indexMap, context);
16
+
17
+ adjustProperNouns(indexMap, context);
18
+
19
+ adjustAcronyms(indexMap, context);
20
+
21
+ adjustMixedPlurals(indexMap, context);
22
+
23
+ adjustPluralPlurals(indexMap, context);
24
+
25
+ adjustSingularPlurals(indexMap, context);
26
+
27
+ compressPageNumbers(indexMap);
28
+
29
+ return indexMap;
30
+ }
31
+
32
+ function createIndexMap(divisionMarkdownNodes, context) {
33
+ const indexMap = {};
34
+
35
+ const { indexOptions } = context,
36
+ { phrases } = indexOptions,
37
+ phraseMatchers = phrases.map((phrase) => {
38
+ const phraseMatcher = PhraseMatcher.fromPhrase(phrase);
39
+
40
+ return phraseMatcher;
41
+ });
42
+
43
+ divisionMarkdownNodes.forEach((divisionMarkdownNode) => {
44
+ const pageNumber = divisionMarkdownNode.getPageNumber();
45
+
46
+ if (pageNumber !== null) {
47
+ const plainText = divisionMarkdownNode.asPlainText(context),
48
+ entries = entriesFromPlainTextAndPhraseMatchers(plainText, phraseMatchers);
49
+
50
+ entries.forEach((entry) => {
51
+ let pageNumbers = indexMap[entry] || null;
52
+
53
+ if (pageNumbers === null) {
54
+ pageNumbers = [];
55
+
56
+ indexMap[entry] = pageNumbers;
57
+ }
58
+
59
+ pageNumbers.push(pageNumber);
60
+ });
61
+ }
62
+ });
63
+
64
+ return indexMap;
65
+ }
66
+
67
+ function entriesFromPlainTextAndPhraseMatchers(plainText, phraseMatchers) {
68
+ let entries;
69
+
70
+ plainText = preparePlainText(plainText); ///
71
+
72
+ phraseMatchers.forEach((phraseMatcher) => {
73
+ plainText = phraseMatcher.replace(plainText);
74
+ });
75
+
76
+ entries = plainText.split(SINGLE_SPACE);
77
+
78
+ entries = entries.map((entry) => {
79
+ entry = PhraseMatcher.revert(entry); ///
80
+
81
+ return entry;
82
+ });
83
+
84
+ return entries;
85
+ }
86
+
87
+ function compressPageNumbers(indexMap) {
88
+ mapValues(indexMap, (entry, pageNumbers) => {
89
+ compress(pageNumbers, (pageNumberA, pageNumberB) => {
90
+ if (pageNumberA === pageNumberB) {
91
+ return true;
92
+ }
93
+ });
94
+
95
+ pageNumbers.sort();
96
+
97
+ return pageNumbers;
98
+ });
99
+ }
100
+
101
+ function removeIgnoredWords(indexMap, context) {
102
+ const { indexOptions } = context,
103
+ { ignoredWords } = indexOptions;
104
+
105
+ ignoredWords.forEach((ignoredWord) => {
106
+ delete indexMap[ignoredWord];
107
+ });
108
+ }
109
+
110
+ function adjustProperNouns(indexMap, context) {
111
+ const { indexOptions } = context,
112
+ { properNouns } = indexOptions;
113
+
114
+ const lowerCaseProperNouns = properNouns.map((properNoun) => {
115
+ const lowerCaseProperNoun = properNoun.toLowerCase();
116
+
117
+ return lowerCaseProperNoun;
118
+ });
119
+
120
+ mapKeys(indexMap, (entry) => {
121
+ const index = lowerCaseProperNouns.findIndex((lowerCaseProperNmae) => {
122
+ if (lowerCaseProperNmae === entry) {
123
+ return true;
124
+ }
125
+ });
126
+
127
+ if (index > -1) {
128
+ const properNoun = properNouns[index];
129
+
130
+ entry = properNoun; ///
131
+ }
132
+
133
+ return entry;
134
+ });
135
+ }
136
+
137
+ function preparePlainText(plainText) {
138
+ plainText = plainText.toLowerCase(); ///
139
+
140
+ plainText = plainText.replace(/[^a-z ]/g, SINGLE_SPACE);
141
+
142
+ plainText = plainText.replace(/\s+/g, SINGLE_SPACE);
143
+
144
+ plainText = plainText.replace(/^\s+|\s+$/g, EMPTY_STRING);
145
+
146
+ return plainText;
147
+ }
148
+
149
+ function adjustAcronyms(indexMap, context) {
150
+ const { indexOptions } = context,
151
+ { acronyms } = indexOptions;
152
+
153
+ const lowerCaseAcronyms = acronyms.map((acronym) => {
154
+ const lowerCaseAcronym = acronym.toLowerCase();
155
+
156
+ return lowerCaseAcronym;
157
+ });
158
+
159
+ mapKeys(indexMap, (entry) => {
160
+ const index = lowerCaseAcronyms.findIndex((lowerCaseProperNmae) => {
161
+ if (lowerCaseProperNmae === entry) {
162
+ return true;
163
+ }
164
+ });
165
+
166
+ if (index > -1) {
167
+ const acronym = acronyms[index];
168
+
169
+ entry = acronym; ///
170
+ }
171
+
172
+ return entry;
173
+ });
174
+ }
175
+
176
+ function adjustMixedPlurals(indexMap, context) {
177
+ const { indexOptions } = context,
178
+ { plurals } = indexOptions,
179
+ mixedPlurals = mixedPluralsFromPlurals(plurals);
180
+
181
+ forEach(indexMap, (entry, pageNumbers) => {
182
+ const entryPlural = isPlural(entry);
183
+
184
+ if (entryPlural) {
185
+ const singularEntry = entry.replace(/s$/, EMPTY_STRING),
186
+ mixedEntry = `${singularEntry}(s)`,
187
+ mixedPluralsIncludesMixedEntry = mixedPlurals.includes(mixedEntry),
188
+ entryMixedPlural = mixedPluralsIncludesMixedEntry; ///
189
+
190
+ if (entryMixedPlural) {
191
+ const pluralPageNumbers = pageNumbers, ///
192
+ singularPageNumbers = indexMap[singularEntry] || [];
193
+
194
+ pageNumbers = [ ///
195
+ ...pluralPageNumbers,
196
+ ...singularPageNumbers
197
+ ];
198
+
199
+ delete indexMap[entry];
200
+ delete indexMap[singularEntry];
201
+
202
+ indexMap[mixedEntry] = pageNumbers;
203
+ }
204
+ }
205
+ });
206
+ }
207
+
208
+ function adjustPluralPlurals(indexMap, context) {
209
+ const { indexOptions } = context,
210
+ { plurals } = indexOptions,
211
+ pluralPlurals = pluralPluralsFromPlurals(plurals);
212
+
213
+ forEach(indexMap, (entry, pageNumbers) => {
214
+ const entryPlural = isPlural(entry);
215
+
216
+ if (entryPlural) {
217
+ const singularEntry = entry.replace(/s$/, EMPTY_STRING),
218
+ pluralPluralsIncludesEntry = pluralPlurals.includes(entry),
219
+ entryPluralPlural = pluralPluralsIncludesEntry; ///
220
+
221
+ if (entryPluralPlural) {
222
+ const pluralPageNumbers = pageNumbers, ///
223
+ singularPageNumbers = indexMap[singularEntry] || [];
224
+
225
+ pageNumbers = [ ///
226
+ ...pluralPageNumbers,
227
+ ...singularPageNumbers
228
+ ];
229
+
230
+ delete indexMap[singularEntry];
231
+
232
+ indexMap[entry] = pageNumbers;
233
+ }
234
+ }
235
+ });
236
+ }
237
+
238
+ function adjustSingularPlurals(indexMap, context) {
239
+ const { indexOptions } = context,
240
+ { plurals } = indexOptions,
241
+ singularPlurals = singularPluralsFromPlurals(plurals);
242
+
243
+ forEach(indexMap, (entry, pageNumbers) => {
244
+ const entryPlural = isPlural(entry);
245
+
246
+ if (entryPlural) {
247
+ const singularEntry = entry.replace(/s$/, EMPTY_STRING),
248
+ singularPluralsIncludesSingularEntry = singularPlurals.includes(singularEntry),
249
+ entrySingularPlural = singularPluralsIncludesSingularEntry; ///
250
+
251
+ if (entrySingularPlural) {
252
+ const pluralPageNumbers = pageNumbers, ///
253
+ singularPageNumbers = indexMap[singularEntry] || [];
254
+
255
+ pageNumbers = [ ///
256
+ ...pluralPageNumbers,
257
+ ...singularPageNumbers
258
+ ];
259
+
260
+ delete indexMap[entry];
261
+
262
+ indexMap[singularEntry] = pageNumbers;
263
+ }
264
+ }
265
+ });
266
+ }
267
+
268
+ function singularPluralsFromPlurals(plurals) {
269
+ const singularPlurals = plurals.reduce((singularPlurals, plural) => {
270
+ const pluralSingular = isSingular(plural);
271
+
272
+ if (pluralSingular) {
273
+ const singularPlural = plural; ///
274
+
275
+ singularPlurals.push(singularPlural);
276
+ }
277
+
278
+ return singularPlurals;
279
+ }, []);
280
+
281
+ return singularPlurals;
282
+ }
283
+
284
+ function pluralPluralsFromPlurals(plurals) {
285
+ const pluralPlurals = plurals.reduce((pluralPlurals, plural) => {
286
+ const pluralPlural = isPlural(plural);
287
+
288
+ if (pluralPlural) {
289
+ const pluralPlural = plural; ///
290
+
291
+ pluralPlurals.push(pluralPlural);
292
+ }
293
+
294
+ return pluralPlurals;
295
+ }, []);
296
+
297
+ return pluralPlurals;
298
+ }
299
+
300
+ function mixedPluralsFromPlurals(plurals) {
301
+ const mixedPlurals = plurals.reduce((mixedPlurals, plural) => {
302
+ const pluralMixed = isMixed(plural);
303
+
304
+ if (pluralMixed) {
305
+ const mixedPlural = plural; ///
306
+
307
+ mixedPlurals.push(mixedPlural);
308
+ }
309
+
310
+ return mixedPlurals;
311
+ }, []);
312
+
313
+ return mixedPlurals;
314
+ }
315
+
316
+ function isSingular(text) {
317
+ const matches = /[^s)]$/.test(text),
318
+ pluralSingular = matches; ///
319
+
320
+ return pluralSingular;
321
+ }
322
+
323
+ function isPlural(text) {
324
+ const matches = /s$/.test(text),
325
+ plural = matches; ///
326
+
327
+ return plural;
328
+ }
329
+
330
+ function isMixed(text) {
331
+ const matches = /\(s\)$/.test(text),
332
+ plural = matches; ///
333
+
334
+ return plural;
335
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ export function forEach(object, callback) {
4
+ const keys = Object.keys(object);
5
+
6
+ keys.forEach((key) => {
7
+ const value = object[key];
8
+
9
+ callback(key, value);
10
+ });
11
+ }
12
+
13
+ export function filter(object, callback) {
14
+ const keys = Object.keys(object);
15
+
16
+ keys.forEach((key) => {
17
+ const value = object[key],
18
+ result = callback(key, value);
19
+
20
+ if (!result) {
21
+ delete object[key];
22
+ }
23
+ });
24
+ }
25
+
26
+ export function mapKeys(object, callback) {
27
+ const keys = Object.keys(object);
28
+
29
+ keys.forEach((key) => {
30
+ const value = object[key];
31
+
32
+ delete object[key];
33
+
34
+ key = callback(key, value); ///
35
+
36
+ object[key] = value;
37
+ });
38
+ }
39
+
40
+ export function mapValues(object, callback) {
41
+ const keys = Object.keys(object);
42
+
43
+ keys.forEach((key) => {
44
+ let value = object[key];
45
+
46
+ value = callback(key, value); ///
47
+
48
+ object[key] = value;
49
+ });
50
+ }
@@ -15,6 +15,8 @@ export function postprocess(divisionMarkdownNode, context) {
15
15
 
16
16
  createContents(divisionMarkdownNodes, context);
17
17
 
18
+ createIndex(divisionMarkdownNodes, context);
19
+
18
20
  return divisionMarkdownNodes;
19
21
  }
20
22
 
@@ -36,6 +38,16 @@ function paginate(divisionMarkdownNodes, context) {
36
38
  return divisionMarkdownNodes;
37
39
  }
38
40
 
41
+ function createIndex(divisionMarkdownNodes, context) {
42
+ divisionMarkdownNodes.some((divisionMarkdownNode) => {
43
+ const indexCreated = divisionMarkdownNode.createIndex(divisionMarkdownNodes, context);
44
+
45
+ if (indexCreated) {
46
+ return true;
47
+ }
48
+ });
49
+ }
50
+
39
51
  function createContents(divisionMarkdownNodes, context) {
40
52
  divisionMarkdownNodes.some((divisionMarkdownNode) => {
41
53
  const contentsCreated = divisionMarkdownNode.createContents(divisionMarkdownNodes, context);
@@ -6,16 +6,17 @@ import { arrayUtilities } from "necessary";
6
6
  const { first, push } = arrayUtilities;
7
7
 
8
8
  const footnoteMarkdownNodeQuery = Query.fromExpression("/subDivision/footnote"),
9
+ indexDirectiveMarkdownNodeQuery = Query.fromExpression("/subDivision/directives/indexDirective"),
9
10
  ignoreDirectiveMarkdownNodeQuery = Query.fromExpression("/division/subDivision/directives/ignoreDirective"),
10
11
  contentsDirectiveMarkdownNodeQuery = Query.fromExpression("/subDivision/directives/contentsDirective"),
11
12
  footnotesDirectiveMarkdownNodeQuery = Query.fromExpression("/subDivision/directives/footnotesDirective"),
12
13
  pageNumberDirectiveMarkdownNodeQuery = Query.fromExpression("/subDivision/directives/pageNumber"), ///
13
- linkMarkdownNodesQuery = Query.fromExpression("//link"),
14
14
  headingMarkdownNodesQuery = Query.fromExpression("/division/subDivision/primaryHeading|secondaryHeading|tertiaryHeading|quaternaryHeading"),
15
15
  subDivisionMarkdownNodesQuery = Query.fromExpression("/division/subDivision"),
16
+ footnoteLinkMarkdownNodesQuery = Query.fromExpression("//footnoteLink"),
16
17
  embedDirectiveMarkdownNodesQuery = Query.fromExpression("/subDivision/directives/embedDirective"),
17
18
  includeDirectiveMarkdownNodesQuery = Query.fromExpression("/subDivision/directives/includeDirective"),
18
- linkFootnoteOrFootnotesDirectiveMarkdownNodesQuery = Query.fromExpression("//link|footnote|footnotesDirective");
19
+ footnoteFootnoteLinkOrFootnotesDirectiveMarkdownNodesQuery = Query.fromExpression("//footnote|footnoteLink|footnotesDirective");
19
20
 
20
21
  export function nodeQuery(expression) {
21
22
  const query = Query.fromExpression(expression);
@@ -52,6 +53,12 @@ export function footnoteMarkdownNodeFromNode(node) {
52
53
  return footnoteMarkdownNode;
53
54
  }
54
55
 
56
+ export function indexDirectiveMarkdownNodeFromNode(node) {
57
+ const indexDirectiveMarkdownNode = nodeFromNodeAndQuery(node, indexDirectiveMarkdownNodeQuery);
58
+
59
+ return indexDirectiveMarkdownNode;
60
+ }
61
+
55
62
  export function ignoreDirectiveMarkdownNodeFromNode(node) {
56
63
  const ignoreDirectiveMarkdownNode = nodeFromNodeAndQuery(node, ignoreDirectiveMarkdownNodeQuery);
57
64
 
@@ -76,12 +83,6 @@ export function pageNumberDirectiveMarkdownNodeFromNode(node) {
76
83
  return pageNumberDirectiveMarkdownNode;
77
84
  }
78
85
 
79
- export function linkMarkdownNodesFromNode(node, linkMarkdownNodes = []) {
80
- nodesFromNodeAndQuery(node, linkMarkdownNodesQuery, linkMarkdownNodes);
81
-
82
- return linkMarkdownNodes;
83
- }
84
-
85
86
  export function headingMarkdownNodesFromNode(node, headingMarkdownNodes = []) {
86
87
  nodesFromNodeAndQuery(node, headingMarkdownNodesQuery, headingMarkdownNodes);
87
88
 
@@ -94,6 +95,12 @@ export function subDivisionMarkdownNodesFromNode(node, subDivisionMarkdownNodes
94
95
  return subDivisionMarkdownNodes;
95
96
  }
96
97
 
98
+ export function footnoteLinkMarkdownNodesFromNode(node, linkMarkdownNodes = []) {
99
+ nodesFromNodeAndQuery(node, footnoteLinkMarkdownNodesQuery, linkMarkdownNodes);
100
+
101
+ return linkMarkdownNodes;
102
+ }
103
+
97
104
  export function embedDirectiveMarkdownNodesFromNode(node, embedDirectiveMarkdownNodes = []) {
98
105
  nodesFromNodeAndQuery(node, embedDirectiveMarkdownNodesQuery, embedDirectiveMarkdownNodes);
99
106
 
@@ -106,24 +113,25 @@ export function includeDirectiveMarkdownNodesFromNode(node, includeDirectiveMark
106
113
  return includeDirectiveMarkdownNodes;
107
114
  }
108
115
 
109
- export function linkFootnoteOrFootnotesDirectiveMarkdownNodesFromNode(node, linkFootnoteOrFootnotesDirectiveMarkdownNodes = []) {
110
- nodesFromNodeAndQuery(node, linkFootnoteOrFootnotesDirectiveMarkdownNodesQuery, linkFootnoteOrFootnotesDirectiveMarkdownNodes);
116
+ export function footnoteFootnoteLinkOrFootnotesDirectiveMarkdownNodesFromNode(node, footnoteFootnoteLinkOrFootnotesDirectiveMarkdownNodes = []) {
117
+ nodesFromNodeAndQuery(node, footnoteFootnoteLinkOrFootnotesDirectiveMarkdownNodesQuery, footnoteFootnoteLinkOrFootnotesDirectiveMarkdownNodes);
111
118
 
112
- return linkFootnoteOrFootnotesDirectiveMarkdownNodes;
119
+ return footnoteFootnoteLinkOrFootnotesDirectiveMarkdownNodes;
113
120
  }
114
121
 
115
122
  export default {
116
123
  footnoteMarkdownNodeFromNode,
124
+ indexDirectiveMarkdownNodeFromNode,
117
125
  ignoreDirectiveMarkdownNodeFromNode,
118
126
  contentsDirectiveMarkdownNodeFromNode,
119
127
  footnotesDirectiveMarkdownNodeFromNode,
120
128
  pageNumberDirectiveMarkdownNodeFromNode,
121
- linkMarkdownNodesFromNode,
122
129
  headingMarkdownNodesFromNode,
123
130
  subDivisionMarkdownNodesFromNode,
131
+ footnoteLinkMarkdownNodesFromNode,
124
132
  embedDirectiveMarkdownNodesFromNode,
125
133
  includeDirectiveMarkdownNodesFromNode,
126
- linkFootnoteOrFootnotesDirectiveMarkdownNodesFromNode
134
+ footnoteFootnoteLinkOrFootnotesDirectiveMarkdownNodesFromNode
127
135
  };
128
136
 
129
137
  function nodeFromNodeAndQuery(node, query) {
@@ -6,6 +6,12 @@ export function appendNode(appendedNode, parentNode) {
6
6
  parentNode.appendChildNode(appendedChildNode);
7
7
  }
8
8
 
9
+ export function prependNode(prependedNode, parentNode) {
10
+ const prependedChildNode = prependedNode; ///
11
+
12
+ parentNode.prependChildNode(prependedChildNode);
13
+ }
14
+
9
15
  export function removeNode(removedNode, parentNode) {
10
16
  const removedChildNode = removedNode; ///
11
17
 
@@ -48,6 +54,15 @@ export function appendTokens(appendedTokens, parentNode, tokens) {
48
54
  tokens.splice(start, deleteCount, ...appendedTokens);
49
55
  }
50
56
 
57
+ export function prependTokens(prependedTokens, parentNode, tokens) {
58
+ const node = parentNode, ///
59
+ firstSignificantTokenIndex = node.getFirstSignificantTokenIndex(tokens),
60
+ start = firstSignificantTokenIndex,
61
+ deleteCount = 0;
62
+
63
+ tokens.splice(start, deleteCount, ...prependedTokens);
64
+ }
65
+
51
66
  export function removeTokens(removedNode, tokens) {
52
67
  const node = removedNode, ///
53
68
  firstSignificantTokenIndex = node.getFirstSignificantTokenIndex(tokens),
@@ -85,3 +100,69 @@ export function addTokensAfter(existingNode, addedTokens, tokens) {
85
100
 
86
101
  tokens.splice(start, deleteCount, ...addedTokens);
87
102
  }
103
+
104
+ export function overwriteClonedNodeTokens(clonedNode, clonedTokens, tokens, offset = 0) {
105
+ const node = clonedNode; ///
106
+
107
+ overwriteNodeTokens(node, clonedTokens, tokens, offset);
108
+ }
109
+
110
+ export function clonedTokensFromNodeAndTokens(node, tokens) {
111
+ const firstSignificantTokenIndex = node.getFirstSignificantTokenIndex(tokens),
112
+ lastSignificantTokenIndex = node.getLastSignificantTokenIndex(tokens),
113
+ start = firstSignificantTokenIndex, ///
114
+ end = lastSignificantTokenIndex + 1;
115
+
116
+ tokens = tokens.slice(start, end); ///
117
+
118
+ const clonedTokens = tokens.map((token) => { ///
119
+ const clonedToken = token.clone();
120
+
121
+ return clonedToken;
122
+ });
123
+
124
+ return clonedTokens;
125
+ }
126
+
127
+ function overwriteNodeTokens(node, clonedTokens, tokens, offset) {
128
+ const nodeTerminalNode = node.isTerminalNode();
129
+
130
+ if (nodeTerminalNode) {
131
+ const terminalNode = node; ///
132
+
133
+ overwriteTerminalNodeTokens(terminalNode, clonedTokens, tokens, offset);
134
+ } else {
135
+ const nonTerminalNode = node; ///
136
+
137
+ overwriteNonTerminalNodeTokens(nonTerminalNode, clonedTokens, tokens, offset);
138
+ }
139
+ }
140
+
141
+ function overwriteTerminalNodeTokens(terminalNode, clonedTokens, tokens, offset) {
142
+ let index,
143
+ significantToken;
144
+
145
+ significantToken = terminalNode.getSignificantToken();
146
+
147
+ if (significantToken !== null) {
148
+ index = tokens.indexOf(significantToken);
149
+
150
+ index -= offset;
151
+
152
+ const clonedToken = clonedTokens[index];
153
+
154
+ significantToken = clonedToken; ///
155
+
156
+ terminalNode.setSignificantToken(significantToken);
157
+ }
158
+ }
159
+
160
+ function overwriteNonTerminalNodeTokens(nonTerminalNode, clonedTokens, tokens, offset) {
161
+ const childNodes = nonTerminalNode.getChildNodes();
162
+
163
+ childNodes.forEach((childNode) => {
164
+ const clonedNode = childNode; ///
165
+
166
+ overwriteNodeTokens(clonedNode, clonedTokens, tokens, offset);
167
+ });
168
+ }