Giter VIP home page Giter VIP logo

remark-retext's Introduction

remark-retext

Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to support retext.

Contents

What is this?

This package is a unified (remark) plugin to support retext.

When should I use this?

This project is useful if you want to check natural language in markdown. The retext ecosystem has many useful plugins to check prose, such as retext-indefinite-article which checks that a and an are used correctly, or retext-readability which checks that sentences are not too complex. This plugins lets you use them on markdown documents.

This plugin is not able to apply changes by retext plugins (such as done by retext-smartypants) to the markdown content.

This plugin is built on mdast-util-to-nlcst, which does the work on syntax trees. remark focusses on making it easier to transform content by abstracting such internals away.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install remark-retext

In Deno with esm.sh:

import remarkRetext from 'https://esm.sh/remark-retext@6'

In browsers with esm.sh:

<script type="module">
  import remarkRetext from 'https://esm.sh/remark-retext@6?bundle'
</script>

Use

Say we have the following file example.md:

## Hello guys!

…and a module example.js:

import remarkParse from 'remark-parse'
import remarkRetext from 'remark-retext'
import remarkStringify from 'remark-stringify'
import retextEnglish from 'retext-english'
import retextEquality from 'retext-equality'
import {read} from 'to-vfile'
import {unified} from 'unified'
import {reporter} from 'vfile-reporter'

const file = await unified()
  .use(remarkParse)
  .use(remarkRetext, unified().use(retextEnglish).use(retextEquality))
  .use(remarkStringify)
  .process(await read('example.md'))

console.error(reporter(file))

…then running node example.js yields:

example.md
1:10-1:14 warning Unexpected potentially insensitive use of `guys`, in somes cases `people`, `persons`, `folks` may be better gals-man retext-equality

⚠ 1 warning

API

This package exports no identifiers. The default export is remarkRetext.

unified().use(remarkRetext, destination[, options])

Bridge or mutate to retext.

Parameters
Returns

Transform (Transformer).

Notes
  • if a processor is given, uses its parser to create a new nlcst tree, then runs the plugins attached to with that (bridge mode); you can add a parser to processor for example with retext-english; other plugins used on the processor should be retext plugins
  • if a parser is given, uses it to create a new nlcst tree, and returns it (mutate mode); you can get a parser by importing Parser from retext-english for example; other plugins used after remarkRetext should be retext plugins

Options

Configuration (TypeScript type).

Fields
  • options.ignore (Array<string>, optional) — list of mdast node types to ignore; the types 'table', 'tableRow', and 'tableCell' are always ignored
  • options.source (Array<string>, optional) — list of mdast node types to mark as nlcst source nodes; the type 'inlineCode' is always marked as source

Types

This package is fully typed with TypeScript. It exports the additional type Options.

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, remark-retext@^6, compatible with Node.js 16.

This plugin works with unified version 6+, remark version 3+, and retext version 7+.

Security

Use of remark-retext does not involve rehype (hast) or user content so there are no openings for cross-site scripting (XSS) attacks.

Related

Contribute

See contributing.md in remarkjs/.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.

License

MIT © Titus Wormer

remark-retext's People

Contributors

greenkeeperio-bot avatar wooorm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

remark-retext's Issues

Example code fails with `TypeError: file.warn is not a function`

I tested the example code with nodejs v10.11.0 and v12.4.0, in both cases I get a type error

TypeError: file.warn is not a function
    at warn ($MYWORKDIR/node_modules/retext-equality/lib/index.js:268:18)
    at Object.simple ($MYWORKDIR/node_modules/retext-equality/lib/index.js:129:5)
    at visitor ($MYWORKDIR/node_modules/retext-equality/lib/index.js:88:23)
    at overload ($MYWORKDIR/node_modules/unist-util-visit/index.js:27:12)
    at one ($MYWORKDIR/node_modules/unist-util-visit-parents/index.js:34:25)
    at all ($MYWORKDIR/node_modules/unist-util-visit-parents/index.js:57:16)
    at one ($MYWORKDIR/node_modules/unist-util-visit-parents/index.js:42:28)
    at visitParents ($MYWORKDIR/node_modules/unist-util-visit-parents/index.js:26:3)
    at visit ($MYWORKDIR/node_modules/unist-util-visit/index.js:22:3)
    at transformer ($MYWORKDIR/node_modules/retext-equality/lib/index.js:70:5)

Does this library need a specific nodejs version or other libraries than

I don't have a lot of experience with JavaScript, so sorry if I made any beginner's mistake 😅

retext-spell error on autolink

