highmark-markdown 0.0.2 → 0.0.3

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.
Files changed (73) hide show
  1. package/example.js +752 -618
  2. package/lib/example/view/textarea/bnf.js +3 -10
  3. package/lib/example/view/textarea/lexicalEntries.js +3 -16
  4. package/lib/example/view/textarea/parseTree.js +3 -3
  5. package/lib/example/view/{div/previewPane.js → xmp.js} +13 -65
  6. package/lib/example/view.js +11 -19
  7. package/lib/mixins/content.js +5 -5
  8. package/lib/node/markdown/anchor.js +12 -29
  9. package/lib/node/markdown/blockListing.js +32 -5
  10. package/lib/node/markdown/blockText.js +9 -2
  11. package/lib/node/markdown/document.js +26 -5
  12. package/lib/node/markdown/endOfLine.js +11 -4
  13. package/lib/node/markdown/error.js +9 -34
  14. package/lib/node/markdown/footnote.js +4 -4
  15. package/lib/node/markdown/footnoteItem.js +3 -3
  16. package/lib/node/markdown/footnotesList.js +10 -10
  17. package/lib/node/markdown/hyperlink.js +20 -38
  18. package/lib/node/markdown/image.js +27 -38
  19. package/lib/node/markdown/inlineListing.js +2 -12
  20. package/lib/node/markdown/inlineText.js +9 -2
  21. package/lib/node/markdown/line.js +11 -4
  22. package/lib/node/markdown/link.js +24 -48
  23. package/lib/node/markdown/orderedList.js +9 -33
  24. package/lib/node/markdown/orderedListItem.js +3 -3
  25. package/lib/node/markdown/reference.js +4 -4
  26. package/lib/node/markdown/stronglyEmphasisedText.js +12 -3
  27. package/lib/node/markdown/tableBodyCell.js +8 -1
  28. package/lib/node/markdown/tableCell.js +31 -8
  29. package/lib/node/markdown/tableHeadCell.js +8 -1
  30. package/lib/node/markdown/text.js +3 -3
  31. package/lib/node/markdown/verticalSpace.js +9 -5
  32. package/lib/node/markdown.js +109 -14
  33. package/lib/ruleNameToHTMLMap.js +2 -2
  34. package/lib/utilities/childNodes.js +53 -4
  35. package/lib/utilities/link.js +32 -6
  36. package/lib/utilities/string.js +52 -0
  37. package/package.json +1 -1
  38. package/src/example/view/textarea/bnf.js +2 -10
  39. package/src/example/view/textarea/lexicalEntries.js +2 -18
  40. package/src/example/view/textarea/parseTree.js +2 -2
  41. package/src/example/view/xmp.js +28 -0
  42. package/src/example/view.js +26 -35
  43. package/src/mixins/content.js +2 -2
  44. package/src/node/markdown/anchor.js +8 -6
  45. package/src/node/markdown/blockListing.js +9 -3
  46. package/src/node/markdown/blockText.js +8 -1
  47. package/src/node/markdown/document.js +30 -5
  48. package/src/node/markdown/endOfLine.js +9 -2
  49. package/src/node/markdown/error.js +12 -11
  50. package/src/node/markdown/footnote.js +2 -2
  51. package/src/node/markdown/footnoteItem.js +1 -1
  52. package/src/node/markdown/footnotesList.js +11 -9
  53. package/src/node/markdown/hyperlink.js +21 -20
  54. package/src/node/markdown/image.js +25 -17
  55. package/src/node/markdown/inlineListing.js +0 -13
  56. package/src/node/markdown/inlineText.js +8 -1
  57. package/src/node/markdown/line.js +14 -6
  58. package/src/node/markdown/link.js +24 -25
  59. package/src/node/markdown/orderedList.js +7 -11
  60. package/src/node/markdown/orderedListItem.js +1 -1
  61. package/src/node/markdown/reference.js +4 -4
  62. package/src/node/markdown/stronglyEmphasisedText.js +14 -4
  63. package/src/node/markdown/tableBodyCell.js +9 -0
  64. package/src/node/markdown/tableCell.js +36 -7
  65. package/src/node/markdown/tableHeadCell.js +9 -0
  66. package/src/node/markdown/text.js +1 -1
  67. package/src/node/markdown/verticalSpace.js +7 -8
  68. package/src/node/markdown.js +148 -11
  69. package/src/ruleNameToHTMLMap.js +1 -1
  70. package/src/utilities/childNodes.js +62 -0
  71. package/src/utilities/link.js +48 -5
  72. package/src/utilities/string.js +55 -0
  73. package/src/example/view/div/previewPane.js +0 -82
