Skip to content

Kryndex/nlcst-is-literal

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nlcst-is-literal Build Status Coverage Status

Check if an NLCST node is meant literally. Useful if a tool wants to exclude these values possibly void of meaning.

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

Installation

npm:

npm install nlcst-is-literal

Usage

var retext = require('retext');
var visit = require('unist-util-visit');
var toString = require('nlcst-to-string');
var literal = require('nlcst-is-literal');

retext().use(plugin).process([
  'The word “foo” is meant as a literal.',
  'The word «bar» is meant as a literal.',
  'The word (baz) is meant as a literal.',
  'The word, qux, is meant as a literal.',
  'The word — quux — is meant as a literal.'
].join('\n\n'));

function plugin() {
  return transformer;
  function transformer(tree) {
    visit(tree, 'WordNode', visitor);
  }
  function visitor(node, index, parent) {
    if (literal(parent, index)) {
      console.log(toString(node));
    }
  }
}

Yields:

foo
bar
baz
qux
quux

API

isLiteral(parent, index)

Check if the node in parent at position is enclosed by matching delimiters.

For example, in:

  • Foo - is meant as a literal.;
  • Meant as a literal is - foo.;
  • The word “foo” is meant as a literal.;

...foo is literal.

License

MIT © Titus Wormer

About

Check whether an NLCST node is meant literally

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%