highmark-markdown 0.0.204 → 0.0.209
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 +9014 -7397
- package/lib/constants.js +13 -1
- package/lib/defaultMarkdownStyle.js +14 -0
- 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 +30 -21
- 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/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/query.js +27 -1
- package/package.json +1 -1
- package/src/constants.js +3 -0
- package/src/defaultMarkdownStyle.js +143 -0
- 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 +52 -48
- package/src/example.js +10 -1
- package/src/index.js +6 -0
- package/src/markdown/bnf.js +1 -1
- 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/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/query.js +29 -0
- 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
package/src/example/view.js
CHANGED
|
@@ -3,22 +3,16 @@
|
|
|
3
3
|
import withStyle from "easy-with-style"; ///
|
|
4
4
|
|
|
5
5
|
import { Element } from "easy";
|
|
6
|
-
import {
|
|
6
|
+
import { MarkdownLexer, MarkdownParser } from "../index";
|
|
7
|
+
import { RowDiv, RowsDiv, ColumnDiv, ColumnsDiv, VerticalSplitterDiv } from "easy-layout";
|
|
7
8
|
|
|
8
9
|
import XMP from "./view/xmp";
|
|
9
10
|
import PreviewDiv from "./view/div/preview";
|
|
10
11
|
import SubHeading from "./view/subHeading";
|
|
11
|
-
import
|
|
12
|
+
import CSSTextarea from "./view/textarea/css";
|
|
12
13
|
import LeftSizeableDiv from "./view/div/sizeable/left";
|
|
13
|
-
import RightSizeableDiv from "./view/div/sizeable/right";
|
|
14
14
|
import MarkdownTextarea from "./view/textarea/markdown";
|
|
15
|
-
import
|
|
16
|
-
import LexicalEntriesTextarea from "./view/textarea/lexicalEntries";
|
|
17
|
-
|
|
18
|
-
import { MarkdownLexer, MarkdownParser } from "../index";
|
|
19
|
-
|
|
20
|
-
const { bnf } = MarkdownParser,
|
|
21
|
-
{ entries } = MarkdownLexer;
|
|
15
|
+
import MarkdownStyleTextarea from "./view/textarea/markdownStyle";
|
|
22
16
|
|
|
23
17
|
const markdownLexer = MarkdownLexer.fromNothing(),
|
|
24
18
|
markdownParser = MarkdownParser.fromNothing();
|
|
@@ -28,16 +22,22 @@ class View extends Element {
|
|
|
28
22
|
this.update();
|
|
29
23
|
}
|
|
30
24
|
|
|
31
|
-
|
|
25
|
+
updateMarkdownStyle() {
|
|
26
|
+
const { markdownStyleElement } = this.properties,
|
|
27
|
+
markdownStyle = this.getMarkdownStyle(),
|
|
28
|
+
css = markdownStyleElement.update(markdownStyle);
|
|
29
|
+
|
|
30
|
+
this.setCSS(css);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
updateMarkdown() {
|
|
32
34
|
const markdown = this.getMarkdown(),
|
|
33
|
-
lexer = markdownLexer, ///
|
|
34
|
-
parser = markdownParser, ///
|
|
35
35
|
content = markdown, ///
|
|
36
|
+
lexer = markdownLexer,
|
|
37
|
+
parser = markdownParser,
|
|
36
38
|
tokens = lexer.tokenise(content),
|
|
37
39
|
node = parser.parse(tokens);
|
|
38
40
|
|
|
39
|
-
let parseTree = null;
|
|
40
|
-
|
|
41
41
|
if (node !== null) {
|
|
42
42
|
const divisionMarkdownNode = node, ///
|
|
43
43
|
parentNode = null,
|
|
@@ -58,15 +58,16 @@ class View extends Element {
|
|
|
58
58
|
this.xmpHTML(html);
|
|
59
59
|
|
|
60
60
|
this.updatePreviewDiv(domElement);
|
|
61
|
-
|
|
62
|
-
parseTree = node.asParseTree(tokens);
|
|
63
61
|
} else {
|
|
64
62
|
this.clearXMP();
|
|
65
63
|
|
|
66
64
|
this.clearPreviewDiv();
|
|
67
65
|
}
|
|
66
|
+
}
|
|
68
67
|
|
|
69
|
-
|
|
68
|
+
update() {
|
|
69
|
+
this.updateMarkdown();
|
|
70
|
+
this.updateMarkdownStyle();
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
childElements() {
|
|
@@ -75,37 +76,29 @@ class View extends Element {
|
|
|
75
76
|
<ColumnsDiv>
|
|
76
77
|
<LeftSizeableDiv>
|
|
77
78
|
<SubHeading>
|
|
78
|
-
|
|
79
|
-
</SubHeading>
|
|
80
|
-
<LexicalEntriesTextarea onKeyUp={this.keyUpHandler} />
|
|
81
|
-
<SubHeading>
|
|
82
|
-
BNF
|
|
79
|
+
Markdown
|
|
83
80
|
</SubHeading>
|
|
84
|
-
<
|
|
81
|
+
<MarkdownTextarea onKeyUp={this.keyUpHandler} />
|
|
85
82
|
<SubHeading>
|
|
86
|
-
|
|
83
|
+
Markdown style
|
|
87
84
|
</SubHeading>
|
|
88
|
-
<
|
|
85
|
+
<MarkdownStyleTextarea onKeyUp={this.keyUpHandler} />
|
|
89
86
|
</LeftSizeableDiv>
|
|
90
87
|
<VerticalSplitterDiv/>
|
|
91
88
|
<ColumnDiv>
|
|
92
89
|
<RowsDiv>
|
|
93
|
-
<
|
|
94
|
-
|
|
95
|
-
</
|
|
96
|
-
<
|
|
97
|
-
<
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
</SubHeading>
|
|
106
|
-
<MarkdownTextarea onKeyUp={this.keyUpHandler} />
|
|
107
|
-
</RowsDiv>
|
|
108
|
-
</RowDiv>
|
|
90
|
+
<SubHeading>
|
|
91
|
+
HTML
|
|
92
|
+
</SubHeading>
|
|
93
|
+
<XMP/>
|
|
94
|
+
<SubHeading>
|
|
95
|
+
CSS
|
|
96
|
+
</SubHeading>
|
|
97
|
+
<CSSTextarea/>
|
|
98
|
+
<SubHeading>
|
|
99
|
+
Preview
|
|
100
|
+
</SubHeading>
|
|
101
|
+
<PreviewDiv/>
|
|
109
102
|
</RowsDiv>
|
|
110
103
|
</ColumnDiv>
|
|
111
104
|
</ColumnsDiv>
|
|
@@ -116,25 +109,36 @@ class View extends Element {
|
|
|
116
109
|
initialise() {
|
|
117
110
|
this.assignContext();
|
|
118
111
|
|
|
119
|
-
const { initialMarkdown } = this.constructor,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
this.setBNF(bnf);
|
|
112
|
+
const { initialMarkdown, initialMarkdownStyle } = this.constructor,
|
|
113
|
+
markdownStyle = initialMarkdownStyle, ///
|
|
114
|
+
markdown = initialMarkdown; ///
|
|
124
115
|
|
|
125
116
|
this.setMarkdown(markdown);
|
|
126
117
|
|
|
127
|
-
this.
|
|
118
|
+
this.setMarkdownStyle(markdownStyle);
|
|
128
119
|
|
|
129
120
|
this.update();
|
|
130
121
|
}
|
|
131
122
|
|
|
123
|
+
static initialMarkdownStyle = `
|
|
124
|
+
min-height: initial;
|
|
125
|
+
|
|
126
|
+
paragraph {
|
|
127
|
+
colour: red;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
`;
|
|
131
|
+
|
|
132
132
|
static initialMarkdown = `1. First item.
|
|
133
133
|
3. Third item.
|
|
134
134
|
`;
|
|
135
135
|
|
|
136
136
|
static tagName = "div";
|
|
137
137
|
|
|
138
|
+
static ignoredProperties = [
|
|
139
|
+
"markdownStyleElement"
|
|
140
|
+
];
|
|
141
|
+
|
|
138
142
|
static defaultProperties = {
|
|
139
143
|
className: "view"
|
|
140
144
|
};
|
package/src/example.js
CHANGED
|
@@ -5,17 +5,26 @@ import "juxtapose";
|
|
|
5
5
|
import withStyle from "easy-with-style"; ///
|
|
6
6
|
|
|
7
7
|
import { Body } from "easy";
|
|
8
|
+
import { MarkdownStyleElement, DefaultMarkdownStyleElement } from "./index"; ///
|
|
8
9
|
|
|
9
10
|
import View from "./example/view";
|
|
10
11
|
|
|
12
|
+
import { PREVIEW_DIV_SELECTORS_STRING } from "./example/constants";
|
|
13
|
+
|
|
11
14
|
const { renderStyles } = withStyle;
|
|
12
15
|
|
|
16
|
+
const selectorSString = PREVIEW_DIV_SELECTORS_STRING;
|
|
17
|
+
|
|
18
|
+
DefaultMarkdownStyleElement.fromSelectorsString(selectorSString);
|
|
19
|
+
|
|
20
|
+
const markdownStyleElement = MarkdownStyleElement.fromSelectorsString(selectorSString);
|
|
21
|
+
|
|
13
22
|
renderStyles();
|
|
14
23
|
|
|
15
24
|
const body = new Body();
|
|
16
25
|
|
|
17
26
|
body.mount(
|
|
18
27
|
|
|
19
|
-
<View/>
|
|
28
|
+
<View markdownStyleElement={markdownStyleElement} />
|
|
20
29
|
|
|
21
30
|
);
|
package/src/index.js
CHANGED
|
@@ -4,7 +4,13 @@ export { default as nodeMap } from "./nodeMap";
|
|
|
4
4
|
export { default as ruleNames } from "./ruleNames";
|
|
5
5
|
export { default as tokenTypes } from "./tokenTypes";
|
|
6
6
|
export { default as elementMap } from "./elementMap";
|
|
7
|
+
export { default as cssUtilities } from "./utilities/css";
|
|
7
8
|
export { default as MarkdownNode } from "./node/markdown";
|
|
8
9
|
export { default as MarkdownLexer } from "./markdown/lexer";
|
|
9
10
|
export { default as MarkdownParser } from "./markdown/parser";
|
|
10
11
|
export { default as queryUtilities } from "./utilities/query";
|
|
12
|
+
export { default as MarkdownStyleLexer } from "./markdownStyle/lexer";
|
|
13
|
+
export { default as MarkdownStyleParser } from "./markdownStyle/parser";
|
|
14
|
+
export { default as MarkdownStyleElement } from "./styleElement/markdown";
|
|
15
|
+
export { default as defaultMarkdownStyle } from "./defaultMarkdownStyle";
|
|
16
|
+
export { default as DefaultMarkdownStyleElement } from "./styleElement/markdown/default";
|
package/src/markdown/bnf.js
CHANGED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const bnf = `
|
|
4
|
+
|
|
5
|
+
style ::= ( ruleSet | declaration | nonsense | error )+ ;
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
ruleSet.. ::= selectorsList "{" ( ruleSet | declaration | nonsense )* "}" ;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
declaration ::= name ":" values ";" ;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
nonsense. ::= [string-literal] | [escaped] | [rule-name] | [number] | [colour] | [unit] | [name] | [special] | [unassigned] ;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
error. ::= . ;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
selectorsList ::= selectors ( "," selectors )* ;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
selectors ::= selector+ ;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
selector ::= [rule-name] class* pseudoClass*
|
|
27
|
+
|
|
28
|
+
| class+ pseudoClass*
|
|
29
|
+
|
|
30
|
+
| pseudoClass+
|
|
31
|
+
|
|
32
|
+
;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
values ::= value+ ;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ::= <NO_WHITESPACE>"."<NO_WHITESPACE>identifier ;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
pseudoClass ::= <NO_WHITESPACE>":"<NO_WHITESPACE>identifier ;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
name. ::= identifier ;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
value. ::= identifier ( <NO_WHITESPACE>"(" arguments ")" )?
|
|
48
|
+
|
|
49
|
+
| [number]<NO_WHITESPACE>[unit]
|
|
50
|
+
|
|
51
|
+
| [string-literal]
|
|
52
|
+
|
|
53
|
+
| [number]
|
|
54
|
+
|
|
55
|
+
| [colour]
|
|
56
|
+
|
|
57
|
+
;
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
arguments ::= argument ( "," argument )* ;
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
argument ::= identifier
|
|
64
|
+
|
|
65
|
+
| [number]<NO_WHITESPACE>[unit]
|
|
66
|
+
|
|
67
|
+
| [string-literal]
|
|
68
|
+
|
|
69
|
+
| [number]
|
|
70
|
+
|
|
71
|
+
| [colour]
|
|
72
|
+
|
|
73
|
+
;
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
identifier ::= ( [rule-name] | [name] ) ( <NO_WHITESPACE>"-"<NO_WHITESPACE>( [rule-name] | [name] ) )* ;
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
`;
|
|
80
|
+
|
|
81
|
+
export default bnf;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import elementMap from "../elementMap";
|
|
4
|
+
|
|
5
|
+
import { ruleNamesExpressionFromElementMap } from "../utilities/entries";
|
|
6
|
+
|
|
7
|
+
const ruleNamesExpression = ruleNamesExpressionFromElementMap(elementMap);
|
|
8
|
+
|
|
9
|
+
const entries = [
|
|
10
|
+
{
|
|
11
|
+
"escaped": "^\\\\[^\\s]"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"rule-name": `^(?:${ruleNamesExpression})`
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"number": "^(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"colour": "^#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"unit": "^(?:deg|%)"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "^[_a-zA-Z0-9]+"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"bracket": "^(?:\\{|\\})"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"special": "^(?:,|:|;|-|\\.|\\(|\\)|\\[|\\])"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"unassigned": "^[^\\s]+"
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
export default entries;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { CommonLexer } from "occam-lexers";
|
|
4
|
+
import { WhitespaceToken,
|
|
5
|
+
EndOfLineNonSignificantToken,
|
|
6
|
+
CStyleSingleLineCommentToken,
|
|
7
|
+
DoublyQuotedStringLiteralToken,
|
|
8
|
+
EndOfLineCommentSignificantToken,
|
|
9
|
+
CStyleEndOfMultiLineCommentToken,
|
|
10
|
+
CStyleStartOfMultiLineCommentToken,
|
|
11
|
+
CStyleMiddleOfMultiLineCommentToken } from "occam-lexers";
|
|
12
|
+
|
|
13
|
+
import entries from "./entries";
|
|
14
|
+
|
|
15
|
+
export default class MarkdownStyleLexer extends CommonLexer {
|
|
16
|
+
static entries = entries;
|
|
17
|
+
|
|
18
|
+
static EndOfLineToken = EndOfLineNonSignificantToken;
|
|
19
|
+
|
|
20
|
+
static WhitespaceToken = WhitespaceToken;
|
|
21
|
+
|
|
22
|
+
static EndOfLineCommentToken = EndOfLineCommentSignificantToken; ///
|
|
23
|
+
|
|
24
|
+
static SingleLineCommentToken = CStyleSingleLineCommentToken; ///
|
|
25
|
+
|
|
26
|
+
static RegularExpressionToken = null;
|
|
27
|
+
|
|
28
|
+
static EndOfMultiLineCommentToken = CStyleEndOfMultiLineCommentToken; ///
|
|
29
|
+
|
|
30
|
+
static StartOfMultiLineCommentToken = CStyleStartOfMultiLineCommentToken; ///
|
|
31
|
+
|
|
32
|
+
static MiddleOfMultiLineCommentToken = CStyleMiddleOfMultiLineCommentToken; ///
|
|
33
|
+
|
|
34
|
+
static SinglyQuotedStringLiteralToken = null;
|
|
35
|
+
|
|
36
|
+
static DoublyQuotedStringLiteralToken = DoublyQuotedStringLiteralToken;
|
|
37
|
+
|
|
38
|
+
static fromNothing() { return CommonLexer.fromNothing(MarkdownStyleLexer); }
|
|
39
|
+
|
|
40
|
+
static fromRules(rules) { return CommonLexer.fromRules(MarkdownStyleLexer, rules); }
|
|
41
|
+
|
|
42
|
+
static fromEntries(entries) { return CommonLexer.fromEntries(MarkdownStyleLexer, entries); }
|
|
43
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { CommonParser } from "occam-parsers";
|
|
4
|
+
|
|
5
|
+
import bnf from "./bnf";
|
|
6
|
+
|
|
7
|
+
export default class MarkdownStyleParser extends CommonParser {
|
|
8
|
+
static bnf = bnf;
|
|
9
|
+
|
|
10
|
+
static fromNothing() { return CommonParser.fromNothing(MarkdownStyleParser); }
|
|
11
|
+
|
|
12
|
+
static fromBNF(bnf) { return CommonParser.fromBNF(MarkdownStyleParser, bnf); }
|
|
13
|
+
|
|
14
|
+
static fromRules(rules) { return CommonParser.fromRules(MarkdownStyleParser, rules); }
|
|
15
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { COLOUR } from "../constants";
|
|
4
|
+
import { nodeQuery } from "../utilities/query";
|
|
5
|
+
import { contentFromNodeAndTokens } from "../utilities/content";
|
|
6
|
+
|
|
7
|
+
const nameNonTerminalNodeQuery = nodeQuery("/*/name"),
|
|
8
|
+
valuesNonTerminalNodeQuery = nodeQuery("/*/values");
|
|
9
|
+
|
|
10
|
+
export default class Declaration {
|
|
11
|
+
constructor(name, values) {
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.values = values;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getName() {
|
|
17
|
+
return this.name;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getValues() {
|
|
21
|
+
return this.values;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
asCSS() {
|
|
25
|
+
const name = this.name.replace(/colour/g, COLOUR),
|
|
26
|
+
css = ` ${name}: ${this.values};`;
|
|
27
|
+
|
|
28
|
+
return css;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static fromNodeAndTokens(node, tokens) {
|
|
32
|
+
const nameNonTerminalNode = nameNonTerminalNodeQuery(node),
|
|
33
|
+
valuesNonTerminalNode = valuesNonTerminalNodeQuery(node),
|
|
34
|
+
nameNonTerminalNodeContent = contentFromNodeAndTokens(nameNonTerminalNode, tokens),
|
|
35
|
+
valuesNonTerminalNodesContent = contentFromNodeAndTokens(valuesNonTerminalNode, tokens),
|
|
36
|
+
name = nameNonTerminalNodeContent, ///
|
|
37
|
+
values = valuesNonTerminalNodesContent, ///
|
|
38
|
+
declaration = new Declaration(name, values);
|
|
39
|
+
|
|
40
|
+
return declaration;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Declaration from "./declaration";
|
|
4
|
+
|
|
5
|
+
import { nodesQuery } from "../utilities/query";
|
|
6
|
+
import { EMPTY_STRING } from "../constants";
|
|
7
|
+
|
|
8
|
+
const declarationNonTerminalNodesQuery = nodesQuery("/*/declaration");
|
|
9
|
+
|
|
10
|
+
export default class Declarations {
|
|
11
|
+
constructor(array) {
|
|
12
|
+
this.array = array;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getLength() { return this.array.length; }
|
|
16
|
+
|
|
17
|
+
asCSS(selectorsList) {
|
|
18
|
+
let css = EMPTY_STRING;
|
|
19
|
+
|
|
20
|
+
const length = this.getLength(),
|
|
21
|
+
selectorsListLength = selectorsList.getLength();
|
|
22
|
+
|
|
23
|
+
if ((length > 0) && (selectorsListLength > 0)) {
|
|
24
|
+
const declarationsCSS = this.array.reduce((declarationsCSS, declaration) => {
|
|
25
|
+
const declarationCSS = declaration.asCSS();
|
|
26
|
+
|
|
27
|
+
declarationsCSS = (declarationsCSS === null) ?
|
|
28
|
+
declarationCSS : ///
|
|
29
|
+
`${declarationsCSS}
|
|
30
|
+
${declarationCSS}`;
|
|
31
|
+
|
|
32
|
+
return declarationsCSS;
|
|
33
|
+
}, null),
|
|
34
|
+
selectorsListCSS = selectorsList.asCSS();
|
|
35
|
+
|
|
36
|
+
css = `${selectorsListCSS} {
|
|
37
|
+
${declarationsCSS}
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return css;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static fromNothing() {
|
|
46
|
+
const array = [],
|
|
47
|
+
declarations = new Declarations(array);
|
|
48
|
+
|
|
49
|
+
return declarations;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static fromNodeAndTokens(node, tokens) {
|
|
53
|
+
const declarationNonTerminalNodes = declarationNonTerminalNodesQuery(node),
|
|
54
|
+
array = declarationNonTerminalNodes.map((declarationNonTerminalNode) => {
|
|
55
|
+
const node = declarationNonTerminalNode, ///
|
|
56
|
+
declaration = Declaration.fromNodeAndTokens(node, tokens);
|
|
57
|
+
|
|
58
|
+
return declaration;
|
|
59
|
+
}),
|
|
60
|
+
declarations = new Declarations(array);
|
|
61
|
+
|
|
62
|
+
return declarations;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import RuleSets from "./ruleSets";
|
|
4
|
+
import Declarations from "./declarations";
|
|
5
|
+
|
|
6
|
+
import { EMPTY_STRING } from "../constants";
|
|
7
|
+
|
|
8
|
+
export default class Division {
|
|
9
|
+
constructor(ruleSets, declarations, selectorsList) {
|
|
10
|
+
this.ruleSets = ruleSets;
|
|
11
|
+
this.declarations = declarations;
|
|
12
|
+
this.selectorsList = selectorsList;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getRuleSets() {
|
|
16
|
+
return this.ruleSets;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getDeclarations() {
|
|
20
|
+
return this.declarations;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getSelectorsList() {
|
|
24
|
+
return this.selectorsList;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
asCSS() {
|
|
28
|
+
const outermost = true,
|
|
29
|
+
ruleSetsCSS = this.ruleSets.asCSS(this.selectorsList, outermost),
|
|
30
|
+
declarationsCSS = this.declarations.asCSS(this.selectorsList, outermost),
|
|
31
|
+
css = (declarationsCSS === EMPTY_STRING) ?
|
|
32
|
+
ruleSetsCSS : ///
|
|
33
|
+
`${declarationsCSS}
|
|
34
|
+
${ruleSetsCSS}`;
|
|
35
|
+
|
|
36
|
+
return css;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static fromNodeTokensAndSelectorsList(node, tokens, selectorsList) {
|
|
40
|
+
const ruleSets = RuleSets.fromNodeAndTokens(node, tokens),
|
|
41
|
+
declarations = Declarations.fromNodeAndTokens(node, tokens),
|
|
42
|
+
division = new Division(ruleSets, declarations, selectorsList);
|
|
43
|
+
|
|
44
|
+
return division;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Declarations from "./declarations";
|
|
4
|
+
import SelectorsList from "./selectorsList";
|
|
5
|
+
|
|
6
|
+
import { EMPTY_STRING } from "../constants";
|
|
7
|
+
|
|
8
|
+
export default class RuleSet {
|
|
9
|
+
constructor(ruleSets, declarations, selectorsList) {
|
|
10
|
+
this.ruleSets = ruleSets;
|
|
11
|
+
this.declarations = declarations;
|
|
12
|
+
this.selectorsList = selectorsList;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getRuleSets() {
|
|
16
|
+
return this.ruleSets;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getDeclarations() {
|
|
20
|
+
return this.declarations;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getSelectorsList() {
|
|
24
|
+
return this.selectorsList;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
asCSS(selectorsList, outermost = false) {
|
|
28
|
+
selectorsList = selectorsList.combine(this.selectorsList, outermost); ///
|
|
29
|
+
|
|
30
|
+
const declarationsCSS = this.declarations.asCSS(selectorsList),
|
|
31
|
+
ruleSetsCSS = this.ruleSets.asCSS(selectorsList),
|
|
32
|
+
css = (declarationsCSS === EMPTY_STRING) ?
|
|
33
|
+
ruleSetsCSS : ///
|
|
34
|
+
`${declarationsCSS}
|
|
35
|
+
${ruleSetsCSS}`;
|
|
36
|
+
|
|
37
|
+
return css;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static fromRuleSetsNodeAndTokens(RuleSets, node, tokens) {
|
|
41
|
+
const ruleSets = RuleSets.fromNodeAndTokens(node, tokens),
|
|
42
|
+
declarations = Declarations.fromNodeAndTokens(node, tokens),
|
|
43
|
+
selectorsList = SelectorsList.fromNodeAndTokens(node, tokens),
|
|
44
|
+
ruleSet = new RuleSet(ruleSets, declarations, selectorsList);
|
|
45
|
+
|
|
46
|
+
return ruleSet;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import RuleSet from "./ruleSet";
|
|
4
|
+
|
|
5
|
+
import { nodesQuery } from "../utilities/query";
|
|
6
|
+
import { EMPTY_STRING } from "../constants";
|
|
7
|
+
|
|
8
|
+
const ruleSetNonTerminalNodesQuery = nodesQuery("/*/ruleSet");
|
|
9
|
+
|
|
10
|
+
export default class RuleSets {
|
|
11
|
+
constructor(array) {
|
|
12
|
+
this.array = array;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getLength() { return this.array.length; }
|
|
16
|
+
|
|
17
|
+
asCSS(selectorsList, outermost = false) {
|
|
18
|
+
let css = EMPTY_STRING;
|
|
19
|
+
|
|
20
|
+
const length = this.getLength(),
|
|
21
|
+
selectorsListLength = selectorsList.getLength();
|
|
22
|
+
|
|
23
|
+
if ((length > 0) && (selectorsListLength > 0)) {
|
|
24
|
+
css = this.array.reduce((css, ruleSet) => {
|
|
25
|
+
const ruleSetCSS = ruleSet.asCSS(selectorsList, outermost);
|
|
26
|
+
|
|
27
|
+
css = (css === null) ?
|
|
28
|
+
ruleSetCSS : ///
|
|
29
|
+
`${css}${ruleSetCSS}`;
|
|
30
|
+
|
|
31
|
+
return css;
|
|
32
|
+
}, null);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return css;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static fromNothing() {
|
|
39
|
+
const array = [],
|
|
40
|
+
ruleSets = new RuleSets(array);
|
|
41
|
+
|
|
42
|
+
return ruleSets;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static fromNodeAndTokens(node, tokens) {
|
|
46
|
+
const ruleSetNonTerminalNodes = ruleSetNonTerminalNodesQuery(node),
|
|
47
|
+
array = ruleSetNonTerminalNodes.map((ruleSetNonTerminalNode) => {
|
|
48
|
+
const node = ruleSetNonTerminalNode, ///
|
|
49
|
+
ruleSet = RuleSet.fromRuleSetsNodeAndTokens(RuleSets, node, tokens);
|
|
50
|
+
|
|
51
|
+
return ruleSet;
|
|
52
|
+
}),
|
|
53
|
+
ruleSets = new RuleSets(array);
|
|
54
|
+
|
|
55
|
+
return ruleSets;
|
|
56
|
+
}
|
|
57
|
+
}
|