@@ -4,50 +4,49 @@ import { arrayUtilities } from "necessary";
4
4
 
5
5
  import MarkdownNode from "../../node/markdown";
6
6
 
7
- import { EMPTY_STRING } from "../../constants";
8
7
  import { HREF_ATTRIBUTE_NAME } from "../../attributeNames";
9
8
 
10
9
  const { second } = arrayUtilities;
11
10
 
12
11
  export default class LinkMarkdownNode extends MarkdownNode {
13
- createDOMElement(context) {
14
- const domElement = super.createDOMElement(context),
15
- href = this.getHRef(),
16
- name = HREF_ATTRIBUTE_NAME,
17
- value = href; ///
12
+ asHTML(indent, context, number = null) {
13
+ let html;
18
14
 
19
- this.setAttribute(name, value);
15
+ if (number === null) {
16
+ const selfClosingTag = this.selfClosingTag(context);
20
17
 
21
- return domElement;
18
+ html = selfClosingTag; ///
19
+ } else {
20
+ const startingTag = this.startingTag(context),
21
+ closingTag = this.closingTag(context);
22
+
23
+ html = `${startingTag}${number}${closingTag}`;
24
+ }
25
+
26
+ return html;
22
27
  }
23
28
 
24
- getIdentifier() {
29
+ identifier(context) {
25
30
  const childNodes = this.getChildNodes(),
26
31
  secondChildNode = second(childNodes),
27
- textMarkdownNode = secondChildNode, ///
28
- textMarkdownNodeContent = textMarkdownNode.getContent(),
29
- identifier = textMarkdownNodeContent; ///
32
+ identifierTerminalNode = secondChildNode, ///
33
+ identifierTerminalNodeContent = identifierTerminalNode.getContent(),
34
+ identifier = identifierTerminalNodeContent; ///
30
35
 
31
36
  return identifier;
32
37
  }
33
38
 
34
- getHRef() {
35
- const identifier = this.getIdentifier(),
36
- href = `#${identifier}`;
37
-
38
- return href;
39
- }
40
-
41
- clear() {
42
- const innerHTML = EMPTY_STRING;
39
+ attributeName() {
40
+ const attributeName = HREF_ATTRIBUTE_NAME;
43
41
 
44
- this.setInnerHTML(innerHTML);
42
+ return attributeName;
45
43
  }
46
44
 
47
- setNumber(number) {
48
- const innerHTML = `${number}`;
45
+ attributeValue(context) {
46
+ const identifier = this.identifier(context),
47
+ attributeValue = `#${identifier}`; ///
49
48
 
50
- this.setInnerHTML(innerHTML);
49
+ return attributeValue;
51
50
  }
52
51
 
53
52
  static fromRuleNameChildNodesAndAmbiguous(ruleName, childNodes, ambiguous) { return MarkdownNode.fromRuleNameChildNodesAndAmbiguous(LinkMarkdownNode, ruleName, childNodes, ambiguous); }
@@ -9,24 +9,20 @@ import { START_ATTRIBUTE_NAME } from "../../attributeNames";
9
9
  const { first } = arrayUtilities;
10
10
 
11
11
  export default class OrderedListMarkdownNode extends MarkdownNode {
12
- createDOMElement(context) {
13
- const domElement = super.createDOMElement(context),
14
- start = this.getStart(),
15
- name = START_ATTRIBUTE_NAME, ///
16
- value = start; ///
12
+ attributeName() {
13
+ const attributeName = START_ATTRIBUTE_NAME;
17
14
 
18
- this.setAttribute(name, value);
19
-
20
- return domElement;
15
+ return attributeName;
21
16
  }
22
17
 
23
- getStart() {
18
+ attributeValue(context) {
24
19
  const childNodes = this.getChildNodes(),
25
20
  firstChildNode = first(childNodes),
26
21
  firstOrderedListItemMarkdownNode = firstChildNode, ///
27
- start = firstOrderedListItemMarkdownNode.getStart();
22
+ start = firstOrderedListItemMarkdownNode.start(),
23
+ attributeValue = start; ///
28
24
 
29
- return start;
25
+ return attributeValue;
30
26
  }
31
27
 
32
28
  static fromRuleNameChildNodesAndAmbiguous(ruleName, childNodes, ambiguous) { return MarkdownNode.fromRuleNameChildNodesAndAmbiguous(OrderedListMarkdownNode, ruleName, childNodes, ambiguous); }
@@ -7,7 +7,7 @@ import MarkdownNode from "../../node/markdown";
7
7
  const { first } = arrayUtilities;
8
8
 
9
9
  export default class OrderedListItemMarkdownNode extends MarkdownNode {
10
- getStart() {
10
+ start() {
11
11
  const childNodes = this.getChildNodes(),
12
12
  firstChildNode = first(childNodes),
13
13
  markerTerminalNode = firstChildNode, ///
@@ -7,12 +7,12 @@ import MarkdownNode from "../../node/markdown";
7
7
  const { second } = arrayUtilities;
8
8
 
9
9
  export default class ReferenceMarkdownNode extends MarkdownNode {
10
- getIdentifier() {
10
+ identifier(context) {
11
11
  const childNodes = this.getChildNodes(),
12
12
  secondChildNode = second(childNodes),
13
- textMarkdownNode = secondChildNode, ///
14
- textMarkdownNodeContent = textMarkdownNode.getContent(),
15
- identifier = textMarkdownNodeContent; ///
13
+ identiierTerminalNode = secondChildNode, ///
14
+ identiierTerminalNodeContent = identiierTerminalNode.getContent(),
15
+ identifier = identiierTerminalNodeContent; ///
16
16
 
17
17
  return identifier;
18
18
  }
@@ -7,15 +7,25 @@ import ruleNameToHTMLMap from "../../ruleNameToHTMLMap";
7
7
 
8
8
  import { STRONG_TEXT_RULE_NAME } from "../../ruleNames";
9
9
 
10
- const strongTextHTML = ruleNameToHTMLMap[STRONG_TEXT_RULE_NAME],
11
- { tagName: strongTextTagName } = strongTextHTML;
10
+ const { tagName } = ruleNameToHTMLMap[STRONG_TEXT_RULE_NAME];
12
11
 
13
12
  class StronglyEmphasisedTextMarkdownNode extends MarkdownNode {
13
+ asHTML(indent, context) {
14
+ let html = super.asHTML(indent, context);
15
+
16
+ const childNodesHTML = html, ///
17
+ startingTag = `<${tagName}>`,
18
+ closingTag = `<\\${tagName}>`;
19
+
20
+ html = `${startingTag}${childNodesHTML}${closingTag}`;
21
+
22
+ return html;
23
+ }
24
+
14
25
  createDOMElement(context) {
15
26
  let domElement = super.createDOMElement(context);
16
27
 
17
- const childDOMElement = domElement, ///
18
- tagName = strongTextTagName; ///
28
+ const childDOMElement = domElement; ///
19
29
 
20
30
  domElement = document.createElement(tagName);
21
31
 
@@ -7,6 +7,15 @@ import MarkdownNode from "../../node/markdown";
7
7
  const { first } = arrayUtilities;
8
8
 
9
9
  export default class TableBodyCellMarkdownNode extends MarkdownNode {
10
+ childNodesAsHTML(indent, context) {
11
+ const childNodes = this.getChildNodes(),
12
+ firstChildNode = first(childNodes),
13
+ tableCellMarkdownNode = firstChildNode, ///
14
+ childNodesHTML = tableCellMarkdownNode.childNodesAsHTML(indent, context);
15
+
16
+ return childNodesHTML;
17
+ }
18
+
10
19
  createChildNodeDOMElements(context) {
11
20
  const domElement = this.getDOMElement(),
12
21
  childNodes = this.getChildNodes(),
@@ -6,12 +6,14 @@ import MarkdownNode from "../../node/markdown";
6
6
  import TextMarkdownNode from "./text";
7
7
 
8
8
  import { PERIOD } from "../../constants";
9
- import { domElementsFromChildNodes } from "../../utilities/childNodes";
9
+ import { htmlFromChildNodes, domElementsFromChildNodes } from "../../utilities/childNodes";
10
10
 
11
11
  const { first } = arrayUtilities;
12
12
 
13
13
  export default class TableCellMarkdownNode extends MarkdownNode {
14
- createChildNodeDOMElements(domElement, context) {
14
+ isEmpty(context) {
15
+ let empty = false;
16
+
15
17
  const childNodes = this.getChildNodes(),
16
18
  childNodesLength = childNodes.length;
17
19
 
@@ -21,20 +23,47 @@ export default class TableCellMarkdownNode extends MarkdownNode {
21
23
 
22
24
  if (firstChildNodeTextMarkdownNode) {
23
25
  const textMarkdownNode = firstChildNode, ///
24
- content = textMarkdownNode.getContent();
26
+ content = textMarkdownNode.content(context);
25
27
 
26
28
  if (content === PERIOD) {
27
- return;
29
+ empty = true;
28
30
  }
29
31
  }
30
32
  }
31
33
 
32
- const domElements = domElementsFromChildNodes(childNodes, context),
34
+ return empty;
35
+ }
36
+
37
+ childNodesAsHTML(indent, context) {
38
+ let childNodesHTML = null;
39
+
40
+ const empty = this.isEmpty(context);
41
+
42
+ if (!empty) {
43
+ const childNodes = this.getChildNodes(),
44
+ html = htmlFromChildNodes(childNodes, context);
45
+
46
+ childNodesHTML = html; ///
47
+ }
48
+
49
+ return childNodesHTML;
50
+ }
51
+
52
+ createChildNodeDOMElements(domElement, context) {
53
+ const empty = this.isEmpty(context);
54
+
55
+ if (empty) {
56
+ return;
57
+ }
58
+
59
+ const childNodes = this.getChildNodes(),
60
+ domElements = domElementsFromChildNodes(childNodes, context),
33
61
  parentDOMElement = domElement, ///
62
+ childDOMElements = domElements, ///
34
63
  siblingDOMElement = null;
35
64
 
36
- domElements.forEach((domElement) => {
37
- parentDOMElement.insertBefore(domElement, siblingDOMElement);
65
+ childDOMElements.forEach((childDOMElement) => {
66
+ parentDOMElement.insertBefore(childDOMElement, siblingDOMElement);
38
67
  });
39
68
  }
40
69
 
@@ -7,6 +7,15 @@ import MarkdownNode from "../../node/markdown";
7
7
  const { first } = arrayUtilities;
8
8
 
9
9
  export default class TableHeadCellMarkdownNode extends MarkdownNode {
10
+ childNodesAsHTML(indent, context) {
11
+ const childNodes = this.getChildNodes(),
12
+ firstChildNode = first(childNodes),
13
+ tableCellMarkdownNode = firstChildNode, ///
14
+ childNodesHTML = tableCellMarkdownNode.childNodesAsHTML(indent, context);
15
+
16
+ return childNodesHTML;
17
+ }
18
+
10
19
  createChildNodeDOMElements(context) {
11
20
  const domElement = this.getDOMElement(),
12
21
  childNodes = this.getChildNodes(),
@@ -7,7 +7,7 @@ import MarkdownNode from "../../node/markdown";
7
7
  const { first } = arrayUtilities;
8
8
 
9
9
  export default class TextMarkdownNode extends MarkdownNode {
10
- getContent() {
10
+ content(context) {
11
11
  const childNodes = this.getChildNodes(),
12
12
  firstChildNode = first(childNodes),
13
13
  terminalNode = firstChildNode, ///
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
 
3
- import contentMixins from "../../mixins/content";
4
-
5
3
  import MarkdownNode from "../../node/markdown";
6
4
 
7
5
  class VerticalSpaceMarkdownNode extends MarkdownNode {
8
- createDOMElement(context) {
9
- const content = this.getContent(context),
10
- domElement = document.createTextNode(content);
6
+ asHTML(index, context) {
7
+ const html = null;
8
+
9
+ return html;
10
+ }
11
11
 
12
- this.setDOMElement(domElement);
12
+ createDOMElement(context) {
13
+ const domElement = null;
13
14
 
14
15
  return domElement;
15
16
  }
@@ -17,6 +18,4 @@ class VerticalSpaceMarkdownNode extends MarkdownNode {
17
18
  static fromRuleNameChildNodesAndAmbiguous(ruleName, childNodes, ambiguous) { return MarkdownNode.fromRuleNameChildNodesAndAmbiguous(VerticalSpaceMarkdownNode, ruleName, childNodes, ambiguous); }
18
19
  }
19
20
 
20
- Object.assign(VerticalSpaceMarkdownNode.prototype, contentMixins);
21
-
22
21
  export default VerticalSpaceMarkdownNode;
@@ -6,6 +6,9 @@ import nodeMixins from "../mixins/node";
6
6
  import elementMixins from "../mixins/element";
7
7
  import ruleNameToHTMLMap from "../ruleNameToHTMLMap";
8
8
 
9
+ import { trim } from "../utilities/string";
10
+ import { EMPTY_STRING } from "../constants";
11
+
9
12
  class MarkdownNode extends NonTerminalNode {
10
13
  constructor(ruleName, childNodes, precedence, ambiguous, domElement) {
11
14
  super(ruleName, childNodes, precedence, ambiguous);
@@ -22,22 +25,149 @@ class MarkdownNode extends NonTerminalNode {
22
25
  }
23
26
 
24
27
  getTagName() {
25
- const html = ruleNameToHTMLMap[this.ruleName],
26
- { tagName } = html;
28
+ const { tagName } = ruleNameToHTMLMap[this.ruleName];
27
29
 
28
30
  return tagName;
29
31
  }
30
32
 
31
33
  getClassName() {
32
- const html = ruleNameToHTMLMap[this.ruleName],
33
- { className } = html;
34
+ const { className } = ruleNameToHTMLMap[this.ruleName];
34
35
 
35
36
  return className;
36
37
  }
37
38
 
38
- setInnerHTML(innerHTML) { this.domElement.innerHTML = innerHTML; }
39
+ attributeName() {
40
+ const attributeName = null;
41
+
42
+ return attributeName;
43
+ }
44
+
45
+ attributeValue(context) {
46
+ const attributeValue = null;
47
+
48
+ return attributeValue;
49
+ }
50
+
51
+ asHTML(indent, context) {
52
+ if (context === undefined) {
53
+ context = indent; ///
54
+
55
+ indent = EMPTY_STRING;
56
+ }
57
+
58
+ const tagName = this.getTagName();
59
+
60
+ let html = null;
61
+
62
+ if (tagName !== null) {
63
+ indent = this.adjustIndent(indent);
64
+
65
+ const childNodesHTML = this.childNodesAsHTML(indent, context);
66
+
67
+ if (childNodesHTML !== null) {
68
+ const startingTag = this.startingTag(context),
69
+ closingTag = this.closingTag(context);
70
+
71
+ html = (indent === null) ?
72
+ `${startingTag}${trim(childNodesHTML)}${closingTag}` :
73
+ `${indent}${startingTag}
74
+ ${trim(childNodesHTML)}
75
+ ${indent}${closingTag}
76
+ `;
77
+ } else {
78
+ const selfClosingTag = this.selfClosingTag(context);
79
+
80
+ html = (indent === null) ?
81
+ selfClosingTag : ///
82
+ `${indent}${selfClosingTag}
83
+ `;
84
+ }
85
+ }
86
+
87
+ return html;
88
+ }
89
+
90
+ closingTag(context) {
91
+ const tagName = this.getTagName(),
92
+ closingTag = `<\\${tagName}>`;
93
+
94
+ return closingTag;
95
+ }
96
+
97
+ startingTag(context) {
98
+ const tagName = this.getTagName(),
99
+ className = this.getClassName(),
100
+ attributeName = this.attributeName();
101
+
102
+ let classHTML = EMPTY_STRING,
103
+ attributeHTML = EMPTY_STRING;
104
+
105
+ if (className !== null) {
106
+ classHTML = ` class="${className}"`;
107
+ }
108
+
109
+ if (attributeName !== null) {
110
+ const attributeValue = this.attributeValue(context);
111
+
112
+ attributeHTML = ` ${attributeName}="${attributeValue}"`;
113
+ }
39
114
 
40
- setAttribute(name, value) { this.domElement.setAttribute(name, value); }
115
+ const startingTag = `<${tagName}${classHTML}${attributeHTML}>`;
116
+
117
+ return startingTag;
118
+ }
119
+
120
+ selfClosingTag(context) {
121
+ const tagName = this.getTagName(),
122
+ className = this.getClassName(),
123
+ attributeName = this.attributeName();
124
+
125
+ let classHTML = EMPTY_STRING,
126
+ attributeHTML = EMPTY_STRING;
127
+
128
+ if (className !== null) {
129
+ classHTML = ` class="${className}"`;
130
+ }
131
+
132
+ if (attributeName !== null) {
133
+ const attributeValue = this.attributeValue(context);
134
+
135
+ attributeHTML = ` ${attributeName}="${attributeValue}"`;
136
+ }
137
+
138
+ const selfClosingTag = `<${tagName}${classHTML}${attributeHTML}/>`;
139
+
140
+ return selfClosingTag;
141
+ }
142
+
143
+ adjustIndent(indent) {
144
+ if (indent !== null) {
145
+ indent = ` ${indent}`;
146
+ }
147
+
148
+ return indent;
149
+ }
150
+
151
+ childNodesAsHTML(indent, context) {
152
+ const childNodes = this.getChildNodes(),
153
+ childNodesHTML = childNodes.reduce((childNodesHTML, childNode) => {
154
+ const childNodeNonTerminalNode = childNode.isNonTerminalNode();
155
+
156
+ if (childNodeNonTerminalNode) {
157
+ const childNodeHTML = childNode.asHTML(indent, context);
158
+
159
+ if (childNodeHTML !== null) {
160
+ childNodesHTML = (childNodesHTML === null) ?
161
+ childNodeHTML : ///
162
+ `${childNodesHTML}${childNodeHTML}`;
163
+ }
164
+ }
165
+
166
+ return childNodesHTML;
167
+ }, null);
168
+
169
+ return childNodesHTML;
170
+ }
41
171
 
42
172
  createDOMElement(context) {
43
173
  let domElement = null;
@@ -47,7 +177,10 @@ class MarkdownNode extends NonTerminalNode {
47
177
  if (tagName !== null) {
48
178
  domElement = document.createElement(tagName);
49
179
 
50
- const className = this.getClassName();
180
+ this.setDOMElement(domElement);
181
+
182
+ const className = this.getClassName(),
183
+ attributeName = this.attributeName();
51
184
 
52
185
  if (className !== null) {
53
186
  Object.assign(domElement, {
@@ -55,7 +188,11 @@ class MarkdownNode extends NonTerminalNode {
55
188
  });
56
189
  }
57
190
 
58
- this.setDOMElement(domElement);
191
+ if (attributeName !== null) {
192
+ const attributeValue = this.attributeValue(context);
193
+
194
+ domElement.setAttribute(attributeName, attributeValue);
195
+ }
59
196
 
60
197
  this.createChildNodeDOMElements(context);
61
198
  }
@@ -70,10 +207,10 @@ class MarkdownNode extends NonTerminalNode {
70
207
  const childNodeNonTerminalNode = childNode.isNonTerminalNode();
71
208
 
72
209
  if (childNodeNonTerminalNode) {
73
- const domElement = childNode.createDOMElement(context);
210
+ const childNodeDOMElement = childNode.createDOMElement(context);
74
211
 
75
- if (domElement !== null) {
76
- this.insertDOMElement(domElement);
212
+ if (childNodeDOMElement !== null) {
213
+ this.insertDOMElement(childNodeDOMElement);
77
214
  }
78
215
  }
79
216
  });
@@ -75,7 +75,7 @@ const ruleNameToHTMLMap = {
75
75
  className: "error"
76
76
  },
77
77
  [ANCHOR_RULE_NAME]: {
78
- tagName: "A",
78
+ tagName: "a",
79
79
  className: "anchor"
80
80
  },
81
81
  [DOCUMENT_RULE_NAME]: {
@@ -4,6 +4,7 @@ import { arrayUtilities } from "necessary";
4
4
 
5
5
  import TextMarkdownNode from "../node/markdown/text";
6
6
 
7
+ import { EMPTY_STRING } from "../constants";
7
8
  import { contentFromMarkdownNodes } from "./content";
8
9
 
9
10
  const { clear } = arrayUtilities;
@@ -51,6 +52,51 @@ export function domElementsFromChildNodes(childNodes, context) {
51
52
  return domElements;
52
53
  }
53
54
 
55
+ export function htmlFromChildNodes(childNodes, context) {
56
+ let html;
57
+
58
+ const htmls = [],
59
+ textMarkdownNodes = [];
60
+
61
+ childNodes.forEach((childNode) => {
62
+ const childNodeNonTerminalNode = childNode.isNonTerminalNode();
63
+
64
+ if (childNodeNonTerminalNode) {
65
+ const childNodeTextMarkdownNode = (childNode instanceof TextMarkdownNode);
66
+
67
+ if (childNodeTextMarkdownNode) {
68
+ const textMarkdownNode = childNode; ///
69
+
70
+ textMarkdownNodes.push(textMarkdownNode);
71
+ } else {
72
+ html = htmlFromTextMarkdownNodes(textMarkdownNodes, context)
73
+
74
+ if (html !== null) {
75
+ htmls.push(html);
76
+ }
77
+
78
+ const indent = null;
79
+
80
+ html = childNode.asHTML(indent, context);
81
+
82
+ if (html !== null) {
83
+ htmls.push(html);
84
+ }
85
+ }
86
+ }
87
+ });
88
+
89
+ html = htmlFromTextMarkdownNodes(textMarkdownNodes, context)
90
+
91
+ if (html !== null) {
92
+ htmls.push(html);
93
+ }
94
+
95
+ html = htmls.join(EMPTY_STRING);
96
+
97
+ return html;
98
+ }
99
+
54
100
  function textDOMElementFromTextMarkdownNodes(textMarkdownNodes, context) {
55
101
  let textDOMElement = null;
56
102
 
@@ -68,3 +114,19 @@ function textDOMElementFromTextMarkdownNodes(textMarkdownNodes, context) {
68
114
  return textDOMElement;
69
115
  }
70
116
 
117
+ function htmlFromTextMarkdownNodes(textMarkdownNodes, context) {
118
+ let html = null;
119
+
120
+ const textMarkdownNodesLength = textMarkdownNodes.length;
121
+
122
+ if (textMarkdownNodesLength > 0) {
123
+ const markdownNodes = textMarkdownNodes, ///
124
+ content = contentFromMarkdownNodes(markdownNodes, context);
125
+
126
+ html = content;
127
+
128
+ clear(textMarkdownNodes);
129
+ }
130
+
131
+ return html;
132
+ }
@@ -1,24 +1,67 @@
1
1
  "use strict";
2
2
 
3
+ import { stringUtilities } from "necessary";
4
+
5
+ import { EMPTY_STRING } from "../constants";
6
+ import { chop, splice } from "../utilities/string";
3
7
  import { linkMarkdownNodesFromNode } from "../utilities/query";
4
8
 
5
- export function renumberLinkMarkdownNodes(documentMarkdownNode, footnotesListMarkdownNode) {
9
+ const { strlen, indexOf } = stringUtilities;
10
+
11
+ export function renumberLinkMarkdownNodesHTML(childNodesHTML, documentMarkdownNode, footnotesListMarkdownNode, context) {
12
+ let number = 1;
13
+
14
+ const identifiers = footnotesListMarkdownNode.identifiers(),
15
+ linkMarkdownNodes = linkMarkdownNodesFromNode(documentMarkdownNode);
16
+
17
+ linkMarkdownNodes.forEach((linkMarkdownNode) => {
18
+ const indent = null,
19
+ identifier = linkMarkdownNode.identifier(context),
20
+ identifiersIncludesIdentifier = identifiers.includes(identifier),
21
+ linkMarkdownNodeHTML = linkMarkdownNode.asHTML(indent, context),
22
+ index = indexOf(childNodesHTML, linkMarkdownNodeHTML),
23
+ length = strlen(linkMarkdownNodeHTML),
24
+ start = index, ///
25
+ deleteCount = length; ///
26
+
27
+ if (identifiersIncludesIdentifier) {
28
+ const linkMarkdownNodeHTML = linkMarkdownNode.asHTML(indent, context, number);
29
+
30
+ childNodesHTML = splice(childNodesHTML, start, deleteCount, linkMarkdownNodeHTML);
31
+
32
+ number++;
33
+ } else {
34
+ childNodesHTML = chop(childNodesHTML, start, deleteCount);
35
+ }
36
+ });
37
+
38
+ return childNodesHTML;
39
+ }
40
+
41
+ export function renumberLinkMarkdownNodes(documentMarkdownNode, footnotesListMarkdownNode, context) {
6
42
  let number = 1;
7
43
 
8
- const identifiers = footnotesListMarkdownNode.getIdentifiers(),
44
+ const identifiers = footnotesListMarkdownNode.identifiers(),
9
45
  linkMarkdownNodes = linkMarkdownNodesFromNode(documentMarkdownNode);
10
46
 
11
47
  linkMarkdownNodes.forEach((linkMarkdownNode) => {
12
- const identifier = linkMarkdownNode.getIdentifier(),
48
+ const identifier = linkMarkdownNode.identifier(context),
49
+ linkMarkdownNodeDOMElement = linkMarkdownNode.getDOMElement(),
13
50
  identifiersIncludesIdentifier = identifiers.includes(identifier);
14
51
 
52
+ let innerHTML;
53
+
15
54
  if (identifiersIncludesIdentifier) {
16
- linkMarkdownNode.setNumber(number);
55
+ innerHTML = `${number}`;
17
56
 
18
57
  number++;
19
58
  } else {
20
- linkMarkdownNode.clear();
59
+ innerHTML = EMPTY_STRING;
21
60
  }
61
+
62
+ Object.assign(linkMarkdownNodeDOMElement, {
63
+ innerHTML
64
+ });
22
65
  });
23
66
  }
24
67