retextjs / retext-syntax-mentions

plugin to classify @mentions as syntax, not natural language
https://unifiedjs.com
MIT License
10 stars 2 forks source link

Error when username is at end of input #1

Closed bkeepers closed 7 years ago

bkeepers commented 7 years ago

Given @foo-bar (which is a valid github username), this plugin will throw an error:

Given Hello @foo-bar, this plugin will throw an error:

Error: Expected node, not `undefined`
    at nlcstToString (/Users/bkeepers/projects/guides/node_modules/nlcst-to-string/index.js:29:15)
    at /Users/bkeepers/projects/guides/node_modules/retext-syntax-mentions/index.js:26:9
wooorm commented 7 years ago

😬

I just tested it and it worked for me. Could you provide more info on what fails and how I can reproduce it?

bkeepers commented 7 years ago

Sorry, I mis-diagnosed the issue. It turns out the error is caused by the username being at the very end of the input.

Here is an example that shows it:

var dictionary = require('dictionary-en-us');
var retext = require('retext');
var english = require('retext-english');
var spell = require('retext-spell');
var mentions = require('retext-syntax-mentions');
var report = require('vfile-reporter');

retext().use(english).use(mentions).use(spell, dictionary).process([
  'Misspelt? @wooorm'
].join('\n'), function (err, file) {
  console.log(report(err || file));
});

Note that this is identical to the example in the README, except:

-  'Misspelt? @wooorm.'
+  'Misspelt? @wooorm'
 ].join('\n'), function (err, file) {
wooorm commented 7 years ago

Ah, great, weird that I hadn’t tested @s near the end of a sentence. Thanks for the issue, and happy New Year! 🎆🎇