highmark-markdown 0.0.156 → 0.0.158
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 +1504 -1162
- package/index.html +1 -0
- package/lib/constants.js +13 -4
- package/lib/example/constants.js +1 -5
- package/lib/example/view/div/sizeable/left.js +2 -2
- package/lib/example/view.js +3 -13
- package/lib/markdown/bnf.js +2 -2
- package/lib/markdown/entries.js +2 -2
- package/lib/markdown/parser.js +5 -5
- package/lib/mixins/content.js +3 -3
- package/lib/node/markdown/blockText.js +3 -3
- package/lib/node/markdown/contentsItem.js +13 -20
- package/lib/node/markdown/contentsLink.js +214 -0
- package/lib/node/markdown/contentsList.js +32 -12
- package/lib/node/markdown/division.js +25 -67
- package/lib/node/markdown/emailLink.js +2 -3
- package/lib/node/markdown/endOfLine.js +2 -2
- package/lib/node/markdown/error.js +2 -2
- package/lib/node/markdown/footnotesList.js +22 -23
- package/lib/node/markdown/heading.js +25 -1
- package/lib/node/markdown/hyperlink.js +2 -3
- package/lib/node/markdown/inlineListing.js +2 -2
- package/lib/node/markdown/inlineText.js +2 -2
- package/lib/node/markdown/line.js +4 -4
- package/lib/node/markdown/lineBreak.js +16 -2
- package/lib/node/markdown/markedText.js +5 -6
- package/lib/node/markdown.js +8 -1
- package/lib/ruleNameToHTMLMap.js +4 -1
- package/lib/ruleNames.js +6 -1
- package/lib/utilities/childNodes.js +60 -35
- package/lib/utilities/content.js +7 -6
- package/lib/utilities/contents.js +172 -0
- package/lib/utilities/node.js +31 -0
- package/lib/utilities/parser.js +21 -0
- package/lib/utilities/tokens.js +2 -2
- package/package.json +2 -2
- package/src/constants.js +1 -0
- package/src/example/constants.js +0 -1
- package/src/example/view/div/sizeable/left.js +1 -1
- package/src/example/view.js +7 -29
- package/src/markdown/bnf.js +1 -1
- package/src/markdown/entries.js +1 -1
- package/src/markdown/parser.js +1 -1
- package/src/mixins/content.js +2 -2
- package/src/node/markdown/blockText.js +8 -5
- package/src/node/markdown/contentsItem.js +14 -26
- package/src/node/markdown/contentsLink.js +162 -0
- package/src/node/markdown/contentsList.js +53 -15
- package/src/node/markdown/division.js +31 -87
- package/src/node/markdown/emailLink.js +3 -3
- package/src/node/markdown/endOfLine.js +2 -1
- package/src/node/markdown/error.js +2 -1
- package/src/node/markdown/footnotesList.js +33 -34
- package/src/node/markdown/heading.js +33 -0
- package/src/node/markdown/hyperlink.js +3 -3
- package/src/node/markdown/inlineListing.js +2 -1
- package/src/node/markdown/inlineText.js +2 -1
- package/src/node/markdown/line.js +4 -4
- package/src/node/markdown/lineBreak.js +10 -0
- package/src/node/markdown/markedText.js +6 -7
- package/src/node/markdown.js +6 -0
- package/src/ruleNameToHTMLMap.js +5 -0
- package/src/ruleNames.js +2 -0
- package/src/utilities/childNodes.js +81 -41
- package/src/utilities/content.js +7 -5
- package/src/utilities/node.js +29 -0
- package/src/utilities/tokens.js +2 -1
- package/lib/utilities/nodes.js +0 -21
- package/lib/utilities/tree.js +0 -172
- /package/src/utilities/{tree.js → contents.js} +0 -0
- /package/src/utilities/{nodes.js → parser.js} +0 -0
|
@@ -20,48 +20,47 @@ export default class FootnotesListMarkdownNode extends MarkdownNode {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
static fromDivisionMarkdownNode(divisionMarkdownNode, context) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
opacity = null;
|
|
32
|
-
|
|
33
|
-
footnotesListMarkdownNode = MarkdownNode.fromRuleNameChildNodesAndOpacity(FootnotesListMarkdownNode, ruleName, childNodes, opacity);
|
|
23
|
+
const node = divisionMarkdownNode, ///
|
|
24
|
+
linkMarkdownNodes = linkMarkdownNodesFromNode(node),
|
|
25
|
+
footnoteMarkdownNodes = footnoteMarkdownNodesFromNode(node),
|
|
26
|
+
linkMarkdownNodesLength = linkMarkdownNodes.length,
|
|
27
|
+
footnoteMarkdownNodesLength = footnoteMarkdownNodes.length;
|
|
28
|
+
|
|
29
|
+
if ((linkMarkdownNodesLength === 0) || (footnoteMarkdownNodesLength === 0)) {
|
|
30
|
+
return;
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
}
|
|
33
|
+
const identifierToFootnoteMarkdownNodeMap = {};
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
footnoteItemMarkdownNodes = [],
|
|
43
|
-
identifierToFootnoteMarkdownNodeMap = {},
|
|
44
|
-
linkMarkdownNodes = linkMarkdownNodesFromNode(node),
|
|
45
|
-
footnoteMarkdownNodes = footnoteMarkdownNodesFromNode(node);
|
|
35
|
+
footnoteMarkdownNodes.forEach((footnoteMarkdownNode) => {
|
|
36
|
+
const identifier = footnoteMarkdownNode.identifier(context);
|
|
46
37
|
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
identifierToFootnoteMarkdownNodeMap[identifier] = footnoteMarkdownNode;
|
|
39
|
+
});
|
|
49
40
|
|
|
50
|
-
|
|
51
|
-
});
|
|
41
|
+
const footnoteItemMarkdownNodes = [];
|
|
52
42
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
linkMarkdownNodes.forEach((linkMarkdownNode) => {
|
|
44
|
+
const identifier = linkMarkdownNode.identifier(context),
|
|
45
|
+
footnoteMarkdownNode = identifierToFootnoteMarkdownNodeMap[identifier] || null;
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
if (footnoteMarkdownNode !== null) {
|
|
48
|
+
const footnoteItemMarkdownNode = FootnoteItemMarkdownNode.fromFootnoteMarkdownNodeAndIdentifier(footnoteMarkdownNode, identifier);
|
|
59
49
|
|
|
60
|
-
|
|
50
|
+
footnoteItemMarkdownNodes.push(footnoteItemMarkdownNode);
|
|
61
51
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
delete identifierToFootnoteMarkdownNodeMap[identifier];
|
|
53
|
+
}
|
|
54
|
+
});
|
|
65
55
|
|
|
66
|
-
|
|
56
|
+
const ruleName = FOOTNOTES_LIST_RULE_NAME,
|
|
57
|
+
childNodes = footnoteItemMarkdownNodes, ///
|
|
58
|
+
opacity = null,
|
|
59
|
+
footnotesListMarkdownNode = MarkdownNode.fromRuleNameChildNodesAndOpacity(FootnotesListMarkdownNode, ruleName, childNodes, opacity),
|
|
60
|
+
replacementChildNode = footnotesListMarkdownNode; ///
|
|
61
|
+
|
|
62
|
+
Object.assign(context, {
|
|
63
|
+
replacementChildNode
|
|
64
|
+
});
|
|
65
|
+
}
|
|
67
66
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import MarkdownNode from "../../node/markdown";
|
|
4
|
+
import AnchorMarkdownNode from "../../node/markdown/anchor";
|
|
5
|
+
|
|
6
|
+
import { HYPHEN, EMPTY_STRING } from "../../constants";
|
|
7
|
+
import { plainTextFromChildNodes } from "../../utilities/childNodes";
|
|
4
8
|
|
|
5
9
|
export default class HeadingMarkdownNode extends MarkdownNode {
|
|
6
10
|
getLevel() {
|
|
@@ -9,5 +13,34 @@ export default class HeadingMarkdownNode extends MarkdownNode {
|
|
|
9
13
|
return level;
|
|
10
14
|
}
|
|
11
15
|
|
|
16
|
+
addAnchor(context) {
|
|
17
|
+
const identifier = this.identifier(context),
|
|
18
|
+
anchorMarkdownNode = AnchorMarkdownNode.fromIdentifier(identifier),
|
|
19
|
+
childNode = anchorMarkdownNode; ///
|
|
20
|
+
|
|
21
|
+
this.addChildNode(childNode);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
identifier(context) {
|
|
25
|
+
const childNodes = this.getChildNodes(),
|
|
26
|
+
leftTrimmed = true,
|
|
27
|
+
plainText = plainTextFromChildNodes(childNodes, context, leftTrimmed),
|
|
28
|
+
identifier = identifierFromPlainText(plainText);
|
|
29
|
+
|
|
30
|
+
return identifier;
|
|
31
|
+
}
|
|
32
|
+
|
|
12
33
|
static fromRuleNameChildNodesAndOpacity(Class, ruleName, childNodes, opacity) { return MarkdownNode.fromRuleNameChildNodesAndOpacity(Class, ruleName, childNodes, opacity); }
|
|
13
34
|
}
|
|
35
|
+
|
|
36
|
+
function identifierFromPlainText(plainText) {
|
|
37
|
+
plainText = plainText.toLowerCase(); ///
|
|
38
|
+
|
|
39
|
+
plainText = plainText.replace(/[^a-z ]/g, EMPTY_STRING);
|
|
40
|
+
|
|
41
|
+
plainText = plainText.replace(/ +/, HYPHEN);
|
|
42
|
+
|
|
43
|
+
const identifier = plainText; ///
|
|
44
|
+
|
|
45
|
+
return identifier;
|
|
46
|
+
}
|
|
@@ -83,9 +83,9 @@ class HyperlinkLinkMarkdownNode extends MarkdownNode {
|
|
|
83
83
|
const inlineText = this.inlineText(context),
|
|
84
84
|
content = (inlineText !== null) ?
|
|
85
85
|
inlineText :
|
|
86
|
-
this.content(context)
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
this.content(context),
|
|
87
|
+
textNode = document.createTextNode(content),
|
|
88
|
+
childNodeDOMElement = textNode; ///
|
|
89
89
|
|
|
90
90
|
this.insertDOMElement(childNodeDOMElement);
|
|
91
91
|
}
|
|
@@ -21,7 +21,8 @@ class InlineListingMarkdownNode extends MarkdownNode {
|
|
|
21
21
|
|
|
22
22
|
content = trim(content); ///
|
|
23
23
|
|
|
24
|
-
const
|
|
24
|
+
const textNode = document.createTextNode(content),
|
|
25
|
+
childNodeDOMElement = textNode; ///
|
|
25
26
|
|
|
26
27
|
this.insertDOMElement(childNodeDOMElement);
|
|
27
28
|
}
|
|
@@ -13,7 +13,8 @@ class InlineTextMarkdownNode extends MarkdownNode {
|
|
|
13
13
|
|
|
14
14
|
createDOMElement(context) {
|
|
15
15
|
const content = this.content(context),
|
|
16
|
-
|
|
16
|
+
textNode = document.createTextNode(content),
|
|
17
|
+
domElement = textNode; ///
|
|
17
18
|
|
|
18
19
|
this.setDOMElement(domElement);
|
|
19
20
|
|
|
@@ -8,24 +8,24 @@ const { first } = arrayUtilities;
|
|
|
8
8
|
|
|
9
9
|
export default class LineMarkdownNode extends MarkdownNode {
|
|
10
10
|
childNodesAsHTML(indent, context) {
|
|
11
|
-
const
|
|
11
|
+
const leftTrimmed = true,
|
|
12
12
|
childNodes = this.getChildNodes(),
|
|
13
13
|
firstChildNode = first(childNodes),
|
|
14
14
|
markedTextChildNode = firstChildNode, ///
|
|
15
|
-
markedTextChildNodeChildNodesHTML = markedTextChildNode.childNodesAsHTML(indent, context,
|
|
15
|
+
markedTextChildNodeChildNodesHTML = markedTextChildNode.childNodesAsHTML(indent, context, leftTrimmed),
|
|
16
16
|
childNodesHTML = `${markedTextChildNodeChildNodesHTML}\n`;
|
|
17
17
|
|
|
18
18
|
return childNodesHTML;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
createChildNodeDOMElements(context) {
|
|
22
|
-
const
|
|
22
|
+
const leftTrimmed = true,
|
|
23
23
|
domElement = this.getDOMElement(),
|
|
24
24
|
childNodes = this.getChildNodes(),
|
|
25
25
|
firstChildNode = first(childNodes),
|
|
26
26
|
markedTextChildNode = firstChildNode; ///
|
|
27
27
|
|
|
28
|
-
markedTextChildNode.createChildNodeDOMElements(domElement, context,
|
|
28
|
+
markedTextChildNode.createChildNodeDOMElements(domElement, context, leftTrimmed);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
static fromRuleNameChildNodesAndOpacity(ruleName, childNodes, opacity) { return MarkdownNode.fromRuleNameChildNodesAndOpacity(LineMarkdownNode, ruleName, childNodes, opacity); }
|
|
@@ -3,5 +3,15 @@
|
|
|
3
3
|
import MarkdownNode from "../../node/markdown";
|
|
4
4
|
|
|
5
5
|
export default class LineBreakMarkdownNode extends MarkdownNode {
|
|
6
|
+
childNodesAsHTML(indent, context) {
|
|
7
|
+
const childNodesHTML = null;
|
|
8
|
+
|
|
9
|
+
return childNodesHTML;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
createChildNodeDOMElements(context) {
|
|
13
|
+
///
|
|
14
|
+
}
|
|
15
|
+
|
|
6
16
|
static fromRuleNameChildNodesAndOpacity(ruleName, childNodes, opacity) { return MarkdownNode.fromRuleNameChildNodesAndOpacity(LineBreakMarkdownNode, ruleName, childNodes, opacity); }
|
|
7
17
|
}
|
|
@@ -5,19 +5,18 @@ import MarkdownNode from "../../node/markdown";
|
|
|
5
5
|
import { htmlFromChildNodes, domElementsFromChildNodes } from "../../utilities/childNodes";
|
|
6
6
|
|
|
7
7
|
export default class MarkedTextMarkdownNode extends MarkdownNode {
|
|
8
|
-
childNodesAsHTML(indent, context,
|
|
8
|
+
childNodesAsHTML(indent, context, leftTrimmed = false) {
|
|
9
9
|
const childNodes = this.getChildNodes(),
|
|
10
|
-
html = htmlFromChildNodes(childNodes, context,
|
|
10
|
+
html = htmlFromChildNodes(childNodes, context, leftTrimmed);
|
|
11
11
|
|
|
12
12
|
return html;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
createChildNodeDOMElements(domElement, context,
|
|
16
|
-
const parentDOMElement = domElement, ///
|
|
17
|
-
siblingDOMElement = null;
|
|
18
|
-
|
|
15
|
+
createChildNodeDOMElements(domElement, context, leftTrimmed = false) {
|
|
19
16
|
const childNodes = this.getChildNodes(),
|
|
20
|
-
domElements = domElementsFromChildNodes(childNodes, context,
|
|
17
|
+
domElements = domElementsFromChildNodes(childNodes, context, leftTrimmed),
|
|
18
|
+
parentDOMElement = domElement, ///
|
|
19
|
+
siblingDOMElement = null,
|
|
21
20
|
childNodeDOMElements = domElements; ///
|
|
22
21
|
|
|
23
22
|
childNodeDOMElements.forEach((childNodeDOMElement) => {
|
package/src/node/markdown.js
CHANGED
|
@@ -23,6 +23,12 @@ class MarkdownNode extends NonTerminalNode {
|
|
|
23
23
|
this.domElement = domElement;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
addChildNode(childNode) {
|
|
27
|
+
const childNodes = this.getChildNodes();
|
|
28
|
+
|
|
29
|
+
childNodes.push(childNode);
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
replaceChildNode(replacedChildNode, replacementChildNode) {
|
|
27
33
|
const childNodes = this.getChildNodes(),
|
|
28
34
|
index = childNodes.indexOf(replacedChildNode),
|
package/src/ruleNameToHTMLMap.js
CHANGED
|
@@ -28,6 +28,7 @@ import { LINK_RULE_NAME,
|
|
|
28
28
|
SUB_DIVISION_RULE_NAME,
|
|
29
29
|
ORDERED_LIST_RULE_NAME,
|
|
30
30
|
BLOCK_LISTING_RULE_NAME,
|
|
31
|
+
CONTENTS_LINK_RULE_NAME,
|
|
31
32
|
CONTENTS_ITEM_RULE_NAME,
|
|
32
33
|
CONTENTS_LIST_RULE_NAME,
|
|
33
34
|
FOOTNOTE_ITEM_RULE_NAME,
|
|
@@ -163,6 +164,10 @@ const ruleNameToHTMLMap = {
|
|
|
163
164
|
tagName: "pre",
|
|
164
165
|
className: "block"
|
|
165
166
|
},
|
|
167
|
+
[CONTENTS_LINK_RULE_NAME]: {
|
|
168
|
+
tagName: "a",
|
|
169
|
+
className: "contents"
|
|
170
|
+
},
|
|
166
171
|
[CONTENTS_ITEM_RULE_NAME]: {
|
|
167
172
|
tagName: "li",
|
|
168
173
|
className: "contents"
|
package/src/ruleNames.js
CHANGED
|
@@ -28,6 +28,7 @@ export const STRONG_TEXT_RULE_NAME = "strongText";
|
|
|
28
28
|
export const SUB_DIVISION_RULE_NAME = "subDivision";
|
|
29
29
|
export const ORDERED_LIST_RULE_NAME = "orderedList";
|
|
30
30
|
export const BLOCK_LISTING_RULE_NAME = "blockListing";
|
|
31
|
+
export const CONTENTS_link_RULE_NAME = "contentsLink";
|
|
31
32
|
export const CONTENTS_ITEM_RULE_NAME = "contentsItem";
|
|
32
33
|
export const CONTENTS_LIST_RULE_NAME = "contentsList";
|
|
33
34
|
export const FOOTNOTE_ITEM_RULE_NAME = "footnoteItem";
|
|
@@ -80,6 +81,7 @@ const ruleNames = {
|
|
|
80
81
|
SUB_DIVISION_RULE_NAME,
|
|
81
82
|
ORDERED_LIST_RULE_NAME,
|
|
82
83
|
BLOCK_LISTING_RULE_NAME,
|
|
84
|
+
CONTENTS_link_RULE_NAME,
|
|
83
85
|
CONTENTS_ITEM_RULE_NAME,
|
|
84
86
|
CONTENTS_LIST_RULE_NAME,
|
|
85
87
|
FOOTNOTE_ITEM_RULE_NAME,
|
|
@@ -9,7 +9,7 @@ import { contentFromMarkdownNodes } from "./content";
|
|
|
9
9
|
|
|
10
10
|
const { clear } = arrayUtilities;
|
|
11
11
|
|
|
12
|
-
export function htmlFromChildNodes(childNodes, context,
|
|
12
|
+
export function htmlFromChildNodes(childNodes, context, leftTrimmed) {
|
|
13
13
|
let html;
|
|
14
14
|
|
|
15
15
|
const htmls = [],
|
|
@@ -28,28 +28,31 @@ export function htmlFromChildNodes(childNodes, context, trimmed) {
|
|
|
28
28
|
|
|
29
29
|
plainTextMarkdownNodes.push(plainTextMarkdownNode);
|
|
30
30
|
} else {
|
|
31
|
-
|
|
31
|
+
const plainText = plainTextFromPlainTextMarkdownNodes(plainTextMarkdownNodes, context, leftTrimmed);
|
|
32
32
|
|
|
33
|
-
if (
|
|
34
|
-
|
|
33
|
+
if (plainText !== null) {
|
|
34
|
+
const html = plainText; ///
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
htmls.push(html);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const indent = null
|
|
40
|
-
|
|
41
|
-
html = markdownNode.asHTML(indent, context);
|
|
39
|
+
const indent = null,
|
|
40
|
+
html = markdownNode.asHTML(indent, context);
|
|
42
41
|
|
|
43
42
|
if (html !== null) {
|
|
44
43
|
htmls.push(html);
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
}
|
|
47
|
+
|
|
48
|
+
leftTrimmed = false;
|
|
48
49
|
});
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
const plainText = plainTextFromPlainTextMarkdownNodes(plainTextMarkdownNodes, context, leftTrimmed);
|
|
52
|
+
|
|
53
|
+
if (plainText !== null) {
|
|
54
|
+
const html = plainText; ///
|
|
51
55
|
|
|
52
|
-
if (html !== null) {
|
|
53
56
|
htmls.push(html);
|
|
54
57
|
}
|
|
55
58
|
|
|
@@ -58,7 +61,56 @@ export function htmlFromChildNodes(childNodes, context, trimmed) {
|
|
|
58
61
|
return html;
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
export function
|
|
64
|
+
export function plainTextFromChildNodes(childNodes, context, leftTrimmed) {
|
|
65
|
+
let plainText;
|
|
66
|
+
|
|
67
|
+
const plainTexts = [],
|
|
68
|
+
plainTextMarkdownNodes = [];
|
|
69
|
+
|
|
70
|
+
childNodes.forEach((childNode) => {
|
|
71
|
+
const childNodeNonTerminalNode = childNode.isNonTerminalNode();
|
|
72
|
+
|
|
73
|
+
if (childNodeNonTerminalNode) {
|
|
74
|
+
const nonTerminalNode = childNode, ///
|
|
75
|
+
markdownNode = nonTerminalNode, ///
|
|
76
|
+
markdownNodePlainTextMarkdownNode = (markdownNode instanceof PlainTextMarkdownNode);
|
|
77
|
+
|
|
78
|
+
if (markdownNodePlainTextMarkdownNode) {
|
|
79
|
+
const plainTextMarkdownNode = markdownNode; ///
|
|
80
|
+
|
|
81
|
+
plainTextMarkdownNodes.push(plainTextMarkdownNode);
|
|
82
|
+
} else {
|
|
83
|
+
plainText = plainTextFromPlainTextMarkdownNodes(plainTextMarkdownNodes, context, leftTrimmed);
|
|
84
|
+
|
|
85
|
+
if (plainText !== null) {
|
|
86
|
+
plainTexts.push(plainText);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const childNodes = markdownNode.getChildNodes();
|
|
90
|
+
|
|
91
|
+
plainText = plainTextFromChildNodes(childNodes, context, leftTrimmed);
|
|
92
|
+
|
|
93
|
+
if (plainText !== EMPTY_STRING) {
|
|
94
|
+
plainTexts.push(plainText);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
leftTrimmed = false;
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
plainText = plainTextFromPlainTextMarkdownNodes(plainTextMarkdownNodes, context, leftTrimmed);
|
|
103
|
+
|
|
104
|
+
if (plainText !== null) {
|
|
105
|
+
plainTexts.push(plainText);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
plainText = plainTexts.join(EMPTY_STRING);
|
|
109
|
+
|
|
110
|
+
return plainText;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function domElementsFromChildNodes(childNodes, context, leftTrimmed) {
|
|
62
114
|
const domElements = [],
|
|
63
115
|
plainTextMarkdownNodes = [];
|
|
64
116
|
|
|
@@ -75,14 +127,14 @@ export function domElementsFromChildNodes(childNodes, context, trimmed) {
|
|
|
75
127
|
|
|
76
128
|
plainTextMarkdownNodes.push(plainTextMarkdownNode);
|
|
77
129
|
} else {
|
|
78
|
-
const
|
|
130
|
+
const plainText = plainTextFromPlainTextMarkdownNodes(plainTextMarkdownNodes, context, leftTrimmed);
|
|
79
131
|
|
|
80
|
-
if (
|
|
81
|
-
const
|
|
132
|
+
if (plainText !== null) {
|
|
133
|
+
const content = plainText, ///
|
|
134
|
+
textNode = document.createTextNode(content),
|
|
135
|
+
domElement = textNode; ///
|
|
82
136
|
|
|
83
137
|
domElements.push(domElement);
|
|
84
|
-
|
|
85
|
-
trimmed = false;
|
|
86
138
|
}
|
|
87
139
|
|
|
88
140
|
const domElement = markdownNode.createDOMElement(context);
|
|
@@ -92,12 +144,16 @@ export function domElementsFromChildNodes(childNodes, context, trimmed) {
|
|
|
92
144
|
}
|
|
93
145
|
}
|
|
94
146
|
}
|
|
147
|
+
|
|
148
|
+
leftTrimmed = false;
|
|
95
149
|
});
|
|
96
150
|
|
|
97
|
-
const
|
|
151
|
+
const plainText = plainTextFromPlainTextMarkdownNodes(plainTextMarkdownNodes, context, leftTrimmed);
|
|
98
152
|
|
|
99
|
-
if (
|
|
100
|
-
const
|
|
153
|
+
if (plainText !== null) {
|
|
154
|
+
const content = plainText, ///
|
|
155
|
+
textNode = document.createTextNode(content),
|
|
156
|
+
domElement = textNode; ///
|
|
101
157
|
|
|
102
158
|
domElements.push(domElement);
|
|
103
159
|
}
|
|
@@ -105,36 +161,20 @@ export function domElementsFromChildNodes(childNodes, context, trimmed) {
|
|
|
105
161
|
return domElements;
|
|
106
162
|
}
|
|
107
163
|
|
|
108
|
-
function
|
|
109
|
-
let
|
|
110
|
-
|
|
111
|
-
const plainTextMarkdownNodesLength = plainTextMarkdownNodes.length;
|
|
112
|
-
|
|
113
|
-
if (plainTextMarkdownNodesLength > 0) {
|
|
114
|
-
const markdownNodes = plainTextMarkdownNodes, ///
|
|
115
|
-
content = contentFromMarkdownNodes(markdownNodes, context, trimmed);
|
|
116
|
-
|
|
117
|
-
html = content; ///
|
|
118
|
-
|
|
119
|
-
clear(plainTextMarkdownNodes);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return html;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function textDOMElementFromPlainTextMarkdownNodes(plainTextMarkdownNodes, context, trimmed) {
|
|
126
|
-
let textDOMElement = null;
|
|
164
|
+
function plainTextFromPlainTextMarkdownNodes(plainTextMarkdownNodes, context, leftTrimmed) {
|
|
165
|
+
let plainText = null;
|
|
127
166
|
|
|
128
167
|
const plainTextMarkdownNodesLength = plainTextMarkdownNodes.length;
|
|
129
168
|
|
|
130
169
|
if (plainTextMarkdownNodesLength > 0) {
|
|
131
170
|
const markdownNodes = plainTextMarkdownNodes, ///
|
|
132
|
-
|
|
171
|
+
rightTrimmed = false,
|
|
172
|
+
content = contentFromMarkdownNodes(markdownNodes, context, leftTrimmed, rightTrimmed);
|
|
133
173
|
|
|
134
|
-
|
|
174
|
+
plainText = content; ///
|
|
135
175
|
|
|
136
176
|
clear(plainTextMarkdownNodes);
|
|
137
177
|
}
|
|
138
178
|
|
|
139
|
-
return
|
|
179
|
+
return plainText;
|
|
140
180
|
}
|
package/src/utilities/content.js
CHANGED
|
@@ -7,7 +7,7 @@ import { ESCAPED_TOKEN_TYPE } from "../tokenTypes";
|
|
|
7
7
|
|
|
8
8
|
const { first, last } = arrayUtilities;
|
|
9
9
|
|
|
10
|
-
export function contentFromMarkdownNodes(markdownNodes, context,
|
|
10
|
+
export function contentFromMarkdownNodes(markdownNodes, context, leftTrimmed, rightTrimmed) {
|
|
11
11
|
let content = EMPTY_STRING;
|
|
12
12
|
|
|
13
13
|
let { tokens } = context;
|
|
@@ -25,9 +25,8 @@ export function contentFromMarkdownNodes(markdownNodes, context, trimmed = false
|
|
|
25
25
|
let firstTokenIndex = firstSignificantTokenIndex, ///
|
|
26
26
|
lastTokenIndex = lastSignificantTokenIndex; ///
|
|
27
27
|
|
|
28
|
-
if (!
|
|
29
|
-
const previousTokenIndex = firstTokenIndex - 1
|
|
30
|
-
nextTokenIndex = lastTokenIndex + 1;
|
|
28
|
+
if (!leftTrimmed) {
|
|
29
|
+
const previousTokenIndex = firstTokenIndex - 1;
|
|
31
30
|
|
|
32
31
|
if (previousTokenIndex > -1) {
|
|
33
32
|
const previousToken = tokens[previousTokenIndex],
|
|
@@ -37,8 +36,11 @@ export function contentFromMarkdownNodes(markdownNodes, context, trimmed = false
|
|
|
37
36
|
firstTokenIndex--;
|
|
38
37
|
}
|
|
39
38
|
}
|
|
39
|
+
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
if (!rightTrimmed) {
|
|
42
|
+
const tokensLength = tokens.length,
|
|
43
|
+
nextTokenIndex = lastTokenIndex + 1;
|
|
42
44
|
|
|
43
45
|
if (nextTokenIndex < tokensLength) {
|
|
44
46
|
const nextToken = tokens[nextTokenIndex],
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export function parentNodeFromNodeAndChildNode(node, childNode) {
|
|
4
|
+
let parentNode = null
|
|
5
|
+
|
|
6
|
+
const nodeNonTerminalNode = node.isNonTerminalNode();
|
|
7
|
+
|
|
8
|
+
if (nodeNonTerminalNode) {
|
|
9
|
+
const nonTerminalNode = node, ///
|
|
10
|
+
childNodes = nonTerminalNode.getChildNodes(),
|
|
11
|
+
index = childNodes.indexOf(childNode);
|
|
12
|
+
|
|
13
|
+
if (index !== -1) {
|
|
14
|
+
parentNode = node; ///
|
|
15
|
+
} else {
|
|
16
|
+
childNodes.some((childNode) => {
|
|
17
|
+
const node = childNode; ///
|
|
18
|
+
|
|
19
|
+
parentNode = parentNodeFromNodeAndChildNode(node, childNode);
|
|
20
|
+
|
|
21
|
+
if (parentNode !== null) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return parentNode;
|
|
29
|
+
}
|
package/src/utilities/tokens.js
CHANGED
|
@@ -8,7 +8,8 @@ export function replaceTokens(replacedChildNode, replacementTokens, context) {
|
|
|
8
8
|
lastSignificantTokenIndex = tokens.indexOf(lastSignificantToken),
|
|
9
9
|
firstSignificantTokenIndex = tokens.indexOf(firstSignificantToken),
|
|
10
10
|
start = firstSignificantTokenIndex, ///
|
|
11
|
-
|
|
11
|
+
end = lastSignificantTokenIndex + 1,
|
|
12
|
+
deleteCount = end - start;
|
|
12
13
|
|
|
13
14
|
tokens.splice(start, deleteCount, ...replacementTokens);
|
|
14
15
|
}
|
package/lib/utilities/nodes.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "setNonTerminalNodes", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return setNonTerminalNodes;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
var _occamparsers = require("occam-parsers");
|
|
12
|
-
var rulesFromStartRuleAndRuleMap = _occamparsers.rulesUtilities.rulesFromStartRuleAndRuleMap;
|
|
13
|
-
function setNonTerminalNodes(parser, nodeMap) {
|
|
14
|
-
var startRule = parser.getStartRule(), ruleMap = parser.getRuleMap(), rules = rulesFromStartRuleAndRuleMap(startRule, ruleMap);
|
|
15
|
-
rules.forEach(function(rule) {
|
|
16
|
-
var ruleName = rule.getName(), MarkdownNode = nodeMap[ruleName], NonTerminalNode = MarkdownNode; ///
|
|
17
|
-
rule.setNonTerminalNode(NonTerminalNode);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsaXRpZXMvbm9kZXMuanMiXSwic291cmNlc0NvbnRlbnQiOlsiXCJ1c2Ugc3RyaWN0XCI7XG5cbmltcG9ydCB7IHJ1bGVzVXRpbGl0aWVzIH0gZnJvbSBcIm9jY2FtLXBhcnNlcnNcIjtcblxuY29uc3QgeyBydWxlc0Zyb21TdGFydFJ1bGVBbmRSdWxlTWFwIH0gPSBydWxlc1V0aWxpdGllcztcblxuZXhwb3J0IGZ1bmN0aW9uIHNldE5vblRlcm1pbmFsTm9kZXMocGFyc2VyLCBub2RlTWFwKSB7XG4gIGNvbnN0IHN0YXJ0UnVsZSA9IHBhcnNlci5nZXRTdGFydFJ1bGUoKSxcbiAgICAgICAgcnVsZU1hcCA9IHBhcnNlci5nZXRSdWxlTWFwKCksXG4gICAgICAgIHJ1bGVzID0gcnVsZXNGcm9tU3RhcnRSdWxlQW5kUnVsZU1hcChzdGFydFJ1bGUsIHJ1bGVNYXApO1xuXG4gIHJ1bGVzLmZvckVhY2goKHJ1bGUpID0+IHtcbiAgICBjb25zdCBydWxlTmFtZSA9IHJ1bGUuZ2V0TmFtZSgpLFxuICAgICAgICAgIE1hcmtkb3duTm9kZSA9IG5vZGVNYXBbcnVsZU5hbWVdLFxuICAgICAgICAgIE5vblRlcm1pbmFsTm9kZSA9IE1hcmtkb3duTm9kZTsgLy8vXG5cbiAgICBydWxlLnNldE5vblRlcm1pbmFsTm9kZShOb25UZXJtaW5hbE5vZGUpO1xuICB9KTtcbn1cbiJdLCJuYW1lcyI6WyJzZXROb25UZXJtaW5hbE5vZGVzIiwicnVsZXNGcm9tU3RhcnRSdWxlQW5kUnVsZU1hcCIsInJ1bGVzVXRpbGl0aWVzIiwicGFyc2VyIiwibm9kZU1hcCIsInN0YXJ0UnVsZSIsImdldFN0YXJ0UnVsZSIsInJ1bGVNYXAiLCJnZXRSdWxlTWFwIiwicnVsZXMiLCJmb3JFYWNoIiwicnVsZSIsInJ1bGVOYW1lIiwiZ2V0TmFtZSIsIk1hcmtkb3duTm9kZSIsIk5vblRlcm1pbmFsTm9kZSIsInNldE5vblRlcm1pbmFsTm9kZSJdLCJyYW5nZU1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7IiwibWFwcGluZ3MiOiJBQUFBOzs7OytCQU1nQkE7OztlQUFBQTs7OzRCQUplO0FBRS9CLElBQU0sQUFBRUMsK0JBQWlDQyw0QkFBYyxDQUEvQ0Q7QUFFRCxTQUFTRCxvQkFBb0JHLE1BQU0sRUFBRUMsT0FBTztJQUNqRCxJQUFNQyxZQUFZRixPQUFPRyxZQUFZLElBQy9CQyxVQUFVSixPQUFPSyxVQUFVLElBQzNCQyxRQUFRUiw2QkFBNkJJLFdBQVdFO0lBRXRERSxNQUFNQyxPQUFPLENBQUMsU0FBQ0M7UUFDYixJQUFNQyxXQUFXRCxLQUFLRSxPQUFPLElBQ3ZCQyxlQUFlVixPQUFPLENBQUNRLFNBQVMsRUFDaENHLGtCQUFrQkQsY0FBYyxHQUFHO1FBRXpDSCxLQUFLSyxrQkFBa0IsQ0FBQ0Q7SUFDMUI7QUFDRiJ9
|