(I'm not sure if this is the right place to report the issue, since it uses several components of the remark and retext environment, so please excuse me if it should be somewhere else.)

Subject of the issue

I'm using remark-retext to run retext-spell on the content of Markdown files, and I get a warning for a spelling error in an autolink.

Your environment

  • OS: macOS Mojave (10.14.6)
  • Packages: See package.json below
  • Env: npm 6.14.4, node v12.18.0

Steps to reproduce

Run these commands in a directory with the files below:

$ npm install
$ node index.js

package.json:

{
  "name": "remark-retext-spell-autolink",
  "version": "0.0.1",
  "license": "BlueOak-1.0.0",
  "files": [
    "index.js"
  ],
  "dependencies": {
    "dictionary-en": "3.0.0",
    "remark-parse": "8.0.2",
    "remark-retext": "4.0.0",
    "remark-stringify": "8.1.0",
    "retext-english": "3.0.4",
    "retext-spell": "4.0.0",
    "unified": "9.0.0",
    "vfile-reporter": "6.0.1"
  }
}

index.js:

'use strict'

const unified = require('unified')

unified()
  .use(require('remark-parse'))
  .use(
    require('remark-retext'),
    unified()
      .use(require('retext-english'))
      .use(require('retext-spell'), {dictionary: require('dictionary-en')})
  )
  .use(require('remark-stringify'))
  .process('<https://blueoakcouncil.org/license/1.0.0>', (err, file) => {
    console.error(require('vfile-reporter')(err || file))
  })

Expected behaviour

I expected no warning for anything in an autolink, since it will undoubtedly contain things that are not (English) words.

I'm reporting here, since I would expect remark-retext to drop autolinks when passing the text from the Markdown to the retext processor.

Actual behaviour

$ node index.js 
  1:10-1:28  warning  `blueoakcouncil.org` is misspelt  blueoakcouncil-org  retext-spell

⚠ 1 warning

Support string arrays like in unified-engine

Subject of the feature

It would be nice if remark-retext could support a unified plugin list instead of a processor using the same syntax as unified-engine. Logic for this resides in https://github.com/unifiedjs/unified-engine/blob/main/lib/configuration.js. It probably makes sense to extract it into a new unified project.

Problem

remark-retext is often used with remark-cli, which supports YAML and JSON configuration files, but remark-retext only works with JavaScript configuration files, because a processor is needed.

Expected behavior

It would be nice if the following .remarkrc file:

const dictionary = require('dictionary-en');
const english = require('retext-english');
const quotes = require('retext-quotes');
const repeatedWords = require('retext-repeated-words');
const syntaxURLs = require('retext-syntax-urls');
const unified = require('unified');

module.exports = {
  plugins: [
    'remark-frontmatter',
    'remark-gfm',
    'remark-lint-heading-increment',
    'remark-lint-no-duplicate-defined-urls',
    'remark-lint-no-duplicate-definitions',
    'remark-lint-no-empty-url',
    'remark-lint-no-reference-like-url',
    'remark-lint-no-undefined-references',
    'remark-lint-no-unneeded-full-reference-image',
    'remark-lint-no-unneeded-full-reference-link',
    'remark-lint-no-unused-definitions',
    'remark-prettier',
    ['remark-validate-links', { repository: 'https://gitlab.com/remcohaszing/koas.git' }],
    [
      'remark-retext',
      unified()
        .use(english)
        .use(syntaxURLs)
        .use(repeatedWords)
        .use(quotes),
    ],
  ],
};

could be rewritten as JSON or YAML:

plugins:
  - remark-frontmatter
  - remark-gfm
  - remark-lint-heading-increment
  - remark-lint-no-duplicate-defined-urls
  - remark-lint-no-duplicate-definitions
  - remark-lint-no-empty-url
  - remark-lint-no-reference-like-url
  - remark-lint-no-undefined-references
  - remark-lint-no-unneeded-full-reference-image
  - remark-lint-no-unneeded-full-reference-link
  - remark-lint-no-unused-definitions
  - remark-prettier
  - - remark-validate-links
    - repository: https://gitlab.com/remcohaszing/koas.git
  - - remark-retext
    - - retext-english
      - retext-syntax-urls
      - retext-repeated-words
      - retext-quotes

Alternatives

N/A

remark-retext not playing nicely with retext-smartypants

I can't get retext-smartypants to do its thing when combined with remark-retext.

This works fine:

const file = unified()
  .use(require('retext-english'))
  .use(require('retext-smartypants'))
  .use(require('retext-stringify'))
  .processSync('He said, "A \'simple\' English sentence. . ."')

console.log(String(file))
// => He said, “A ‘simple’ English sentence…"

But this doesn't:

const file = unified()
  .use(require('remark-parse'))
  .use(
    require('remark-retext'),
    unified()
      .use(require('retext-english'))
      .use(require('retext-smartypants'))
  )
  .use(require('remark-stringify'))
  .processSync('He said, "A \'simple\' English sentence. . ."')

console.log(String(file))
// => He said, "A 'simple' English sentence. . ."

@wooorm am I doing something wrong?

Add option to use syncronous processor

Initial checklist

Problem

remark-retext currently returns an async processor with no option to change this.

Solution

By adding an option to request a syncronous processor instead, the plugin would become more versatile.

Alternatives

Do not use remark-retext in syncronous functions.

Default example doesn't run

Hey Titus!

Unfortunately running into some issues with upgrading retext-mapbox-standard to the 'newest everything' and I can isolate the problem up to this module, sort of...

Here's a gist for demonstration: https://gist.github.com/tmcw/0dbd9cbcbccdd10899200cf6d00f04f5

Issues that I've been able to isolate so far:

  • The readme example on this project uses throw err for error reporting within the remark callback method, but that gets caught by unified and silenced.
  • The actual error is Error: mdast-util-to-nlcst expected node

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.