highmark-markdown 0.0.433 → 0.0.435
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 +1634 -919
- package/lib/defaultMarkdownStyle.js +2 -2
- package/lib/elementMap.js +4 -1
- package/lib/example/importer.js +2 -2
- package/lib/index/item.js +102 -0
- package/lib/index/list.js +88 -0
- package/lib/index/match.js +76 -0
- package/lib/letters.js +41 -0
- package/lib/markdown/bnf.js +2 -2
- package/lib/node/markdown/division.js +5 -5
- package/lib/node/markdown/footnotesList.js +5 -10
- package/lib/node/markdown/indexHeading.js +120 -0
- package/lib/node/markdown/indexItem.js +42 -2
- package/lib/node/markdown/indexLink.js +2 -3
- package/lib/node/markdown/indexList.js +5 -10
- package/lib/node/markdown/line.js +2 -2
- package/lib/nodeMap.js +3 -2
- package/lib/replacement/footnotesList.js +4 -4
- package/lib/replacement/index.js +187 -0
- package/lib/replacement/indexHeading.js +122 -0
- package/lib/replacement/indexItem.js +4 -4
- package/lib/replacement/indexList.js +9 -41
- package/lib/replacement.js +1 -9
- package/lib/ruleNames.js +6 -1
- package/lib/utilities/index.js +42 -42
- package/lib/utilities/object.js +8 -2
- package/package.json +1 -1
- package/src/defaultMarkdownStyle.js +18 -1
- package/src/elementMap.js +5 -0
- package/src/example/importer.js +7 -2
- package/src/index/item.js +43 -0
- package/src/index/list.js +62 -0
- package/src/index/{phraseMatcher.js → match.js} +6 -6
- package/src/letters.js +32 -0
- package/src/markdown/bnf.js +4 -1
- package/src/node/markdown/division.js +4 -4
- package/src/node/markdown/footnotesList.js +9 -16
- package/src/node/markdown/indexHeading.js +7 -0
- package/src/node/markdown/indexItem.js +20 -0
- package/src/node/markdown/indexLink.js +1 -4
- package/src/node/markdown/indexList.js +9 -16
- package/src/node/markdown/line.js +3 -2
- package/src/nodeMap.js +4 -1
- package/src/replacement/footnotesList.js +4 -3
- package/src/replacement/index.js +98 -0
- package/src/replacement/indexHeading.js +18 -0
- package/src/replacement/indexItem.js +4 -3
- package/src/replacement/indexList.js +7 -20
- package/src/replacement.js +0 -12
- package/src/ruleNames.js +2 -0
- package/src/utilities/index.js +46 -46
- package/src/utilities/object.js +12 -2
- package/lib/index/phraseMatcher.js +0 -76
|
@@ -179,11 +179,28 @@ footnotesItem {
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
indexList {
|
|
182
|
+
margin: 0;
|
|
182
183
|
list-style-type: none;
|
|
183
184
|
}
|
|
184
185
|
|
|
186
|
+
indexHeading {
|
|
187
|
+
font-size: 17pt;
|
|
188
|
+
line-height: 1;
|
|
189
|
+
font-weight: normal;
|
|
190
|
+
font-family: "Computer Modern Sans";
|
|
191
|
+
text-transform: uppercase;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
indexHeading {
|
|
195
|
+
margin: 13pt 0 0 0;
|
|
196
|
+
|
|
197
|
+
:first-child {
|
|
198
|
+
margin-top: 0;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
185
202
|
indexItem {
|
|
186
|
-
margin
|
|
203
|
+
margin: 0;
|
|
187
204
|
}
|
|
188
205
|
|
|
189
206
|
indexLink {
|
package/src/elementMap.js
CHANGED
|
@@ -27,6 +27,7 @@ import { LINE_RULE_NAME,
|
|
|
27
27
|
STRONG_TEXT_RULE_NAME,
|
|
28
28
|
SUB_DIVISION_RULE_NAME,
|
|
29
29
|
ORDERED_LIST_RULE_NAME,
|
|
30
|
+
INDEX_HEADING_RULE_NAME,
|
|
30
31
|
BLOCK_LISTING_RULE_NAME,
|
|
31
32
|
CONTENTS_LINK_RULE_NAME,
|
|
32
33
|
CONTENTS_ITEM_RULE_NAME,
|
|
@@ -167,6 +168,10 @@ const elementMap = {
|
|
|
167
168
|
tagName: "ol",
|
|
168
169
|
className: null
|
|
169
170
|
},
|
|
171
|
+
[INDEX_HEADING_RULE_NAME]: {
|
|
172
|
+
tagName: "h3",
|
|
173
|
+
className: "index"
|
|
174
|
+
},
|
|
170
175
|
[BLOCK_LISTING_RULE_NAME]: {
|
|
171
176
|
tagName: "pre",
|
|
172
177
|
className: "block"
|
package/src/example/importer.js
CHANGED
|
@@ -72,6 +72,8 @@ const indexContent = `## Index
|
|
|
72
72
|
|
|
73
73
|
introductionContent = `# Introduction
|
|
74
74
|
|
|
75
|
+
CLI
|
|
76
|
+
|
|
75
77
|
I have tried to make Occam[^occam] as useable as possible but there are limits.
|
|
76
78
|
At the end of the day it is an expert system and some of its parts, not least the verifier, need detailed explanation.
|
|
77
79
|
It is the purpose of this book is to provide these explanations.
|
|
@@ -88,6 +90,8 @@ This book explains how this is possible.
|
|
|
88
90
|
|
|
89
91
|
gettingStartedContent = `# Getting started
|
|
90
92
|
|
|
93
|
+
CLI
|
|
94
|
+
|
|
91
95
|
Another short paragraph with a reference to a footnote[^occam].
|
|
92
96
|
|
|
93
97
|
[^occam]: The word Occam is used somewhat nebulously here.
|
|
@@ -104,10 +108,11 @@ This book explains these divers parts and there is a companion book, called The
|
|
|
104
108
|
@pageNumber
|
|
105
109
|
`,
|
|
106
110
|
|
|
107
|
-
installingTheCLIContent = `## Installing the CLI
|
|
111
|
+
installingTheCLIContent = `## Installing the CLI
|
|
112
|
+
`,
|
|
108
113
|
|
|
109
114
|
gettingToGripsWithTheIDEIContent = `## Getting to grips with the IDE
|
|
110
|
-
|
|
115
|
+
|
|
111
116
|
* An unordered list to test...
|
|
112
117
|
* ...the indexing.
|
|
113
118
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { arrayUtilities } from "necessary";
|
|
4
|
+
|
|
5
|
+
const { first } = arrayUtilities;
|
|
6
|
+
|
|
7
|
+
export default class IndexItem {
|
|
8
|
+
constructor(lowerCaseLetter, wordOrPhrase, pageNumbers) {
|
|
9
|
+
this.lowerCaseLetter = lowerCaseLetter;
|
|
10
|
+
this.wordOrPhrase = wordOrPhrase;
|
|
11
|
+
this.pageNumbers = pageNumbers;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getLowerCaseLetter() {
|
|
15
|
+
return this.lowerCaseLetter;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getWordOrPhrase() {
|
|
19
|
+
return this.wordOrPhrase;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getPageNumbers() {
|
|
23
|
+
return this.pageNumbers;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
matchLetter(letter) {
|
|
27
|
+
const matchesLetter = (this.lowerCaseLetter === letter);
|
|
28
|
+
|
|
29
|
+
return matchesLetter;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static fromWordOrPhraseAndPageNumbers(wordOrPhrase, pageNumbers) {
|
|
33
|
+
const lowerCaseWordOrPhrase = wordOrPhrase.toLowerCase(),
|
|
34
|
+
lowerCaseLetters = [
|
|
35
|
+
...lowerCaseWordOrPhrase
|
|
36
|
+
],
|
|
37
|
+
firstLowerCaseLetter = first(lowerCaseLetters),
|
|
38
|
+
lowerCaseLetter = firstLowerCaseLetter, ///
|
|
39
|
+
indexItem = new IndexItem(lowerCaseLetter, wordOrPhrase, pageNumbers);
|
|
40
|
+
|
|
41
|
+
return indexItem;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { stringUtilities } from "necessary";
|
|
4
|
+
|
|
5
|
+
import IndexItem from "../index/item";
|
|
6
|
+
|
|
7
|
+
import { indexMapFromDivisionMarkdownNodes } from "../utilities/index";
|
|
8
|
+
|
|
9
|
+
const { strcmp } = stringUtilities;
|
|
10
|
+
|
|
11
|
+
export default class IndexList {
|
|
12
|
+
constructor(indexItems) {
|
|
13
|
+
this.indexItems = indexItems;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getIndexItems() {
|
|
17
|
+
return this.indexItems;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
reduceIndexItemByLetter(letter, callback) {
|
|
21
|
+
const indexItems = this.indexItems.filter((indexItem) => {
|
|
22
|
+
const indexItemMatchesLetter = indexItem.matchLetter(letter);
|
|
23
|
+
|
|
24
|
+
if (indexItemMatchesLetter) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const result = indexItems.map(callback);
|
|
30
|
+
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static fromDivisionMarkdownNodes(divisionMarkdownNodes, context) {
|
|
35
|
+
const indexMap = indexMapFromDivisionMarkdownNodes(divisionMarkdownNodes, context),
|
|
36
|
+
indexItems = indexItemsFromIndexMap(indexMap),
|
|
37
|
+
indexList = new IndexList(indexItems);
|
|
38
|
+
|
|
39
|
+
return indexList;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function indexItemsFromIndexMap(indexMap) {
|
|
44
|
+
const wordsOrPhrases = Object.keys(indexMap); ///
|
|
45
|
+
|
|
46
|
+
wordsOrPhrases.sort((wordOrPhraseA, wordOrPhraseB) => {
|
|
47
|
+
const lowerCaseWordOrPhraseA = wordOrPhraseA.toLowerCase(),
|
|
48
|
+
lowerCaseWordOrPhraseB = wordOrPhraseB.toLowerCase(),
|
|
49
|
+
difference = strcmp(lowerCaseWordOrPhraseB, lowerCaseWordOrPhraseA);
|
|
50
|
+
|
|
51
|
+
return difference;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const indexItems = wordsOrPhrases.map((wordOrPhrase, index) => {
|
|
55
|
+
const pageNumbers = indexMap[wordOrPhrase],
|
|
56
|
+
indexItem = IndexItem.fromWordOrPhraseAndPageNumbers(wordOrPhrase, pageNumbers);
|
|
57
|
+
|
|
58
|
+
return indexItem;
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
return indexItems;
|
|
62
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { UNDERSCORE, GLOBAL_FLAG, SINGLE_SPACE } from "../constants";
|
|
4
4
|
|
|
5
|
-
export default class
|
|
5
|
+
export default class IndexMatch {
|
|
6
6
|
constructor(regularExpression, replacement) {
|
|
7
7
|
this.regularExpression = regularExpression;
|
|
8
8
|
this.replacement = replacement;
|
|
@@ -22,17 +22,17 @@ export default class PhraseMatcher {
|
|
|
22
22
|
return plainText;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
static revert(
|
|
26
|
-
|
|
25
|
+
static revert(wordOrPhrase) {
|
|
26
|
+
wordOrPhrase = wordOrPhrase.replace(/_/g, SINGLE_SPACE);
|
|
27
27
|
|
|
28
|
-
return
|
|
28
|
+
return wordOrPhrase;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
static fromPhrase(phrase) {
|
|
32
32
|
const regularExpression = new RegExp(phrase, GLOBAL_FLAG),
|
|
33
33
|
replacement = phrase.replace(/\s/g, UNDERSCORE),
|
|
34
|
-
|
|
34
|
+
indexMatch = new IndexMatch(regularExpression, replacement);
|
|
35
35
|
|
|
36
|
-
return
|
|
36
|
+
return indexMatch;
|
|
37
37
|
}
|
|
38
38
|
}
|
package/src/letters.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const letters = [
|
|
4
|
+
"a",
|
|
5
|
+
"b",
|
|
6
|
+
"c",
|
|
7
|
+
"d",
|
|
8
|
+
"e",
|
|
9
|
+
"f",
|
|
10
|
+
"g",
|
|
11
|
+
"h",
|
|
12
|
+
"i",
|
|
13
|
+
"j",
|
|
14
|
+
"k",
|
|
15
|
+
"l",
|
|
16
|
+
"m",
|
|
17
|
+
"n",
|
|
18
|
+
"o",
|
|
19
|
+
"p",
|
|
20
|
+
"q",
|
|
21
|
+
"r",
|
|
22
|
+
"s",
|
|
23
|
+
"t",
|
|
24
|
+
"u",
|
|
25
|
+
"v",
|
|
26
|
+
"w",
|
|
27
|
+
"x",
|
|
28
|
+
"y",
|
|
29
|
+
"z"
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
export default letters;
|
package/src/markdown/bnf.js
CHANGED
|
@@ -260,10 +260,13 @@ const bnf = `
|
|
|
260
260
|
footnotesItem ::= anchor paragraph ;
|
|
261
261
|
|
|
262
262
|
|
|
263
|
+
indexHeading ::= line ;
|
|
264
|
+
|
|
265
|
+
|
|
263
266
|
indexList ::= indexItem+ ;
|
|
264
267
|
|
|
265
268
|
|
|
266
|
-
indexItem ::= line... indexLink ( comma indexLink )* ;
|
|
269
|
+
indexItem ::= line... comma indexLink ( comma indexLink )* ;
|
|
267
270
|
|
|
268
271
|
|
|
269
272
|
indexLink ::= [number] ;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import { arrayUtilities } from "necessary";
|
|
4
4
|
|
|
5
5
|
import MarkdownNode from "../../node/markdown";
|
|
6
|
+
import IndexReplacement from "../../replacement/index";
|
|
6
7
|
import FootnoteReplacement from "../../replacement/footnote";
|
|
7
|
-
import IndexListReplacement from "../../replacement/indexList";
|
|
8
8
|
import ContentsListReplacement from "../../replacement/contentsList";
|
|
9
9
|
import FootnotesListReplacement from "../../replacement/footnotesList";
|
|
10
10
|
import FootnoteSubDivisionReplacement from "../../replacement/subDivision/footnote";
|
|
@@ -139,10 +139,10 @@ export default class DivisionMarkdownNode extends MarkdownNode {
|
|
|
139
139
|
|
|
140
140
|
if (indexDirectiveSubDivisionReplacement !== null) {
|
|
141
141
|
const divisionMarkdownNode = this, ///
|
|
142
|
-
|
|
142
|
+
indexReplacement = IndexReplacement.fromDivisionMarkdownNodesAndDivisionMarkdownNode(divisionMarkdownNodes, divisionMarkdownNode, context);
|
|
143
143
|
|
|
144
|
-
if (
|
|
145
|
-
|
|
144
|
+
if (indexReplacement !== null) {
|
|
145
|
+
indexReplacement.replaceIndexDirectiveSubdivisionReplacement(indexDirectiveSubDivisionReplacement, divisionMarkdownNode, context);
|
|
146
146
|
|
|
147
147
|
indexCreated = true;
|
|
148
148
|
}
|
|
@@ -31,22 +31,15 @@ export default class FootnotesListMarkdownNode extends MarkdownNode {
|
|
|
31
31
|
clone() { return super.clone(this.start); }
|
|
32
32
|
|
|
33
33
|
static fromFootnotesItemReplacementsAndStart(footnotesItemReplacements, start) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return childNode;
|
|
45
|
-
}),
|
|
46
|
-
opacity = null;
|
|
47
|
-
|
|
48
|
-
footnotesListMarkdownNode = MarkdownNode.fromRuleNameChildNodesAndOpacity(FootnotesListMarkdownNode, ruleName, childNodes, opacity, start);
|
|
49
|
-
}
|
|
34
|
+
const ruleName = FOOTNOTES_LIST_RULE_NAME,
|
|
35
|
+
childNodes = footnotesItemReplacements.map((footnotesItemReplacement) => {
|
|
36
|
+
const footnotesItemReplacementMode = footnotesItemReplacement.getFootnotesItemMarkdownNode(),
|
|
37
|
+
childNode = footnotesItemReplacementMode; ///
|
|
38
|
+
|
|
39
|
+
return childNode;
|
|
40
|
+
}),
|
|
41
|
+
opacity = null,
|
|
42
|
+
footnotesListMarkdownNode = MarkdownNode.fromRuleNameChildNodesAndOpacity(FootnotesListMarkdownNode, ruleName, childNodes, opacity, start);
|
|
50
43
|
|
|
51
44
|
return footnotesListMarkdownNode;
|
|
52
45
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import MarkdownNode from "../../node/markdown";
|
|
4
|
+
|
|
5
|
+
export default class IndexHeadingMarkdownNode extends MarkdownNode {
|
|
6
|
+
static fromRuleNameChildNodesAndOpacity(ruleName, childNodes, opacity) { return MarkdownNode.fromRuleNameChildNodesAndOpacity(IndexHeadingMarkdownNode, ruleName, childNodes, opacity); }
|
|
7
|
+
}
|
|
@@ -3,5 +3,25 @@
|
|
|
3
3
|
import MarkdownNode from "../../node/markdown";
|
|
4
4
|
|
|
5
5
|
export default class IndexItemMarkdownNode extends MarkdownNode {
|
|
6
|
+
asHTML(indent, context) {
|
|
7
|
+
indent = this.adjustIndent(indent);
|
|
8
|
+
|
|
9
|
+
const childNodesHTML = this.childNodesAsHTML(indent, context),
|
|
10
|
+
startingTag = this.startingTag(context),
|
|
11
|
+
closingTag = this.closingTag(context),
|
|
12
|
+
html = `${indent}${startingTag}${childNodesHTML}${closingTag}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
return html;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
childNodesAsHTML(indent, context) {
|
|
19
|
+
indent = null;
|
|
20
|
+
|
|
21
|
+
const childNodesHTML = super.childNodesAsHTML(indent, context);
|
|
22
|
+
|
|
23
|
+
return childNodesHTML;
|
|
24
|
+
}
|
|
25
|
+
|
|
6
26
|
static fromRuleNameChildNodesAndOpacity(ruleName, childNodes, opacity) { return MarkdownNode.fromRuleNameChildNodesAndOpacity(IndexItemMarkdownNode, ruleName, childNodes, opacity); }
|
|
7
27
|
}
|
|
@@ -24,13 +24,10 @@ export default class IndexLinkMarkdownNode extends MarkdownNode {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
asHTML(indent, context) {
|
|
27
|
-
indent = this.adjustIndent(indent);
|
|
28
|
-
|
|
29
27
|
const childNodesHTML = this.childNodesAsHTML(indent, context),
|
|
30
28
|
startingTag = this.startingTag(context),
|
|
31
29
|
closingTag = this.closingTag(context),
|
|
32
|
-
html = `${
|
|
33
|
-
`;
|
|
30
|
+
html = `${startingTag}${childNodesHTML}${closingTag}`;
|
|
34
31
|
|
|
35
32
|
return html;
|
|
36
33
|
}
|
|
@@ -12,22 +12,15 @@ export default class IndexListMarkdownNode extends MarkdownNode {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
static fromIndexItemReplacements(indexItemReplacements) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return childNode;
|
|
26
|
-
}),
|
|
27
|
-
opacity = null;
|
|
28
|
-
|
|
29
|
-
indexListMarkdownNode = MarkdownNode.fromRuleNameChildNodesAndOpacity(IndexListMarkdownNode, ruleName, childNodes, opacity);
|
|
30
|
-
}
|
|
15
|
+
const ruleName = INDEX_LIST_RULE_NAME,
|
|
16
|
+
childNodes = indexItemReplacements.map((indexItemReplacement) => {
|
|
17
|
+
const indexItemReplacementNode = indexItemReplacement.getIndexItemMarkdownNode(),
|
|
18
|
+
childNode = indexItemReplacementNode; ///
|
|
19
|
+
|
|
20
|
+
return childNode;
|
|
21
|
+
}),
|
|
22
|
+
opacity = null,
|
|
23
|
+
indexListMarkdownNode = MarkdownNode.fromRuleNameChildNodesAndOpacity(IndexListMarkdownNode, ruleName, childNodes, opacity);
|
|
31
24
|
|
|
32
25
|
return indexListMarkdownNode;
|
|
33
26
|
}
|
|
@@ -21,8 +21,9 @@ export default class LineMarkdownNode extends MarkdownNode {
|
|
|
21
21
|
const childNodesHTML = this.childNodesAsHTML(indent, context),
|
|
22
22
|
startingTag = this.startingTag(context),
|
|
23
23
|
closingTag = this.closingTag(context),
|
|
24
|
-
html =
|
|
25
|
-
|
|
24
|
+
html = (indent !== null) ?
|
|
25
|
+
`${indent}${startingTag}${childNodesHTML}${closingTag}
|
|
26
|
+
`: `${startingTag}${childNodesHTML}${closingTag}`;
|
|
26
27
|
|
|
27
28
|
return html;
|
|
28
29
|
}
|
package/src/nodeMap.js
CHANGED
|
@@ -27,6 +27,7 @@ import InlineTextMarkdownNode from "./node/markdown/inlineText";
|
|
|
27
27
|
import StrongTextMarkdownNode from "./node/markdown/strongText";
|
|
28
28
|
import SubDivisionMarkdownNode from "./node/markdown/subDivision";
|
|
29
29
|
import OrderedListMarkdownNode from "./node/markdown/orderedList";
|
|
30
|
+
import IndexHeadingMarkdownNode from "./node/markdown/indexHeading";
|
|
30
31
|
import BlockListingMarkdownNode from "./node/markdown/blockListing";
|
|
31
32
|
import TableHeadRowMarkdownNode from "./node/markdown/tableHeadRow";
|
|
32
33
|
import TableBodyRowMarkdownNode from "./node/markdown/tableBodyRow";
|
|
@@ -87,11 +88,12 @@ import { LINE_RULE_NAME,
|
|
|
87
88
|
STRONG_TEXT_RULE_NAME,
|
|
88
89
|
SUB_DIVISION_RULE_NAME,
|
|
89
90
|
ORDERED_LIST_RULE_NAME,
|
|
90
|
-
|
|
91
|
+
INDEX_HEADING_RULE_NAME,
|
|
91
92
|
BLOCK_LISTING_RULE_NAME,
|
|
92
93
|
CONTENTS_LINK_RULE_NAME,
|
|
93
94
|
CONTENTS_ITEM_RULE_NAME,
|
|
94
95
|
CONTENTS_LIST_RULE_NAME,
|
|
96
|
+
FOOTNOTE_LINK_RULE_NAME,
|
|
95
97
|
TABLE_HEAD_ROW_RULE_NAME,
|
|
96
98
|
TABLE_BODY_ROW_RULE_NAME,
|
|
97
99
|
INLINE_LISTING_RULE_NAME,
|
|
@@ -148,6 +150,7 @@ const nodeMap = {
|
|
|
148
150
|
[STRONG_TEXT_RULE_NAME]: StrongTextMarkdownNode,
|
|
149
151
|
[SUB_DIVISION_RULE_NAME]: SubDivisionMarkdownNode,
|
|
150
152
|
[ORDERED_LIST_RULE_NAME]: OrderedListMarkdownNode,
|
|
153
|
+
[INDEX_HEADING_RULE_NAME]: IndexHeadingMarkdownNode,
|
|
151
154
|
[BLOCK_LISTING_RULE_NAME]: BlockListingMarkdownNode,
|
|
152
155
|
[CONTENTS_LINK_RULE_NAME]: ContentsLinkMarkdownNode,
|
|
153
156
|
[CONTENTS_ITEM_RULE_NAME]: ContentsItemMarkdownNode,
|
|
@@ -44,10 +44,11 @@ export default class FootnotesListReplacement extends Replacement {
|
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
const
|
|
47
|
+
const footnotesItemReplacementsLength = footnotesItemReplacements.length;
|
|
48
48
|
|
|
49
|
-
if (
|
|
50
|
-
const
|
|
49
|
+
if (footnotesItemReplacementsLength > 0) {
|
|
50
|
+
const footnotesListMarkdownNode = FootnotesListMarkdownNode.fromFootnotesItemReplacementsAndStart(footnotesItemReplacements, start),
|
|
51
|
+
node = footnotesListMarkdownNode, ///
|
|
51
52
|
tokens = [];
|
|
52
53
|
|
|
53
54
|
footnotesItemReplacements.forEach((footnotesItemReplacement) => {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Replacement from "../replacement";
|
|
4
|
+
|
|
5
|
+
import letters from "../letters";
|
|
6
|
+
import IndexList from "../index/list";
|
|
7
|
+
import IndexListReplacement from "../replacement/indexList";
|
|
8
|
+
import IndexHeadingReplacement from "./indexHeading";
|
|
9
|
+
|
|
10
|
+
import { replaceNodes, replaceTokens } from "../utilities/replacement";
|
|
11
|
+
|
|
12
|
+
export default class IndexReplacement extends Replacement {
|
|
13
|
+
constructor(node, tokens, nodes) {
|
|
14
|
+
super(node, tokens);
|
|
15
|
+
|
|
16
|
+
this.nodes = nodes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getNodes() {
|
|
20
|
+
return this.nodes;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getReplacementNodes() {
|
|
24
|
+
const replacementNodes = this.nodes; ///
|
|
25
|
+
|
|
26
|
+
return replacementNodes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getReplacementTokens() {
|
|
30
|
+
const tokens = this.getTokens(),
|
|
31
|
+
replacementTokens = tokens; ///
|
|
32
|
+
|
|
33
|
+
return replacementTokens;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
replace(replacedNode, parentNode, context) {
|
|
37
|
+
const { tokens } = context,
|
|
38
|
+
replacementNodes = this.getReplacementNodes(),
|
|
39
|
+
replacementTokens = this.getReplacementTokens();
|
|
40
|
+
|
|
41
|
+
replaceNodes(replacementNodes, replacedNode, parentNode);
|
|
42
|
+
|
|
43
|
+
replaceTokens(replacementTokens, replacedNode, tokens);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
replaceIndexDirectiveSubdivisionReplacement(indexDirectiveSubDivisionReplacement, divisionMarkdownNode, context) {
|
|
47
|
+
const subDivisionMarkdownNode = indexDirectiveSubDivisionReplacement.getSubDivisionMarkdownNode(),
|
|
48
|
+
replacedNode = subDivisionMarkdownNode, ///
|
|
49
|
+
parentNode = divisionMarkdownNode; ///
|
|
50
|
+
|
|
51
|
+
this.replace(replacedNode, parentNode, context)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static fromDivisionMarkdownNodesAndDivisionMarkdownNode(divisionMarkdownNodes, divisionMarkdownNode, context) {
|
|
55
|
+
let indexReplacement = null;
|
|
56
|
+
|
|
57
|
+
const indexList = IndexList.fromDivisionMarkdownNodes(divisionMarkdownNodes, context),
|
|
58
|
+
indexReplacements = [];
|
|
59
|
+
|
|
60
|
+
letters.forEach((letter) => {
|
|
61
|
+
const indexListReplacement = IndexListReplacement.fromIndexListAndLetter(indexList, letter, context);
|
|
62
|
+
|
|
63
|
+
if (indexListReplacement !== null) {
|
|
64
|
+
let indexReplacement;
|
|
65
|
+
|
|
66
|
+
const indexHeadingReplacement = IndexHeadingReplacement.fromLetter(letter, context);
|
|
67
|
+
|
|
68
|
+
indexReplacement = indexHeadingReplacement; ///
|
|
69
|
+
|
|
70
|
+
indexReplacements.push(indexReplacement);
|
|
71
|
+
|
|
72
|
+
indexReplacement = indexListReplacement; ///
|
|
73
|
+
|
|
74
|
+
indexReplacements.push(indexReplacement);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const indexListReplacementsLength = indexReplacements.length;
|
|
79
|
+
|
|
80
|
+
if (indexListReplacementsLength > 0) {
|
|
81
|
+
const node = null,
|
|
82
|
+
nodes = [],
|
|
83
|
+
tokens = [];
|
|
84
|
+
|
|
85
|
+
indexReplacements.forEach((indexReplacement) => {
|
|
86
|
+
const node = indexReplacement.getNode();
|
|
87
|
+
|
|
88
|
+
indexReplacement.getTokens(tokens);
|
|
89
|
+
|
|
90
|
+
nodes.push(node);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
indexReplacement = Replacement.fromNodeAndTokens(IndexReplacement, node, tokens, nodes);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return indexReplacement;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Replacement from "../replacement";
|
|
4
|
+
|
|
5
|
+
import { INDEX_HEADING_RULE_NAME } from "../ruleNames";
|
|
6
|
+
|
|
7
|
+
export default class IndexHeadingReplacement extends Replacement {
|
|
8
|
+
static fromLetter(letter, context) {
|
|
9
|
+
const { nodeFromTokens, tokensFromContent } = context, ///
|
|
10
|
+
startRuleName = INDEX_HEADING_RULE_NAME,
|
|
11
|
+
content = `${letter}`,
|
|
12
|
+
tokens = tokensFromContent(content),
|
|
13
|
+
node = nodeFromTokens(tokens, startRuleName),
|
|
14
|
+
indexHeadingReplacement = Replacement.fromNodeAndTokens(IndexHeadingReplacement, node, tokens);
|
|
15
|
+
|
|
16
|
+
return indexHeadingReplacement;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -13,11 +13,12 @@ export default class IndexItemReplacement extends Replacement {
|
|
|
13
13
|
return indexItemMarkdownNode;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
static
|
|
16
|
+
static fromIndexItem(indexItem, context) {
|
|
17
17
|
const { nodeFromTokens, tokensFromContent } = context,
|
|
18
|
-
|
|
18
|
+
wordOrPhrase = indexItem.getWordOrPhrase(),
|
|
19
|
+
pageNumbers = indexItem.getPageNumbers(),
|
|
19
20
|
pageNumbersContent = pageNumbers.join(COMMA),
|
|
20
|
-
content = `${
|
|
21
|
+
content = `${wordOrPhrase},${pageNumbersContent}`,
|
|
21
22
|
startRuleName = INDEX_ITEM_RULE_NAME,
|
|
22
23
|
tokens = tokensFromContent(content),
|
|
23
24
|
node = nodeFromTokens(tokens, startRuleName),
|
|
@@ -1,36 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Replacement from "../replacement";
|
|
4
|
-
|
|
5
4
|
import IndexItemReplacement from "../replacement/indexItem";
|
|
6
5
|
import IndexListMarkdownNode from "../node/markdown/indexList";
|
|
7
6
|
|
|
8
|
-
import { indexMapFromDivisionMarkdownNodes } from "../utilities/index";
|
|
9
|
-
|
|
10
7
|
export default class IndexListReplacement extends Replacement {
|
|
11
|
-
|
|
12
|
-
const subDivisionMarkdownNode = indexDirectiveSubDivisionReplacement.getSubDivisionMarkdownNode(),
|
|
13
|
-
replacedNode = subDivisionMarkdownNode, ///
|
|
14
|
-
parentNode = divisionMarkdownNode; ///
|
|
15
|
-
|
|
16
|
-
super.replace(replacedNode, parentNode, context)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static fromDivisionMarkdownNodesAndDivisionMarkdownNode(divisionMarkdownNodes, divisionMarkdownNode, context) {
|
|
8
|
+
static fromIndexListAndLetter(indexList, letter, context) {
|
|
20
9
|
let indexListReplacement = null;
|
|
21
10
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
indexItemReplacements = entries.map((entry) => {
|
|
25
|
-
const pageNumbers = indexMap[entry],
|
|
26
|
-
indexItemReplacement = IndexItemReplacement.fromEntryAndPageNumbers(entry, pageNumbers, context);
|
|
11
|
+
const indexItemReplacements = indexList.reduceIndexItemByLetter(letter, (indexItem) => {
|
|
12
|
+
const indexItemReplacement = IndexItemReplacement.fromIndexItem(indexItem, context);
|
|
27
13
|
|
|
28
14
|
return indexItemReplacement;
|
|
29
15
|
}),
|
|
30
|
-
|
|
16
|
+
indexItemReplacementsLength = indexItemReplacements.length;
|
|
31
17
|
|
|
32
|
-
if (
|
|
33
|
-
const
|
|
18
|
+
if (indexItemReplacementsLength > 0) {
|
|
19
|
+
const indexListMarkdownNode = IndexListMarkdownNode.fromIndexItemReplacements(indexItemReplacements),
|
|
20
|
+
node = indexListMarkdownNode, ///
|
|
34
21
|
tokens = [];
|
|
35
22
|
|
|
36
23
|
indexItemReplacements.forEach((indexItemReplacement) => {
|