1
- # nlcst-is-literal [ ![ Build Status] ( https://img.shields.io/ travis/wooorm/nlcst-is-literal.svg )] ( https:// travis-ci.org/wooorm/nlcst-is-literal ) [ ![ Coverage Status] ( https://img.shields.io/ codecov/c/github/wooorm/nlcst-is-literal.svg )] ( https:// codecov.io/github/wooorm/nlcst-is-literal )
1
+ # nlcst-is-literal [ ![ Build Status] [ travis-badge ]] [ travis ] [ ![ Coverage Status] [ codecov-badge ]] [ codecov ]
2
2
3
- Check whether an NLCST node is meant literally. Useful if a tool wants to
3
+ Check if an NLCST node is meant literally. Useful if a tool wants to
4
4
exclude these values possibly void of meaning.
5
5
6
6
As an example, a spell-checker could exclude these literal words, thus not
7
7
warning about “monsieur”.
8
8
9
9
## Installation
10
10
11
- [ npm] ( https://docs.npmjs.com/cli/install ) :
11
+ [ npm] [ ] :
12
12
13
13
``` bash
14
14
npm install nlcst-is-literal
@@ -20,23 +20,27 @@ npm install nlcst-is-literal
20
20
var retext = require (' retext' );
21
21
var visit = require (' unist-util-visit' );
22
22
var toString = require (' nlcst-to-string' );
23
- var isLiteral = require (' .' );
24
-
25
- retext ().use (function () {
26
- return function (cst ) {
27
- visit (cst, ' WordNode' , function (node , index , parent ) {
28
- if (isLiteral (parent, index)) {
29
- console .log (toString (node));
30
- }
31
- });
32
- }
33
- }).process ([
23
+ var literal = require (' nlcst-is-literal' );
24
+
25
+ retext ().use (plugin).process ([
34
26
' The word “foo” is meant as a literal.' ,
35
27
' The word «bar» is meant as a literal.' ,
36
28
' The word (baz) is meant as a literal.' ,
37
29
' The word, qux, is meant as a literal.' ,
38
30
' The word — quux — is meant as a literal.'
39
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
+ }
42
+ }
43
+ }
40
44
```
41
45
42
46
Yields:
51
55
52
56
## API
53
57
54
- ### isLiteral(parent, index)
58
+ ### ` isLiteral(parent, index) `
55
59
56
60
Check if the node in ` parent ` at ` position ` is enclosed
57
61
by matching delimiters.
@@ -64,22 +68,22 @@ For example, in:
64
68
65
69
...` foo ` is literal.
66
70
67
- ###### Parameters
71
+ ## License
72
+
73
+ [ MIT] [ license ] © [ Titus Wormer] [ author ]
68
74
69
- * ` node ` ([ ` NLCSTParentNode ` ] ( https://github.com/wooorm/nlcst#parent ) )
70
- — Parent to search.
75
+ <!-- Definitions -->
71
76
72
- * ` nodes ` ( ` Array.<NLCSTNode> ` ) — Position of node to check.
77
+ [ travis-badge ] : https://img.shields.io/travis/wooorm/nlcst-is-literal.svg
73
78
74
- ###### Returns
79
+ [ travis ] : https://travis-ci.org/wooorm/nlcst-is-literal
75
80
76
- ` boolean ` — Whether the node is literal.
81
+ [ codecov-badge ] : https://img.shields.io/codecov/c/github/wooorm/nlcst-is- literal.svg
77
82
78
- ** Throws **
83
+ [ codecov ] : https://codecov.io/github/wooorm/nlcst-is-literal
79
84
80
- * ` Error ` — When no parent node is given;
81
- * ` Error ` — When no index is given.
85
+ [ npm ] : https://docs.npmjs.com/cli/install
82
86
83
- ## License
87
+ [ license ] : LICENSE
84
88
85
- [ MIT ] ( LICENSE ) © [ Titus Wormer ] ( http://wooorm.com )
89
+ [ author ] : http://wooorm.com
0 commit comments