@@ -16,34 +16,43 @@ npm install nlcst-is-literal
16
16
17
17
## Usage
18
18
19
+ Say we have the following file, ` example.txt ` :
20
+
21
+ ``` text
22
+ The word “foo” is meant as a literal.
23
+
24
+ The word «bar» is meant as a literal.
25
+
26
+ The word (baz) is meant as a literal.
27
+
28
+ The word, qux, is meant as a literal.
29
+
30
+ The word — quux — is meant as a literal.
31
+ ```
32
+
33
+ And our script, ` example.js ` , looks as follows:
34
+
19
35
``` javascript
20
- var retext = require (' retext' );
36
+ var vfile = require (' to-vfile' );
37
+ var unified = require (' unified' );
38
+ var english = require (' retext-english' );
21
39
var visit = require (' unist-util-visit' );
22
40
var toString = require (' nlcst-to-string' );
23
41
var literal = require (' nlcst-is-literal' );
24
42
25
- retext ().use (plugin).process ([
26
- ' The word “foo” is meant as a literal.' ,
27
- ' The word «bar» is meant as a literal.' ,
28
- ' The word (baz) is meant as a literal.' ,
29
- ' The word, qux, is meant as a literal.' ,
30
- ' The word — quux — is meant as a literal.'
31
- ].join (' \n\n ' ));
32
-
33
- function plugin () {
34
- return transformer;
35
- function transformer (tree ) {
36
- visit (tree, ' WordNode' , visitor);
37
- }
38
- function visitor (node , index , parent ) {
39
- if (literal (parent, index)) {
40
- console .log (toString (node));
41
- }
43
+ var file = vfile .readSync (' example.txt' );
44
+ var tree = unified ().use (english).parse (file);
45
+
46
+ visit (tree, ' WordNode' , visitor);
47
+
48
+ function visitor (node , index , parent ) {
49
+ if (literal (parent, index)) {
50
+ console .log (toString (node));
42
51
}
43
52
}
44
53
```
45
54
46
- Yields :
55
+ Now, running ` node example ` yields :
47
56
48
57
``` text
49
58
foo
0 commit comments