highmark-markdown 0.0.206 → 0.0.210
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 +9011 -7223
- package/lib/constants.js +13 -1
- package/lib/defaultMarkdownStyle.js +14 -0
- package/lib/elementMap.js +6 -3
- package/lib/example/constants.js +5 -1
- package/lib/example/view/div/preview.js +5 -3
- package/lib/example/view/div/sizeable/left.js +2 -2
- package/lib/example/view/textarea/{bnf.js → css.js} +17 -17
- package/lib/example/view/textarea/{lexicalEntries.js → markdownStyle.js} +25 -19
- package/lib/example/view/xmp.js +2 -2
- package/lib/example/view.js +31 -22
- package/lib/example.js +9 -2
- package/lib/index.js +25 -1
- package/lib/markdown/bnf.js +2 -2
- package/lib/markdownStyle/bnf.js +14 -0
- package/lib/markdownStyle/entries.js +50 -0
- package/lib/markdownStyle/lexer.js +162 -0
- package/lib/{example/view/div/sizeable/right.js → markdownStyle/parser.js} +46 -34
- package/lib/node/markdown/division.js +14 -7
- package/lib/node/markdown/footnotes.js +135 -0
- package/lib/nodeMap.js +3 -2
- package/lib/ruleNames.js +8 -3
- package/lib/style/declaration.js +72 -0
- package/lib/style/declarations.js +89 -0
- package/lib/style/division.js +83 -0
- package/lib/style/ruleSet.js +85 -0
- package/lib/style/ruleSets.js +89 -0
- package/lib/style/selector.js +131 -0
- package/lib/style/selectors.js +134 -0
- package/lib/style/selectorsList.js +128 -0
- package/lib/styleElement/markdown/default.js +163 -0
- package/lib/styleElement/markdown.js +195 -0
- package/lib/styleElement.js +100 -0
- package/lib/utilities/content.js +29 -4
- package/lib/utilities/css.js +51 -0
- package/lib/utilities/entries.js +24 -0
- package/lib/utilities/footnotes.js +3 -3
- package/lib/utilities/query.js +39 -4
- package/package.json +1 -1
- package/src/constants.js +3 -0
- package/src/defaultMarkdownStyle.js +143 -0
- package/src/elementMap.js +8 -3
- package/src/example/constants.js +1 -0
- package/src/example/view/div/preview.js +5 -2
- package/src/example/view/div/sizeable/left.js +1 -1
- package/src/example/view/textarea/{bnf.js → css.js} +10 -10
- package/src/example/view/textarea/markdownStyle.js +41 -0
- package/src/example/view/xmp.js +0 -3
- package/src/example/view.js +55 -50
- package/src/example.js +10 -1
- package/src/index.js +6 -0
- package/src/markdown/bnf.js +5 -0
- package/src/markdownStyle/bnf.js +81 -0
- package/src/markdownStyle/entries.js +39 -0
- package/src/markdownStyle/lexer.js +43 -0
- package/src/markdownStyle/parser.js +15 -0
- package/src/node/markdown/division.js +25 -9
- package/src/node/markdown/footnotes.js +19 -0
- package/src/nodeMap.js +5 -2
- package/src/ruleNames.js +4 -2
- package/src/style/declaration.js +42 -0
- package/src/style/declarations.js +64 -0
- package/src/style/division.js +46 -0
- package/src/style/ruleSet.js +48 -0
- package/src/style/ruleSets.js +57 -0
- package/src/style/selector.js +126 -0
- package/src/style/selectors.js +121 -0
- package/src/style/selectorsList.js +95 -0
- package/src/styleElement/markdown/default.js +28 -0
- package/src/styleElement/markdown.js +48 -0
- package/src/styleElement.js +49 -0
- package/src/utilities/content.js +27 -0
- package/src/utilities/css.js +41 -0
- package/src/utilities/entries.js +23 -0
- package/src/utilities/footnotes.js +2 -2
- package/src/utilities/query.js +40 -3
- package/lib/example/view/textarea/parseTree.js +0 -183
- package/src/example/view/div/sizeable/right.js +0 -19
- package/src/example/view/textarea/lexicalEntries.js +0 -36
- package/src/example/view/textarea/parseTree.js +0 -50
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { arrayUtilities } from "necessary";
|
|
4
|
+
|
|
5
|
+
import Selector from "./selector";
|
|
6
|
+
|
|
7
|
+
import { nodesQuery } from "../utilities/query";
|
|
8
|
+
|
|
9
|
+
const selectorNonTerminalNodesQuery = nodesQuery("/selectors/selector");
|
|
10
|
+
|
|
11
|
+
const { first } = arrayUtilities;
|
|
12
|
+
|
|
13
|
+
export default class Selectors {
|
|
14
|
+
constructor(content, whitespace) {
|
|
15
|
+
this.content = content;
|
|
16
|
+
this.whitespace = whitespace;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getContent() {
|
|
20
|
+
return this.content;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
hasWhitespace() {
|
|
24
|
+
return this.whitespace;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
combine(selectors, outermost = false) {
|
|
28
|
+
if (selectors !== null) {
|
|
29
|
+
const outerSelectors = this, ///
|
|
30
|
+
innerSelectors = selectors, ///
|
|
31
|
+
outerSelectorsContent = outerSelectors.getContent(),
|
|
32
|
+
innerSelectorsContent = innerSelectors.getContent(),
|
|
33
|
+
outerSelectorsWhitespace = outerSelectors.hasWhitespace(),
|
|
34
|
+
innerSelectorsWhitespace = innerSelectors.hasWhitespace();
|
|
35
|
+
|
|
36
|
+
selectors = null;
|
|
37
|
+
|
|
38
|
+
if (outermost && !innerSelectorsWhitespace) {
|
|
39
|
+
///
|
|
40
|
+
} else {
|
|
41
|
+
if ((outerSelectorsContent !== null) && (innerSelectorsContent !== null)) {
|
|
42
|
+
const content = `${outerSelectorsContent}${innerSelectorsContent}`,
|
|
43
|
+
whitespace = outerSelectorsWhitespace;
|
|
44
|
+
|
|
45
|
+
selectors = Selectors.fromContentAndWhitespace(content, whitespace);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return selectors;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
asCSS() {
|
|
54
|
+
const css = this.content; ///
|
|
55
|
+
|
|
56
|
+
return css;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static fromNodeAndTokens(node, tokens) {
|
|
60
|
+
const selectors = selectorsFromNodeAndTokens(node, tokens);
|
|
61
|
+
|
|
62
|
+
return selectors;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static fromSelectorsString(selectorsString) {
|
|
66
|
+
const content = selectorsString,
|
|
67
|
+
whitespace = false,
|
|
68
|
+
selectors = new Selectors(content, whitespace);
|
|
69
|
+
|
|
70
|
+
return selectors;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static fromContentAndWhitespace(content, whitespace) {
|
|
74
|
+
const selectors = new Selectors(content, whitespace);
|
|
75
|
+
|
|
76
|
+
return selectors;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function selectorsFromNodeAndTokens(node, tokens) {
|
|
81
|
+
let selectors = null;
|
|
82
|
+
|
|
83
|
+
const selectorNonTerminalNodes = selectorNonTerminalNodesQuery(node),
|
|
84
|
+
selectorArray = selectorNonTerminalNodes.reduce((selectorArray, selectorNonTerminalNode) => {
|
|
85
|
+
const node = selectorNonTerminalNode, ///
|
|
86
|
+
selector = Selector.fromNodeAndTokens(node, tokens);
|
|
87
|
+
|
|
88
|
+
if (selector !== null) {
|
|
89
|
+
selectorArray.push(selector);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return selectorArray;
|
|
93
|
+
}, []),
|
|
94
|
+
selectorsArrayLength = selectorArray.length;
|
|
95
|
+
|
|
96
|
+
if (selectorsArrayLength > 0) {
|
|
97
|
+
const firstSelector = first(selectorArray),
|
|
98
|
+
selector = firstSelector, ///
|
|
99
|
+
content = selectorArray.reduce((content, selector) => {
|
|
100
|
+
const selectorContent = selector.getContent(),
|
|
101
|
+
selectorWhitespace = selector.hasWhitespace();
|
|
102
|
+
|
|
103
|
+
if (content === null) {
|
|
104
|
+
content = selectorWhitespace ?
|
|
105
|
+
` ${selectorContent}` :
|
|
106
|
+
`${selectorContent}`;
|
|
107
|
+
} else {
|
|
108
|
+
content = selectorWhitespace ?
|
|
109
|
+
`${content} ${selectorContent}` :
|
|
110
|
+
`${content}${selectorContent}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return content;
|
|
114
|
+
}, null),
|
|
115
|
+
whitespace = selector.hasWhitespace();
|
|
116
|
+
|
|
117
|
+
selectors = new Selectors(content, whitespace);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return selectors;
|
|
121
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Selectors from "./selectors";
|
|
4
|
+
|
|
5
|
+
import { EMPTY_STRING } from "../constants";
|
|
6
|
+
import { nodeQuery, nodesQuery } from "../utilities/query";
|
|
7
|
+
|
|
8
|
+
const selectorsNonTerminalNodesQuery = nodesQuery("/selectorsList/selectors"),
|
|
9
|
+
selectorsListNonTerminalNodeQuery = nodeQuery("/ruleSet/selectorsList");
|
|
10
|
+
|
|
11
|
+
export default class SelectorsList {
|
|
12
|
+
constructor(array) {
|
|
13
|
+
this.array = array;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getLength() { return this.array.length; }
|
|
17
|
+
|
|
18
|
+
reduceSelectors(callback, initialValue) { return this.array.reduce(callback, initialValue); }
|
|
19
|
+
|
|
20
|
+
forEachSelectors(callback) { this.array.forEach(callback); }
|
|
21
|
+
|
|
22
|
+
combine(selectorsList, outermost = false) {
|
|
23
|
+
const outerSelectorsList = SelectorsList.fromArray(this.array), ///
|
|
24
|
+
innerSelectorsList = selectorsList, ///
|
|
25
|
+
array = outerSelectorsList.reduceSelectors((array, outerSelectors) => {
|
|
26
|
+
innerSelectorsList.forEachSelectors((innerSelectors) => {
|
|
27
|
+
const selectors = outerSelectors.combine(innerSelectors, outermost);
|
|
28
|
+
|
|
29
|
+
if (selectors !== null) {
|
|
30
|
+
array.push(selectors);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return array;
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
selectorsList = SelectorsList.fromArray(array);
|
|
38
|
+
|
|
39
|
+
return selectorsList;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
asCSS() {
|
|
43
|
+
let css = EMPTY_STRING;
|
|
44
|
+
|
|
45
|
+
const length = this.getLength();
|
|
46
|
+
|
|
47
|
+
if (length > 0) {
|
|
48
|
+
css = this.array.reduce((css, selectors) => {
|
|
49
|
+
const selectorsCSS = selectors.asCSS();
|
|
50
|
+
|
|
51
|
+
css = (css === null) ?
|
|
52
|
+
selectorsCSS : ///
|
|
53
|
+
`${css},
|
|
54
|
+
${selectorsCSS}`;
|
|
55
|
+
|
|
56
|
+
return css;
|
|
57
|
+
}, null);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return css;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static fromArray(array) {
|
|
64
|
+
const selectorsList = new SelectorsList(array);
|
|
65
|
+
|
|
66
|
+
return selectorsList;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static fromNodeAndTokens(node, tokens) {
|
|
70
|
+
const selectorsListNonTerminalNode = selectorsListNonTerminalNodeQuery(node);
|
|
71
|
+
|
|
72
|
+
node = selectorsListNonTerminalNode; ///
|
|
73
|
+
|
|
74
|
+
const selectorsNonTerminalNodes = selectorsNonTerminalNodesQuery(node),
|
|
75
|
+
array = selectorsNonTerminalNodes.map((selectorsNonTerminalNode) => {
|
|
76
|
+
const node = selectorsNonTerminalNode, ///
|
|
77
|
+
selectors = Selectors.fromNodeAndTokens(node, tokens);
|
|
78
|
+
|
|
79
|
+
return selectors;
|
|
80
|
+
}),
|
|
81
|
+
selectorsList = new SelectorsList(array);
|
|
82
|
+
|
|
83
|
+
return selectorsList;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static fromSelectorsString(selectorsString) {
|
|
87
|
+
const selectors = Selectors.fromSelectorsString(selectorsString),
|
|
88
|
+
array = [
|
|
89
|
+
selectors
|
|
90
|
+
],
|
|
91
|
+
selectorsList = new SelectorsList(array);
|
|
92
|
+
|
|
93
|
+
return selectorsList;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import defaultMarkdownStyle from "../../defaultMarkdownStyle";
|
|
4
|
+
import MarkdownStyleElement from "../../styleElement/markdown";
|
|
5
|
+
|
|
6
|
+
export default class DefaultMarkdownStyleElement extends MarkdownStyleElement {
|
|
7
|
+
update(defaultMarkdownStyle) {
|
|
8
|
+
const markdownStyle = defaultMarkdownStyle; ///
|
|
9
|
+
|
|
10
|
+
super.update(markdownStyle)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
reset() {
|
|
14
|
+
this.update(defaultMarkdownStyle)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static fromSelectorsString(Class, selectorsString) {
|
|
18
|
+
if (selectorsString === undefined) {
|
|
19
|
+
selectorsString = Class; ///
|
|
20
|
+
|
|
21
|
+
Class = DefaultMarkdownStyleElement; ///
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const defaultMarkdownStyleElement = MarkdownStyleElement.fromSelectorsString(Class, selectorsString);
|
|
25
|
+
|
|
26
|
+
defaultMarkdownStyleElement.reset();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import StyleElement from "../styleElement";
|
|
4
|
+
import SelectorsList from "../style/selectorsList";
|
|
5
|
+
|
|
6
|
+
import { EMPTY_STRING } from "../constants";
|
|
7
|
+
import { createDOMElement } from "../styleElement";
|
|
8
|
+
import { cssFromMarkdownStyleAndSelectorsList } from "../utilities/css";
|
|
9
|
+
|
|
10
|
+
export default class MarkdownStyleElement extends StyleElement {
|
|
11
|
+
constructor(domElement, selectorsList) {
|
|
12
|
+
super(domElement);
|
|
13
|
+
|
|
14
|
+
this.selectorsList = selectorsList;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getSelectorsList() {
|
|
18
|
+
return this.selectorsList;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
update(markdownStyle = null) {
|
|
22
|
+
const css = cssFromMarkdownStyleAndSelectorsList(markdownStyle, this.selectorsList);
|
|
23
|
+
|
|
24
|
+
this.setCSS(css);
|
|
25
|
+
|
|
26
|
+
return css;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
reset() {
|
|
30
|
+
const markdownStyle = EMPTY_STRING;
|
|
31
|
+
|
|
32
|
+
this.update(markdownStyle)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static fromSelectorsString(Class, selectorString) {
|
|
36
|
+
if (selectorString === undefined) {
|
|
37
|
+
selectorString = Class; ///
|
|
38
|
+
|
|
39
|
+
Class = MarkdownStyleElement; ///
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const domElement = createDOMElement(),
|
|
43
|
+
selectorsList = SelectorsList.fromSelectorsString(selectorString),
|
|
44
|
+
markdownStyleElement = new Class(domElement, selectorsList);
|
|
45
|
+
|
|
46
|
+
return markdownStyleElement;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { HEAD, STYLE } from "./constants";
|
|
4
|
+
|
|
5
|
+
export default class StyleElement {
|
|
6
|
+
constructor(domElement) {
|
|
7
|
+
this.domElement = domElement;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
getDOMElement() {
|
|
11
|
+
return this.domElement;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
setDOMElement(domElement) {
|
|
15
|
+
this.domElement = domElement;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getInnerHTML() { return this.domElement.innerHTML; }
|
|
19
|
+
|
|
20
|
+
setInnerHTML(innerHTML) { this.domElement.innerHTML = innerHTML; }
|
|
21
|
+
|
|
22
|
+
setCSS(css) {
|
|
23
|
+
const innerHTML = `
|
|
24
|
+
${css}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
this.setInnerHTML(innerHTML);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
remove() { this.domElement.remove(); }
|
|
31
|
+
|
|
32
|
+
static fromNothing() {
|
|
33
|
+
const domElement = createDOMElement(),
|
|
34
|
+
styleElement = new StyleElement(domElement);
|
|
35
|
+
|
|
36
|
+
return styleElement;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function createDOMElement() {
|
|
41
|
+
const headDOMElement = document.querySelector(HEAD),
|
|
42
|
+
styleDOMElement = document.createElement(STYLE);
|
|
43
|
+
|
|
44
|
+
headDOMElement.appendChild(styleDOMElement);
|
|
45
|
+
|
|
46
|
+
const domElement = styleDOMElement; ///
|
|
47
|
+
|
|
48
|
+
return domElement;
|
|
49
|
+
}
|
package/src/utilities/content.js
CHANGED
|
@@ -67,6 +67,33 @@ export function contentFromMarkdownNodes(markdownNodes, context, leftTrimmed, ri
|
|
|
67
67
|
return content;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
export function contentFromNodeAndTokens(node, tokens, offset = 0) {
|
|
71
|
+
const firstSignificantToken = node.getFirstSignificantToken(),
|
|
72
|
+
lastSignificantToken = node.getLastSignificantToken(),
|
|
73
|
+
firstToken = firstSignificantToken, ///
|
|
74
|
+
lastToken = lastSignificantToken, ///
|
|
75
|
+
firstTokenIndex = tokens.indexOf(firstToken) + offset, ///
|
|
76
|
+
lastTokenIndex = tokens.indexOf(lastToken);
|
|
77
|
+
|
|
78
|
+
let content = EMPTY_STRING;
|
|
79
|
+
|
|
80
|
+
for (let index = firstTokenIndex; index <= lastTokenIndex; index++) {
|
|
81
|
+
const token = tokens[index],
|
|
82
|
+
tokenContent = token.getContent();
|
|
83
|
+
|
|
84
|
+
content += tokenContent;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return content;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function remainingContentFromNodeTokensAndOffset(node, tokens, offset) {
|
|
91
|
+
const content = contentFromNodeAndTokens(node, tokens, offset),
|
|
92
|
+
remainingContent = content; ///
|
|
93
|
+
|
|
94
|
+
return remainingContent;
|
|
95
|
+
}
|
|
96
|
+
|
|
70
97
|
function tokenContentFromToken(token) {
|
|
71
98
|
let tokenContent = token.getContent();
|
|
72
99
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Division from "../style/division";
|
|
4
|
+
import SelectorsList from "../style/selectorsList";
|
|
5
|
+
import MarkdownStyleLexer from "../markdownStyle/lexer";
|
|
6
|
+
import MarkdownStyleParser from "../markdownStyle/parser";
|
|
7
|
+
|
|
8
|
+
import { EMPTY_STRING } from "../constants";
|
|
9
|
+
|
|
10
|
+
const markdownStyleLexer = MarkdownStyleLexer.fromNothing(),
|
|
11
|
+
markdownStyleParser = MarkdownStyleParser.fromNothing();
|
|
12
|
+
|
|
13
|
+
export function cssFromMarkdownStyleAndSelectorsList(markdownStyle, selectorsList) {
|
|
14
|
+
let css = EMPTY_STRING;
|
|
15
|
+
|
|
16
|
+
const lexer = markdownStyleLexer, ///
|
|
17
|
+
parser = markdownStyleParser, ///
|
|
18
|
+
content = markdownStyle, ///
|
|
19
|
+
tokens = lexer.tokenise(content),
|
|
20
|
+
node = parser.parse(tokens);
|
|
21
|
+
|
|
22
|
+
if (node !== null) {
|
|
23
|
+
const division = Division.fromNodeTokensAndSelectorsList(node, tokens, selectorsList);
|
|
24
|
+
|
|
25
|
+
css = division.asCSS();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return css;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function cssFromMarkdownStyleAndSelectorString(markdownStyle, selectorString) {
|
|
32
|
+
const selectorsList = SelectorsList.fromSelectorsString(selectorString),
|
|
33
|
+
css = cssFromMarkdownStyleAndSelectorsList(markdownStyle, selectorsList);
|
|
34
|
+
|
|
35
|
+
return css;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default {
|
|
39
|
+
cssFromMarkdownStyleAndSelectorsList,
|
|
40
|
+
cssFromMarkdownStyleAndSelectorString
|
|
41
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export function ruleNamesExpressionFromElementMap(elementMap) {
|
|
4
|
+
const ruleNames = Object.keys(elementMap);
|
|
5
|
+
|
|
6
|
+
ruleNames.reverse();
|
|
7
|
+
|
|
8
|
+
const ruleNamesExpression = ruleNames.reduce((ruleNamesExpression, ruleName) => {
|
|
9
|
+
const { tagName } = elementMap[ruleName];
|
|
10
|
+
|
|
11
|
+
if (tagName !== null) {
|
|
12
|
+
ruleNamesExpression = (ruleNamesExpression === null) ?
|
|
13
|
+
ruleName :
|
|
14
|
+
`${ruleNamesExpression}|${ruleName}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return ruleNamesExpression;
|
|
18
|
+
}, null);
|
|
19
|
+
|
|
20
|
+
return ruleNamesExpression
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { linkMarkdownNodesFromNode } from "../utilities/query";
|
|
4
4
|
|
|
5
|
-
export function renumberLinkMarkdownNodes(
|
|
6
|
-
const node =
|
|
5
|
+
export function renumberLinkMarkdownNodes(markdownNode, footnotesListMarkdownNode, context) {
|
|
6
|
+
const node = markdownNode, ///
|
|
7
7
|
linkMarkdownNodes = linkMarkdownNodesFromNode(node),
|
|
8
8
|
identifierToNumberNap = footnotesListMarkdownNode.identifierToNumberMap();
|
|
9
9
|
|
package/src/utilities/query.js
CHANGED
|
@@ -6,11 +6,41 @@ import { arrayUtilities } from "necessary";
|
|
|
6
6
|
const { first, push } = arrayUtilities;
|
|
7
7
|
|
|
8
8
|
const linkMarkdownNodesQuery = Query.fromExpression(`//link`),
|
|
9
|
-
contentMarkdownNodeQuery = Query.fromExpression(`//contents`),
|
|
10
9
|
headingMarkdownNodesQuery = Query.fromExpression(`//primaryHeading|secondaryHeading|tertiaryHeading|quaternaryHeading`),
|
|
10
|
+
contentsMarkdownNodeQuery = Query.fromExpression(`//contents`),
|
|
11
11
|
footnoteMarkdownNodesQuery = Query.fromExpression(`//footnote`),
|
|
12
|
+
footnotesMarkdownNodesQuery = Query.fromExpression(`//footnotes`),
|
|
12
13
|
referenceMarkdownNodesQuery = Query.fromExpression(`//reference`);
|
|
13
14
|
|
|
15
|
+
export function nodeQuery(expression) {
|
|
16
|
+
const query = Query.fromExpression(expression);
|
|
17
|
+
|
|
18
|
+
return function(node) {
|
|
19
|
+
const nodes = query.execute(node),
|
|
20
|
+
nodesLength = nodes.length;
|
|
21
|
+
|
|
22
|
+
if (nodesLength > 0) {
|
|
23
|
+
const firstNode = first(nodes);
|
|
24
|
+
|
|
25
|
+
node = firstNode; ///
|
|
26
|
+
} else {
|
|
27
|
+
node = null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return node;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function nodesQuery(expression) {
|
|
35
|
+
const query = Query.fromExpression(expression);
|
|
36
|
+
|
|
37
|
+
return function(node) {
|
|
38
|
+
const nodes = query.execute(node);
|
|
39
|
+
|
|
40
|
+
return nodes;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
14
44
|
export function linkMarkdownNodesFromNode(node, linkMarkdownNodes = []) {
|
|
15
45
|
nodesFromNodeAndQuery(node, linkMarkdownNodesQuery, linkMarkdownNodes);
|
|
16
46
|
|
|
@@ -18,7 +48,7 @@ export function linkMarkdownNodesFromNode(node, linkMarkdownNodes = []) {
|
|
|
18
48
|
}
|
|
19
49
|
|
|
20
50
|
export function contentsMarkdownNodeFromNode(node) {
|
|
21
|
-
const contentsMarkdownNode = nodeFromNodeAndQuery(node,
|
|
51
|
+
const contentsMarkdownNode = nodeFromNodeAndQuery(node, contentsMarkdownNodeQuery);
|
|
22
52
|
|
|
23
53
|
return contentsMarkdownNode;
|
|
24
54
|
}
|
|
@@ -41,12 +71,19 @@ export function referenceMarkdownNodesFromNode(node, referenceMarkdownNodes = []
|
|
|
41
71
|
return referenceMarkdownNodes;
|
|
42
72
|
}
|
|
43
73
|
|
|
74
|
+
export function footnotesMarkdownNodesFromNode(node, footnotesMarkdownNodes = []) {
|
|
75
|
+
nodesFromNodeAndQuery(node, footnotesMarkdownNodesQuery, footnotesMarkdownNodes);
|
|
76
|
+
|
|
77
|
+
return footnotesMarkdownNodes;
|
|
78
|
+
}
|
|
79
|
+
|
|
44
80
|
export default {
|
|
45
81
|
linkMarkdownNodesFromNode,
|
|
46
82
|
contentsMarkdownNodeFromNode,
|
|
47
83
|
headingMarkdownNodesFromNode,
|
|
48
84
|
footnoteMarkdownNodesFromNode,
|
|
49
|
-
referenceMarkdownNodesFromNode
|
|
85
|
+
referenceMarkdownNodesFromNode,
|
|
86
|
+
footnotesMarkdownNodesFromNode
|
|
50
87
|
};
|
|
51
88
|
|
|
52
89
|
function nodeFromNodeAndQuery(node, query) {
|