occam-dom 5.2.26 → 5.2.27
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 +72 -1
- package/example.js +68 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -13,7 +13,49 @@
|
|
|
13
13
|
|
|
14
14
|
## Introduction
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Specifically, "outer" token arrays and node trees resulting from the user of Occam's [lexers](https://github.com/djalbat/occam-lexers) and [parsers](https://github.com/djalbat/occam-parsers), respectively, can be refined into "inner" token arrays and node trees for convenience.
|
|
17
|
+
|
|
18
|
+
An example is helpful. Consider the following outer node tree that results from parsing some simple Markdown.
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
|
|
|
22
|
+
markdown [0-2]
|
|
23
|
+
|
|
|
24
|
+
division [0-2]
|
|
25
|
+
|
|
|
26
|
+
---------------------------------------------------------------------
|
|
27
|
+
| | |
|
|
28
|
+
subDivision.. [0] verticalSpace [0-1] subDivision.. [2]
|
|
29
|
+
| | |
|
|
30
|
+
primaryHeading [0] --------------- paragraph [2]
|
|
31
|
+
| | | |
|
|
32
|
+
------------------- <END_OF_LINE> <END_OF_LINE> line [2]
|
|
33
|
+
| | |
|
|
34
|
+
"#"[hashes] [0] line [0] ---------------------
|
|
35
|
+
| | |
|
|
36
|
+
plainText. [0] plainText. [2] plainText. [2]
|
|
37
|
+
| | |
|
|
38
|
+
"Heading"[word] [0] "Paragraph"[word] [2] "."[special] [2]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This contains far more information than is needed to render the markdown as HTML. The following inner node tree will in fact suffice:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
|
|
|
45
|
+
division
|
|
46
|
+
|
|
|
47
|
+
------------------
|
|
48
|
+
| |
|
|
49
|
+
primaryHeading paragraph
|
|
50
|
+
| |
|
|
51
|
+
line line
|
|
52
|
+
| |
|
|
53
|
+
plainText -----------
|
|
54
|
+
| |
|
|
55
|
+
plainText plainText
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Locating the outer nodes that contribute to this inner node tree is straightforward enough using Occam's [queries](https://github.com/djalbat/occam-query). However, the arrays of nodes that result are not in the above form. This package provides the means to form such node trees.
|
|
17
59
|
|
|
18
60
|
## Installation
|
|
19
61
|
|
|
@@ -51,7 +93,36 @@ One last thing to bear in mind is that this package is included by way of a rela
|
|
|
51
93
|
|
|
52
94
|
## Usage
|
|
53
95
|
|
|
96
|
+
Suppose that a Markdown document is being parsed by way of [Highmark](https://github.com/djalbat/highmark-markdown)'s lexer and parser:
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
const markdownLexer = MarkdownLexer.fromNothing(),
|
|
100
|
+
markdownParser = MarkdownParser.fromNothing();
|
|
101
|
+
|
|
102
|
+
...
|
|
103
|
+
|
|
104
|
+
const content = markdown, ///
|
|
105
|
+
tokens = markdownLexer.tokenise(content),
|
|
106
|
+
node = markdownParser.parse(tokens);
|
|
107
|
+
|
|
54
108
|
...
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
A number of arrays of nodes can be created from the document's "outer" node by applying queries:
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
export function nodesFromNodeAndQueries(node, queries, nodes = []) {
|
|
115
|
+
queries.forEach((query) => {
|
|
116
|
+
const queryNodes = query.execute(node);
|
|
117
|
+
|
|
118
|
+
push(nodes, queryNodes);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return nodes;
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
These can then be formed into an ""
|
|
55
126
|
|
|
56
127
|
## Building
|
|
57
128
|
|