@@ -16,34 +16,43 @@ npm install nlcst-is-literal
1616
1717## Usage  
1818
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+ 
1935``` javascript 
20- var  retext =  require (' retext' 
36+ var  vfile =  require (' to-vfile' 
37+ var  unified =  require (' unified' 
38+ var  english =  require (' retext-english' 
2139var  visit =  require (' unist-util-visit' 
2240var  toString =  require (' nlcst-to-string' 
2341var  literal =  require (' nlcst-is-literal' 
2442
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' 
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' 
47+ 
48+ function  visitor (node , index , parent ) {
49+   if  (literal (parent, index)) {
50+     console .log (toString (node));
4251  }
4352}
4453``` 
4554
46- Yields :
55+ Now, running  ` node example `  yields :
4756
4857``` text 
4958foo 
0 commit comments