retext-syntax-mentions
retext plugin to classify @mentions
as syntax instead of natural language.
Contents
What is this?
This package is a unified (retext) plugin to classify mentions (as used on for example GitHub) as SourceNode
instead of natural language. That node represent “external (ungrammatical) values” instead of natural language, which hides mentions from retext-spell
, retext-readability
, retext-equality
, and other things that check words.
When should I use this?
You can use this plugin any time there are mentions in prose, that are (incorrectly) warned about by linting plugins.
Install
This package is ESM only. In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with npm:
npm install retext-syntax-mentions
In Deno with esm.sh
:
import retextSyntaxMentions from 'https://esm.sh/retext-syntax-mentions@3'
In browsers with esm.sh
:
<script type="module">
import retextSyntaxMentions from 'https://esm.sh/retext-syntax-mentions@3?bundle'
</script>
Use
Without retext-syntax-mentions
:
import dictionary from 'dictionary-en-gb'
import {reporter} from 'vfile-reporter'
import {unified} from 'unified'
import retextEnglish from 'retext-english'
import retextSyntaxMentions from 'retext-syntax-mentions'
import retextSpell from 'retext-spell'
import retextStringify from 'retext-stringify'
const file = await unified()
.use(retextEnglish)
.use(retextSpell, dictionary)
.use(retextStringify)
.process('Misspelt? @wooorm.')
console.log(reporter(file))
Yields:
1:12-1:18 warning `wooorm` is misspelt; did you mean `worm`? retext-spell retext-spell
⚠ 1 warning
With retext-syntax-mentions
:
.use(retextEnglish)
+ .use(retextSyntaxMentions)
.use(retextSpell, dictionary)
Yields:
no issues found
API
This package exports no identifiers. The default export is retextSyntaxMentions
.
unified().use(retextSyntaxMentions[, options])
Classify @mentions
as syntax instead of natural language.
options
Configuration (optional).
options.style
Style can be either 'github'
(for GitHub user and team mentions), 'twitter'
(for Twitter handles), or a regular expression (such as /^@\w{1,15}$/i
, which is the Twitter regex).
Types
This package is fully typed with TypeScript. It exports the additional type Options
.
Compatibility
Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. Our projects sometimes work with older versions, but this is not guaranteed.
Related
retext-syntax-urls
— classify URLs and filepaths as syntaxretext-spell
— check spellingretext-readability
— check readabilityretext-equality
— check possible insensitive, inconsiderate language
Contribute
See contributing.md
in retextjs/.github
for ways to get started. See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.