highmark-occam 1.0.1
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/README.md +139 -0
- package/lib/blockListing.js +40 -0
- package/lib/constants.js +13 -0
- package/lib/div/container.js +44 -0
- package/lib/div/line.js +48 -0
- package/lib/div/lines.js +61 -0
- package/lib/div/syntax.js +50 -0
- package/lib/document/bnf.js +32 -0
- package/lib/document/furtle.js +37 -0
- package/lib/document/json.js +33 -0
- package/lib/document/markdown.js +45 -0
- package/lib/document/markdownStyle.js +39 -0
- package/lib/document/nominal.js +50 -0
- package/lib/document/plainText.js +28 -0
- package/lib/document.js +55 -0
- package/lib/documentTypes.js +54 -0
- package/lib/example/customGrammarsJSON/firstOrderLogic.js +28 -0
- package/lib/example/preamble.js +18 -0
- package/lib/example/view/div/column.js +24 -0
- package/lib/example/view/div/markdown.js +84 -0
- package/lib/example/view/div/sizeable.js +25 -0
- package/lib/example/view/heading.js +27 -0
- package/lib/example/view/input.js +28 -0
- package/lib/example/view/listing.js +26 -0
- package/lib/example/view/subHeading.js +29 -0
- package/lib/example/view/textarea/content.js +46 -0
- package/lib/example/view/textarea.js +30 -0
- package/lib/example/view.js +73 -0
- package/lib/example.js +23 -0
- package/lib/index.js +31 -0
- package/lib/line.js +42 -0
- package/lib/map/node/html.js +24 -0
- package/lib/node/html/listing/block.js +56 -0
- package/lib/overlay.js +65 -0
- package/lib/overlayTokenTypes.js +89 -0
- package/lib/prettyPrinter.js +55 -0
- package/lib/styles.js +22 -0
- package/lib/token/overlay/common/content.js +25 -0
- package/lib/token/overlay/common/error.js +25 -0
- package/lib/token/overlay/common/labelName.js +25 -0
- package/lib/token/overlay/common/nonsense.js +25 -0
- package/lib/token/overlay/common/procedureReferenceName.js +25 -0
- package/lib/token/overlay/common/referenceName.js +25 -0
- package/lib/token/overlay/common/stuff.js +25 -0
- package/lib/token/overlay/markdown/heading.js +25 -0
- package/lib/token/overlay/markdown/link.js +25 -0
- package/lib/token/overlay/markdown/listing.js +25 -0
- package/lib/token/overlay/markdown/path.js +25 -0
- package/lib/token/overlay/markdown/reference.js +25 -0
- package/lib/token/overlay/markdown/table.js +25 -0
- package/lib/token/overlay/markdownStyle/name.js +25 -0
- package/lib/token/overlay/markdownStyle/value.js +25 -0
- package/lib/token/overlay/nonTerminalNode.js +25 -0
- package/lib/token/overlay/terminalNode.js +25 -0
- package/lib/utilities/character.js +18 -0
- package/lib/utilities/customGrammars.js +48 -0
- package/lib/utilities/document.js +57 -0
- package/lib/utilities/grammar.js +51 -0
- package/lib/utilities/lines.js +32 -0
- package/lib/utilities/query.js +20 -0
- package/lib/utilities/tokens.js +19 -0
- package/license.txt +48 -0
- package/package.json +52 -0
- package/src/blockListing.js +39 -0
- package/src/constants.js +3 -0
- package/src/div/container.js +37 -0
- package/src/div/line.js +43 -0
- package/src/div/lines.js +68 -0
- package/src/div/syntax.js +45 -0
- package/src/document/bnf.js +27 -0
- package/src/document/furtle.js +32 -0
- package/src/document/json.js +28 -0
- package/src/document/markdown.js +40 -0
- package/src/document/markdownStyle.js +34 -0
- package/src/document/nominal.js +56 -0
- package/src/document/plainText.js +23 -0
- package/src/document.js +54 -0
- package/src/documentTypes.js +19 -0
- package/src/example/customGrammarsJSON/firstOrderLogic.js +18 -0
- package/src/example/preamble.js +13 -0
- package/src/example/view/div/column.js +11 -0
- package/src/example/view/div/markdown.js +99 -0
- package/src/example/view/div/sizeable.js +12 -0
- package/src/example/view/heading.js +14 -0
- package/src/example/view/input.js +15 -0
- package/src/example/view/listing.js +14 -0
- package/src/example/view/subHeading.js +16 -0
- package/src/example/view/textarea/content.js +43 -0
- package/src/example/view/textarea.js +17 -0
- package/src/example/view.js +93 -0
- package/src/example.js +28 -0
- package/src/index.js +5 -0
- package/src/line.js +47 -0
- package/src/map/node/html.js +13 -0
- package/src/node/html/listing/block.js +68 -0
- package/src/overlay.js +87 -0
- package/src/overlayTokenTypes.js +33 -0
- package/src/prettyPrinter.js +54 -0
- package/src/styles.js +4 -0
- package/src/token/overlay/common/content.js +11 -0
- package/src/token/overlay/common/error.js +11 -0
- package/src/token/overlay/common/labelName.js +11 -0
- package/src/token/overlay/common/nonsense.js +11 -0
- package/src/token/overlay/common/procedureReferenceName.js +11 -0
- package/src/token/overlay/common/referenceName.js +11 -0
- package/src/token/overlay/common/stuff.js +11 -0
- package/src/token/overlay/markdown/heading.js +11 -0
- package/src/token/overlay/markdown/link.js +11 -0
- package/src/token/overlay/markdown/listing.js +11 -0
- package/src/token/overlay/markdown/path.js +11 -0
- package/src/token/overlay/markdown/reference.js +11 -0
- package/src/token/overlay/markdown/table.js +11 -0
- package/src/token/overlay/markdownStyle/name.js +11 -0
- package/src/token/overlay/markdownStyle/value.js +11 -0
- package/src/token/overlay/nonTerminalNode.js +17 -0
- package/src/token/overlay/terminalNode.js +17 -0
- package/src/utilities/character.js +11 -0
- package/src/utilities/customGrammars.js +34 -0
- package/src/utilities/document.js +44 -0
- package/src/utilities/grammar.js +38 -0
- package/src/utilities/lines.js +31 -0
- package/src/utilities/query.js +13 -0
- package/src/utilities/tokens.js +12 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
{
|
|
5
|
+
"name": "Default",
|
|
6
|
+
"termBNF": "term ::= \"(\" argument \")\"\n\n | variable \n \n ;",
|
|
7
|
+
"statementBNF": "statement ::= \"(\" metaArgument \")\" \n \n | equality\n\n | judgement\n\n | typeAssertion \n \n | definedAssertion \n\n | containedAssertion \n \n | signatureAssertion\n\n | subproofAssertion \n\n | propertyAssertion \n\n | metavariable ( frameSubstitution | termSubstitution )?\n\n ;\n\nequality ::= term \"=\" term ;\n\ntypeAssertion ::= term \":\" type ;\n\ndefinedAssertion ::= ( frame | term ) \"is\" ( \"defined\" | \"undefined\" ) ;\n\ncontainedAssertion ::= ( frame | term ) \"is\" ( \"present\" | \"missing\" ) \"in\" statement ;\n\nsignatureAssertion ::= signature \"satisfies\" metavariable ; \n\nsubproofAssertion ::= \"[\" statement ( \",\" statement )* \"]\" \"...\" statement ;\n\npropertyAssertion ::= term \"is\" ( \"a\" | \"an\" ) propertyRelation ;\n\npropertyRelation ::= property \"of\" term ;\n\njudgement ::= frame \"|\"<NO_WHITESPACE>\"-\" assumption ;\n\nframe ::= \"[\" ( ( metavariable | assumption ) ( \",\" assumption )* ) \"]\" ;\n \nassumption ::= metavariable \"::\" statement ;\n\nmetaLevelAssumption ::= reference \"::\" statement ;\n\ntermSubstitution ::= \"[\" term \"for\" term \"]\" ;\n\nframeSubstitution ::= \"[\" frame \"for\" frame \"]\" ;\n\nstatementSubstitution ::= \"[\" statement \"for\" statement \"]\" ;\n\nreferenceSubstitution ::= \"[\" reference \"for\" reference \"]\" ;",
|
|
8
|
+
"typeVocabulary": "",
|
|
9
|
+
"symbolVocabulary": ""
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "first-order-logic",
|
|
13
|
+
"termBNF": "",
|
|
14
|
+
"statementBNF": "\n\n statement ::= ( \"∀\" | \"∃\" )<NO_WHITESPACE>( frameArgument | argument ) metaArgument \n\n | ( frameArgument | argument ) \"is\" ( \"𝘣𝘰𝘶𝘯𝘥\" | \"𝘧𝘳𝘦𝘦\" ) \"in\" metaArgument\n\n ;\n\n",
|
|
15
|
+
"typeVocabulary": "",
|
|
16
|
+
"symbolVocabulary": "𝘣𝘰𝘶𝘯𝘥\n𝘧𝘳𝘦𝘦\n∀\n∃\n"
|
|
17
|
+
}
|
|
18
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { customGrammarsUtilities } from "../index"; ///
|
|
4
|
+
|
|
5
|
+
import firstOrderLogicCustomGrammarsJSON from "./customGrammarsJSON/firstOrderLogic";
|
|
6
|
+
|
|
7
|
+
const { registerCustomGrammarsMap } = customGrammarsUtilities;
|
|
8
|
+
|
|
9
|
+
const customGrammarsJSONMap = {
|
|
10
|
+
"first-order-logic": firstOrderLogicCustomGrammarsJSON
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
registerCustomGrammarsMap(customGrammarsJSONMap);
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import withStyle from "easy-with-style";
|
|
4
|
+
|
|
5
|
+
import { Element } from "easy";
|
|
6
|
+
import { grammarUtilities } from "../../../index"; ///
|
|
7
|
+
|
|
8
|
+
const { topmostHTMLNodeFromDocumentMarkdownNode } = grammarUtilities;
|
|
9
|
+
|
|
10
|
+
class MarkdownDiv extends Element {
|
|
11
|
+
clear() {
|
|
12
|
+
const topmostHTMLNode = this.getTopmostHTMLNode();
|
|
13
|
+
|
|
14
|
+
if (topmostHTMLNode !== null) {
|
|
15
|
+
const domElement = this.getDOMElement(),
|
|
16
|
+
parentDOMElement = domElement, ///
|
|
17
|
+
context = null;
|
|
18
|
+
|
|
19
|
+
topmostHTMLNode.unmount(parentDOMElement, context);
|
|
20
|
+
|
|
21
|
+
this.clearTopmostHTMLNode();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
update(documentMarkdownNode, tokens) {
|
|
26
|
+
if (documentMarkdownNode === null) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const domElement = this.getDOMElement(),
|
|
31
|
+
parentDOMElement = domElement, ///
|
|
32
|
+
siblingDOMElement = null,
|
|
33
|
+
context = {
|
|
34
|
+
tokens
|
|
35
|
+
},
|
|
36
|
+
topmostHTMLNode = topmostHTMLNodeFromDocumentMarkdownNode(documentMarkdownNode);
|
|
37
|
+
|
|
38
|
+
topmostHTMLNode.mount(parentDOMElement, siblingDOMElement, context);
|
|
39
|
+
|
|
40
|
+
this.setTopmostHTMLNode(topmostHTMLNode);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
clearTopmostHTMLNode() {
|
|
44
|
+
const topmostHTMLNode = null;
|
|
45
|
+
|
|
46
|
+
this.setTopmostHTMLNode(topmostHTMLNode);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getTopmostHTMLNode() {
|
|
50
|
+
const { topmostHTMLNode } = this.getState();
|
|
51
|
+
|
|
52
|
+
return topmostHTMLNode;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
setTopmostHTMLNode(topmostHTMLNode) {
|
|
56
|
+
this.updateState({
|
|
57
|
+
topmostHTMLNode
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
setInitialState() {
|
|
62
|
+
const topmostHTMLNode = null;
|
|
63
|
+
|
|
64
|
+
this.setState({
|
|
65
|
+
topmostHTMLNode
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
parentContext() {
|
|
70
|
+
const clearMarkdownDiv = this.clear.bind(this),
|
|
71
|
+
updateMarkdownDiv = this.update.bind(this);
|
|
72
|
+
|
|
73
|
+
return ({
|
|
74
|
+
clearMarkdownDiv,
|
|
75
|
+
updateMarkdownDiv
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
initialise() {
|
|
80
|
+
this.setInitialState();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static tagName = "div";
|
|
84
|
+
|
|
85
|
+
static defaultProperties = {
|
|
86
|
+
className: "markdown"
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default withStyle(MarkdownDiv)`
|
|
91
|
+
|
|
92
|
+
width: 100%;
|
|
93
|
+
height: 100%;
|
|
94
|
+
border: 1px solid darkgrey;
|
|
95
|
+
padding: 0.25rem;
|
|
96
|
+
position: absolute;
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import withStyle from "easy-with-style"; ///
|
|
4
|
+
|
|
5
|
+
import { Input } from "easy";
|
|
6
|
+
|
|
7
|
+
export default withStyle(Input)`
|
|
8
|
+
|
|
9
|
+
border: 1px solid darkgrey;
|
|
10
|
+
padding: 0.25rem;
|
|
11
|
+
font-size: 1.2rem;
|
|
12
|
+
line-height: 1.5rem;
|
|
13
|
+
font-family: monospace;
|
|
14
|
+
|
|
15
|
+
`;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import withStyle from "easy-with-style"; ///
|
|
4
|
+
|
|
5
|
+
import Textarea from "../textarea";
|
|
6
|
+
|
|
7
|
+
class ContentTextarea extends Textarea {
|
|
8
|
+
getContent() {
|
|
9
|
+
const value = this.getValue(),
|
|
10
|
+
content = value; ///
|
|
11
|
+
|
|
12
|
+
return content;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
setContent(content) {
|
|
16
|
+
const value = content;
|
|
17
|
+
|
|
18
|
+
this.setValue(value);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
parentContext() {
|
|
22
|
+
const getContent = this.getContent.bind(this),
|
|
23
|
+
setContent = this.setContent.bind(this),
|
|
24
|
+
focusContentTextarea = this.focus.bind(this);
|
|
25
|
+
|
|
26
|
+
return ({
|
|
27
|
+
getContent,
|
|
28
|
+
setContent,
|
|
29
|
+
focusContentTextarea
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static defaultProperties = {
|
|
34
|
+
className: "content",
|
|
35
|
+
spellCheck: "false"
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default withStyle(ContentTextarea)`
|
|
40
|
+
|
|
41
|
+
height: 64rem;
|
|
42
|
+
|
|
43
|
+
`;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import withStyle from "easy-with-style"; ///
|
|
4
|
+
|
|
5
|
+
import { Textarea } from "easy";
|
|
6
|
+
|
|
7
|
+
export default withStyle(Textarea)`
|
|
8
|
+
|
|
9
|
+
border: 1px solid darkgrey;
|
|
10
|
+
resize: vertical;
|
|
11
|
+
padding: 0.25rem;
|
|
12
|
+
font-size: 1.2rem;
|
|
13
|
+
line-height: 1.5rem;
|
|
14
|
+
white-space: pre;
|
|
15
|
+
font-family: monospace;
|
|
16
|
+
|
|
17
|
+
`;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import withStyle from "easy-with-style"; ///
|
|
4
|
+
|
|
5
|
+
import { Element } from "easy";
|
|
6
|
+
import { grammarUtilities } from "../index"; ///
|
|
7
|
+
import { RowsDiv, ColumnsDiv, VerticalSplitterDiv } from "easy-layout";
|
|
8
|
+
|
|
9
|
+
import ColumnDiv from "./view/div/column";
|
|
10
|
+
import SubHeading from "./view/subHeading";
|
|
11
|
+
import SizeableDiv from "./view/div/sizeable";
|
|
12
|
+
import MarkdownDiv from "./view/div/markdown";
|
|
13
|
+
import ContentTextarea from "./view/textarea/content";
|
|
14
|
+
|
|
15
|
+
const { tokensFromMarkdown, documentMarkdownNodeFromTokens } = grammarUtilities;
|
|
16
|
+
|
|
17
|
+
class View extends Element {
|
|
18
|
+
keyUpHandler = (event, element) => {
|
|
19
|
+
this.update();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
update() {
|
|
23
|
+
const content = this.getContent(),
|
|
24
|
+
markdown = content, ///
|
|
25
|
+
tokens = tokensFromMarkdown(markdown),
|
|
26
|
+
documentMarkdownNode = documentMarkdownNodeFromTokens(tokens);
|
|
27
|
+
|
|
28
|
+
this.clearMarkdownDiv();
|
|
29
|
+
|
|
30
|
+
this.updateMarkdownDiv(documentMarkdownNode, tokens);
|
|
31
|
+
|
|
32
|
+
this.focusContentTextarea();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
didMount() {
|
|
36
|
+
this.update();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
willUnmount() {
|
|
40
|
+
///
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
childElements() {
|
|
44
|
+
return (
|
|
45
|
+
|
|
46
|
+
<ColumnsDiv>
|
|
47
|
+
<SizeableDiv>
|
|
48
|
+
<RowsDiv>
|
|
49
|
+
<SubHeading>
|
|
50
|
+
Content
|
|
51
|
+
</SubHeading>
|
|
52
|
+
<ContentTextarea onKeyUp={this.keyUpHandler} />
|
|
53
|
+
</RowsDiv>
|
|
54
|
+
</SizeableDiv>
|
|
55
|
+
<VerticalSplitterDiv/>
|
|
56
|
+
<ColumnDiv>
|
|
57
|
+
<MarkdownDiv/>
|
|
58
|
+
</ColumnDiv>
|
|
59
|
+
</ColumnsDiv>
|
|
60
|
+
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
initialise() {
|
|
65
|
+
this.assignContext();
|
|
66
|
+
|
|
67
|
+
const content = `\`\`\`nominal:first-order-logic
|
|
68
|
+
Lemma
|
|
69
|
+
Suppose
|
|
70
|
+
[F] |- R :: S
|
|
71
|
+
Then
|
|
72
|
+
∃[G] [G] |- R :: S
|
|
73
|
+
Proof
|
|
74
|
+
[G] is 𝘧𝘳𝘦𝘦 in [G] |- R :: S by FreeMetavariable
|
|
75
|
+
Therefore
|
|
76
|
+
∃[G] [G] |- R :: S by MetaExistentialIntroduction
|
|
77
|
+
\`\`\``;
|
|
78
|
+
|
|
79
|
+
this.setContent(content);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static tagName = "div";
|
|
83
|
+
|
|
84
|
+
static defaultProperties = {
|
|
85
|
+
className: "view"
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default withStyle(View)`
|
|
90
|
+
|
|
91
|
+
padding: 1rem;
|
|
92
|
+
|
|
93
|
+
`;
|
package/src/example.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import "juxtapose";
|
|
4
|
+
|
|
5
|
+
import withStyle from "easy-with-style"; ///
|
|
6
|
+
|
|
7
|
+
import { Body } from "easy";
|
|
8
|
+
import { juliaMonoStyle, prettyPrinterStyle } from "occam-styles";
|
|
9
|
+
|
|
10
|
+
import "./example/preamble";
|
|
11
|
+
|
|
12
|
+
import View from "./example/view";
|
|
13
|
+
|
|
14
|
+
const { renderStyle, renderStyles } = withStyle;
|
|
15
|
+
|
|
16
|
+
const body = new Body();
|
|
17
|
+
|
|
18
|
+
renderStyles();
|
|
19
|
+
|
|
20
|
+
renderStyle(prettyPrinterStyle);
|
|
21
|
+
|
|
22
|
+
renderStyle(juliaMonoStyle);
|
|
23
|
+
|
|
24
|
+
body.mount(
|
|
25
|
+
|
|
26
|
+
<View/>
|
|
27
|
+
|
|
28
|
+
);
|
package/src/index.js
ADDED
package/src/line.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { arrayUtilities } from "necessary";
|
|
4
|
+
|
|
5
|
+
const { push } = arrayUtilities;
|
|
6
|
+
|
|
7
|
+
export default class Line {
|
|
8
|
+
constructor(tokens, content) {
|
|
9
|
+
this.tokens = tokens;
|
|
10
|
+
this.content = content;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getTokens(tokens = []) {
|
|
14
|
+
push(tokens, this.tokens);
|
|
15
|
+
|
|
16
|
+
return tokens;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getContent() {
|
|
20
|
+
return this.content;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
tokenise(lexer) {
|
|
24
|
+
this.tokens = lexer.tokenise(this.content);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
asHTML() {
|
|
28
|
+
const html = this.tokens.reduce((html, token) => {
|
|
29
|
+
const tokenHTML = token.asHTML();
|
|
30
|
+
|
|
31
|
+
html = (html !== null) ?
|
|
32
|
+
`${html}${tokenHTML}` :
|
|
33
|
+
tokenHTML; ///
|
|
34
|
+
|
|
35
|
+
return html;
|
|
36
|
+
}, null);
|
|
37
|
+
|
|
38
|
+
return html;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static fromContent(content) {
|
|
42
|
+
const tokens = null,
|
|
43
|
+
line = new Line(tokens, content);
|
|
44
|
+
|
|
45
|
+
return line;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { htmlNodeMap as htmlNodeMapBase, markdownRuleNames } from "highmark-markdown";
|
|
4
|
+
|
|
5
|
+
import BlockListingHTMLNode from "../../node/html/listing/block";
|
|
6
|
+
|
|
7
|
+
const { BLOCK_LISTING_MARKDOWN_RULE_NAME } = markdownRuleNames;
|
|
8
|
+
|
|
9
|
+
const htmlNodeMap = Object.assign({}, htmlNodeMapBase, {
|
|
10
|
+
[BLOCK_LISTING_MARKDOWN_RULE_NAME]: BlockListingHTMLNode
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export default htmlNodeMap;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { BlockListingHTMLNode as BlockListingHTMLNodeBase } from "highmark-markdown";
|
|
4
|
+
|
|
5
|
+
import BlockListing from "../../../blockListing";
|
|
6
|
+
|
|
7
|
+
import { documentFromContentLanguageNameAndReleaseName } from "../../../utilities/document";
|
|
8
|
+
|
|
9
|
+
export default class BlockListingHTMLNode extends BlockListingHTMLNodeBase {
|
|
10
|
+
constructor(outerNode, parentNode, childNodes, domElement, blockListing) {
|
|
11
|
+
super(outerNode, parentNode, childNodes, domElement);
|
|
12
|
+
|
|
13
|
+
this.blockListing = blockListing;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getBlockListing() {
|
|
17
|
+
return this.blockListing;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
content(context) {
|
|
21
|
+
let content = super.content(context);
|
|
22
|
+
|
|
23
|
+
content = `${content}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
return content;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
mount(parentDOMElement, siblingDOMElement, context) {
|
|
30
|
+
this.blockListing = this.createBlockListing(context);
|
|
31
|
+
|
|
32
|
+
siblingDOMElement = this.blockListing.mount(parentDOMElement, siblingDOMElement, context);
|
|
33
|
+
|
|
34
|
+
return siblingDOMElement;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
unmount(parentDOMElement, context) {
|
|
38
|
+
this.blockListing.unmount(parentDOMElement, context);
|
|
39
|
+
|
|
40
|
+
this.blockListing = null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
createBlockListing(context) {
|
|
44
|
+
const content = this.content(context),
|
|
45
|
+
markdownNode = this.getMarkdownNode(),
|
|
46
|
+
languageName = markdownNode.languageName(context),
|
|
47
|
+
releaseName = markdownNode.releaseName(context),
|
|
48
|
+
document = documentFromContentLanguageNameAndReleaseName(content, languageName, releaseName),
|
|
49
|
+
properties = {},
|
|
50
|
+
blockListing = BlockListing.fromClass(properties, document);
|
|
51
|
+
|
|
52
|
+
return blockListing;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static fromNothing() {
|
|
56
|
+
const blockListing = null,
|
|
57
|
+
blockListingHTMLNode = BlockListingHTMLNodeBase.fromNothing(BlockListingHTMLNode, blockListing);
|
|
58
|
+
|
|
59
|
+
return blockListingHTMLNode;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static fromOuterNode(outerNode) {
|
|
63
|
+
const blockListing = null,
|
|
64
|
+
blockListingHTMLNode = BlockListingHTMLNodeBase.fromOuterNode(BlockListingHTMLNode, outerNode, blockListing);
|
|
65
|
+
|
|
66
|
+
return blockListingHTMLNode;
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/overlay.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { EMPTY_STRING } from "./constants";
|
|
4
|
+
import { queriesFromExpressionStrings } from "./utilities/query";
|
|
5
|
+
|
|
6
|
+
export default class Overlay {
|
|
7
|
+
constructor(weakMap) {
|
|
8
|
+
this.weakMap = weakMap;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getWeakMap() {
|
|
12
|
+
return this.weakMap;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
lineAsHTML(line) {
|
|
16
|
+
let html = EMPTY_STRING;
|
|
17
|
+
|
|
18
|
+
const tokens = line.getTokens();
|
|
19
|
+
|
|
20
|
+
tokens.forEach((token) => { ///
|
|
21
|
+
const overlayToken = this.weakMap.get(token) || null;
|
|
22
|
+
|
|
23
|
+
if (overlayToken !== null) {
|
|
24
|
+
const overlayTokenHTML = overlayToken.asHTML();
|
|
25
|
+
|
|
26
|
+
html += overlayTokenHTML;
|
|
27
|
+
} else {
|
|
28
|
+
const tokenHTML = token.asHTML();
|
|
29
|
+
|
|
30
|
+
html += tokenHTML;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return html;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return html;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static fromNodeAndOverlayTokenMap(node, overlayTokenMap) {
|
|
40
|
+
const weakMap = weakMapFromNodeAndOverlayTokenMap(node, overlayTokenMap),
|
|
41
|
+
overlay = new Overlay(weakMap);
|
|
42
|
+
|
|
43
|
+
return overlay;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function weakMapFromNodeAndOverlayTokenMap(node, overlayTokenMap) {
|
|
48
|
+
const weakMap = new WeakMap();
|
|
49
|
+
|
|
50
|
+
if (node !== null) {
|
|
51
|
+
const expressionStrings = Object.keys(overlayTokenMap),
|
|
52
|
+
OverlayTokens = Object.values(overlayTokenMap),
|
|
53
|
+
queries = queriesFromExpressionStrings(expressionStrings);
|
|
54
|
+
|
|
55
|
+
OverlayTokens.forEach((OverlayToken, index) => {
|
|
56
|
+
const query = queries[index],
|
|
57
|
+
nodes = query.execute(node);
|
|
58
|
+
|
|
59
|
+
nodes.forEach((node) => {
|
|
60
|
+
const nodeTerminalNode = node.isTerminalNode();
|
|
61
|
+
|
|
62
|
+
if (nodeTerminalNode) {
|
|
63
|
+
const terminalNode = node, ///
|
|
64
|
+
significantToken = terminalNode.getSignificantToken(),
|
|
65
|
+
content = significantToken.getContent(),
|
|
66
|
+
overlayToken = OverlayToken.fromContentAndTerminalNode(content, terminalNode),
|
|
67
|
+
overlaidToken = significantToken; ///
|
|
68
|
+
|
|
69
|
+
weakMap.set(overlaidToken, overlayToken);
|
|
70
|
+
} else {
|
|
71
|
+
const nonTerminalNode = node,
|
|
72
|
+
significantTokens = nonTerminalNode.getSignificantTokens();
|
|
73
|
+
|
|
74
|
+
significantTokens.forEach((significantToken) => {
|
|
75
|
+
const content = significantToken.getContent(),
|
|
76
|
+
overlayToken = OverlayToken.fromContentAndNonTerminalNode(content, nonTerminalNode),
|
|
77
|
+
overlaidToken = significantToken; ///
|
|
78
|
+
|
|
79
|
+
weakMap.set(overlaidToken, overlayToken);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return weakMap;
|
|
87
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export const pathOverlayTokenType = "path overlay";
|
|
4
|
+
export const nameOverlayTokenType = "name overlay";
|
|
5
|
+
export const linkOverlayTokenType = "link overlay";
|
|
6
|
+
export const valueOverlayTokenType = "value overlay";
|
|
7
|
+
export const errorOverlayTokenType = "error overlay";
|
|
8
|
+
export const tableOverlayTokenType = "table overlay";
|
|
9
|
+
export const contextOverlayTokenType = "context overlay";
|
|
10
|
+
export const listingOverlayTokenType = "listing overlay";
|
|
11
|
+
export const headingOverlayTokenType = "heading overlay";
|
|
12
|
+
export const contentOverlayTokenType = "content overlay";
|
|
13
|
+
export const nonsenseOverlayTokenType = "nonsense overlay";
|
|
14
|
+
export const labelNameOverlayTokenType = "label-name overlay";
|
|
15
|
+
export const referenceNameOverlayTokenType = "reference-name overlay";
|
|
16
|
+
export const procedureReferenceNameOverlayTokenType = "procedure-reference-name overlay";
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
pathOverlayTokenType,
|
|
20
|
+
nameOverlayTokenType,
|
|
21
|
+
linkOverlayTokenType,
|
|
22
|
+
valueOverlayTokenType,
|
|
23
|
+
errorOverlayTokenType,
|
|
24
|
+
tableOverlayTokenType,
|
|
25
|
+
contextOverlayTokenType,
|
|
26
|
+
listingOverlayTokenType,
|
|
27
|
+
headingOverlayTokenType,
|
|
28
|
+
contentOverlayTokenType,
|
|
29
|
+
nonsenseOverlayTokenType,
|
|
30
|
+
labelNameOverlayTokenType,
|
|
31
|
+
referenceNameOverlayTokenType,
|
|
32
|
+
procedureReferenceNameOverlayTokenType
|
|
33
|
+
};
|