Skip to content

Commit 9154341

Browse files
committed
Refactor docs
1 parent e67e4f9 commit 9154341

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

readme.md

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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]
22

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
44
exclude these values possibly void of meaning.
55

66
As an example, a spell-checker could exclude these literal words, thus not
77
warning about “monsieur”.
88

99
## Installation
1010

11-
[npm](https://docs.npmjs.com/cli/install):
11+
[npm][]:
1212

1313
```bash
1414
npm install nlcst-is-literal
@@ -20,23 +20,27 @@ npm install nlcst-is-literal
2020
var retext = require('retext');
2121
var visit = require('unist-util-visit');
2222
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([
3426
'The word “foo” is meant as a literal.',
3527
'The word «bar» is meant as a literal.',
3628
'The word (baz) is meant as a literal.',
3729
'The word, qux, is meant as a literal.',
3830
'The word — quux — is meant as a literal.'
3931
].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+
}
4044
```
4145

4246
Yields:
@@ -51,7 +55,7 @@ quux
5155

5256
## API
5357

54-
### isLiteral(parent, index)
58+
### `isLiteral(parent, index)`
5559

5660
Check if the node in `parent` at `position` is enclosed
5761
by matching delimiters.
@@ -64,22 +68,22 @@ For example, in:
6468

6569
...`foo` is literal.
6670

67-
###### Parameters
71+
## License
72+
73+
[MIT][license] © [Titus Wormer][author]
6874

69-
* `node` ([`NLCSTParentNode`](https://github.com/wooorm/nlcst#parent))
70-
— Parent to search.
75+
<!-- Definitions -->
7176

72-
* `nodes` (`Array.<NLCSTNode>`) — Position of node to check.
77+
[travis-badge]: https://img.shields.io/travis/wooorm/nlcst-is-literal.svg
7378

74-
###### Returns
79+
[travis]: https://travis-ci.org/wooorm/nlcst-is-literal
7580

76-
`boolean` — Whether the node is literal.
81+
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/nlcst-is-literal.svg
7782

78-
**Throws**
83+
[codecov]: https://codecov.io/github/wooorm/nlcst-is-literal
7984

80-
* `Error` — When no parent node is given;
81-
* `Error` — When no index is given.
85+
[npm]: https://docs.npmjs.com/cli/install
8286

83-
## License
87+
[license]: LICENSE
8488

85-
[MIT](LICENSE) © [Titus Wormer](http://wooorm.com)
89+
[author]: http://wooorm.com

0 commit comments

Comments
 (0)