Top Related Projects
☔️ interface for parsing, inspecting, transforming, and serializing content through syntax trees
markdown processor powered by plugins part of the @unifiedjs collective
The pluggable natural language linter for text and markdown.
:pencil: A markup-aware linter for prose built with speed and extensibility in mind.
Naive linter for English prose
Quick Overview
Retext is a natural language processor powered by plugins. It's an extensible system that allows you to analyze and manipulate natural language in JavaScript. Retext can be used for various text processing tasks, including spell checking, readability analysis, and content transformation.
Pros
- Highly modular and extensible through plugins
- Supports a wide range of natural language processing tasks
- Easy to integrate with other JavaScript projects
- Active community and regular updates
Cons
- Learning curve for creating custom plugins
- Performance may be slower compared to more specialized NLP libraries
- Limited built-in functionality without plugins
- Documentation could be more comprehensive for advanced use cases
Code Examples
- Basic usage with spell checking:
import {retext} from 'retext'
import retextSpell from 'retext-spell'
import dictionary from 'dictionary-en'
const text = 'Some misspelled words: helo world'
retext()
.use(retextSpell, dictionary)
.process(text)
.then((file) => {
console.log(String(file))
})
- Readability analysis:
import {retext} from 'retext'
import retextReadability from 'retext-readability'
const text = 'The cat sat on the mat. The mat was red.'
retext()
.use(retextReadability)
.process(text)
.then((file) => {
console.log(file.messages)
})
- Content transformation:
import {retext} from 'retext'
import retextSmartypants from 'retext-smartypants'
const text = 'This is "quoted" text with some dashes--like this.'
retext()
.use(retextSmartypants)
.process(text)
.then((file) => {
console.log(String(file))
})
Getting Started
To get started with Retext, follow these steps:
-
Install Retext and desired plugins:
npm install retext retext-spell dictionary-en
-
Create a new JavaScript file (e.g.,
example.js
) and add the following code:import {retext} from 'retext' import retextSpell from 'retext-spell' import dictionary from 'dictionary-en' const text = 'Your text to process' retext() .use(retextSpell, dictionary) .process(text) .then((file) => { console.log(String(file)) })
-
Run the script:
node example.js
This basic example demonstrates spell checking. You can add more plugins and customize the processing pipeline as needed for your specific use case.
Competitor Comparisons
☔️ interface for parsing, inspecting, transforming, and serializing content through syntax trees
Pros of unified
- More versatile and extensible, supporting multiple syntax trees (ASTs) for various content types
- Larger ecosystem with plugins for parsing, transforming, and serializing different formats
- Better suited for complex document processing pipelines
Cons of unified
- Steeper learning curve due to its more comprehensive architecture
- May be overkill for simple text processing tasks
- Requires more setup and configuration for basic use cases
Code comparison
unified:
import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypeStringify)
.process('# Hello, world!')
.then((file) => console.log(String(file)))
retext:
import { retext } from 'retext'
import retextPos from 'retext-pos'
import retextKeywords from 'retext-keywords'
retext()
.use(retextPos)
.use(retextKeywords)
.process('Hello, world!')
.then((file) => console.log(String(file)))
Summary
unified is a more powerful and flexible tool for processing various types of content, while retext focuses specifically on natural language processing. unified offers a wider range of capabilities but may require more setup, whereas retext provides a simpler approach for text-specific tasks. Choose unified for complex document processing needs and retext for straightforward natural language analysis.
markdown processor powered by plugins part of the @unifiedjs collective
Pros of remark
- Broader ecosystem with more plugins and integrations
- Better suited for Markdown processing and transformation
- More active development and larger community support
Cons of remark
- Steeper learning curve due to more complex architecture
- Potentially slower processing for simple text operations
- May be overkill for projects that don't require Markdown handling
Code Comparison
remark:
import { remark } from 'remark';
import remarkHtml from 'remark-html';
const markdown = '# Hello, world!';
remark()
.use(remarkHtml)
.process(markdown)
.then((file) => console.log(String(file)));
retext:
import { retext } from 'retext';
import retextPos from 'retext-pos';
const text = 'The quick brown fox jumps over the lazy dog.';
retext()
.use(retextPos)
.process(text)
.then((file) => console.log(String(file)));
Both remark and retext are part of the unified ecosystem, but they serve different purposes. remark is primarily focused on Markdown processing, while retext is designed for natural language processing. remark offers a more extensive plugin ecosystem and is better suited for projects involving Markdown transformation. However, retext excels in text analysis and manipulation tasks, making it a more appropriate choice for natural language processing applications.
The pluggable natural language linter for text and markdown.
Pros of textlint
- More extensive rule ecosystem with a wide range of community-contributed plugins
- Supports multiple markup languages (Markdown, AsciiDoc, Re:VIEW)
- Provides a command-line interface for easy integration into workflows
Cons of textlint
- Steeper learning curve due to more complex configuration options
- Slower performance on large documents compared to retext
- Less focus on natural language processing tasks
Code Comparison
textlint configuration:
{
"rules": {
"no-todo": true,
"max-comma": { "max": 3 },
"spellcheck-tech-word": true
}
}
retext usage:
import {retext} from 'retext'
import retextSpell from 'retext-spell'
import dictionary from 'dictionary-en-us'
retext()
.use(retextSpell, dictionary)
.process('Some text to analyze')
Both textlint and retext are powerful text analysis tools, but they cater to slightly different use cases. textlint offers more flexibility for various markup languages and has a larger ecosystem of rules, making it suitable for complex documentation projects. retext, on the other hand, focuses more on natural language processing tasks and provides a simpler API, making it easier to integrate into JavaScript projects for specific text analysis needs.
:pencil: A markup-aware linter for prose built with speed and extensibility in mind.
Pros of Vale
- Written in Go, offering better performance and easier deployment
- Extensive rule set and customizable style guides out-of-the-box
- Integrates well with various text editors and CI/CD pipelines
Cons of Vale
- Less flexible for programmatic text transformations
- Steeper learning curve for creating custom rules
- Limited to linting and doesn't provide text manipulation capabilities
Code Comparison
Vale configuration (.vale.ini
):
StylesPath = styles
MinAlertLevel = suggestion
[*.md]
BasedOnStyles = Vale, proselint
Retext usage:
import {retext} from 'retext'
import retextSpell from 'retext-spell'
import dictionary from 'dictionary-en-us'
retext()
.use(retextSpell, dictionary)
.process('Some text to analyze')
Vale focuses on configuration-based linting, while Retext provides a programmable pipeline for text analysis and transformation. Vale excels in ready-to-use style checking, whereas Retext offers more flexibility for custom text processing tasks.
Naive linter for English prose
Pros of write-good
- Lightweight and easy to use with minimal setup
- Focuses specifically on writing style improvements
- Provides clear, actionable suggestions for better writing
Cons of write-good
- Less extensible compared to retext's plugin system
- Limited to English language analysis
- Fewer customization options for specific use cases
Code Comparison
write-good:
var writeGood = require('write-good');
var suggestions = writeGood('So the cat was stolen.');
console.log(suggestions);
retext:
var retext = require('retext');
var english = require('retext-english');
var stringify = require('retext-stringify');
var passive = require('retext-passive');
retext()
.use(english)
.use(passive)
.use(stringify)
.process('So the cat was stolen.')
.then((file) => console.log(String(file)));
write-good provides a simpler API for quick writing improvements, while retext offers a more modular and extensible approach for text processing and analysis. write-good is ideal for straightforward writing enhancement, whereas retext is better suited for complex natural language processing tasks and customizable text transformations.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
retext is a tool that transforms natural language with plugins. These plugins can inspect and change the natural language. You can use retext on the server, the client, deno, etc.
Intro
retext is an ecosystem of plugins that work with natural language as structured data, specifically CSTs (concrete syntax trees). Syntax trees make it easy for programs to deal with prose. We call those programs plugins. Plugins inspect and change trees. You can use the many existing plugins or you can make your own. Some example use cases are to check spelling, fix typography, or make sure text is readable.
- for more about us, see
unifiedjs.com
- for updates, see Twitter
- for questions, see support
- to help, see contribute or sponsor below
Contents
What is this?
With this project and a plugin, you can turn simple punctuation:
He said, "A 'simple' english sentence. . .
â¦into smart punctuation:
He said, âA âsimpleâ english sentenceâ¦â
Show example code
import retextLatin from 'retext-latin'
import retextSmartyPants from 'retext-smartypants'
import retextStringify from 'retext-stringify'
import {unified} from 'unified'
const file = await unified()
.use(retextLatin)
.use(retextSmartyPants)
.use(retextStringify)
.process("He said, \"A 'simple' english sentence. . .")
console.log(String(file))
With another plugin, you can check natural language:
In:
Where can I find an ATM machine?
Out:
1:21-1:32 warning Unexpected redundant `ATM machine`, expected `ATM` atm retext-redundant-acronyms
â 1 warning
Show example code
import retextEnglish from 'retext-english'
import retextRedundantAcronyms from 'retext-redundant-acronyms'
import retextStringify from 'retext-stringify'
import {unified} from 'unified'
import {reporter} from 'vfile-reporter'
const file = await unified()
.use(retextEnglish)
.use(retextRedundantAcronyms)
.use(retextStringify)
.process('Where can I find an ATM machine?')
console.log(reporter(file))
â¦and you can make your own plugins.
You can use retext for many different things. unified is the core project that transforms content with ASTs. retext adds support for natural language to unified. nlcst is the natural language AST that retext uses.
This GitHub repository is a monorepo that contains the following packages:
retext-dutch
â parse Dutch prose to a syntax treeretext-english
â parse English prose to a syntax treeretext-latin
â parse any Latin-script prose to a syntax treeretext-stringify
â serialize a syntax treeretext
â programmatic interface with bothretext-latin
andretext-stringify
When should I use this?
It is recommended to use unified
with retext-english
(or retext-dutch
)
and retext-stringify
if your content is in English (or Dutch).
Otherwise, if your content is in another Latin-script language, use retext
.
Plugins
retext plugins deal with natural language. You can choose from the many plugins that already exist. Here are three good ways to find plugins:
awesome-retext
â selection of the most awesome projects- List of plugins â list of all plugins
retext-plugin
topic â any tagged repo on GitHub
Some plugins are maintained by us here in the @retextjs
organization while
others are maintained by folks elsewhere.
Anyone can make retext plugins, so as always when choosing whether to include
dependencies in your project, make sure to carefully assess the quality of
retext plugins too.
Types
The retext organization and the unified collective as a whole is fully typed
with TypeScript.
Types for nlcst are available in @types/nlcst
.
For TypeScript to work, it is important to type your plugins. For example:
/**
* @typedef {import('nlcst').Root} Root
*/
/**
* @typedef Options
* Configuration (optional).
* @property {boolean | null | undefined} [someField]
* Some option.
*/
/**
* My plugin.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns
* Transform.
*/
export function myRetextPluginAcceptingOptions(options) {
/**
* @param {Root} tree
* Tree.
* @param {VFile} file
* File.
* @returns {undefined}
* Nothing.
*/
return function (tree, file) {
// Do things.
}
}
Compatibility
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line compatible with Node.js 16.
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.
For info on how to submit a security report, see our security policy.
Sponsor
Support this effort and give back by sponsoring on OpenCollective!
Vercel |
Motif |
HashiCorp |
GitBook |
Gatsby |
|||||
Netlify |
Coinbase |
ThemeIsle |
Expo |
Boost Note |
Markdown Space |
Holloway |
|||
You? |
License
MIT © Titus Wormer
Top Related Projects
☔️ interface for parsing, inspecting, transforming, and serializing content through syntax trees
markdown processor powered by plugins part of the @unifiedjs collective
The pluggable natural language linter for text and markdown.
:pencil: A markup-aware linter for prose built with speed and extensibility in mind.
Naive linter for English prose
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot