remark-retext
Advanced tools
Comparing version 4.0.0 to 5.0.0
91
index.js
@@ -1,38 +0,73 @@ | ||
'use strict' | ||
/** | ||
* @typedef {import('unist').Node} Node | ||
* @typedef {import('mdast').Root} MdastRoot | ||
* @typedef {import('mdast-util-to-nlcst').ParserInstance} ParserInstance | ||
* @typedef {import('mdast-util-to-nlcst').ParserConstructor} ParserConstructor | ||
* @typedef {import('mdast-util-to-nlcst').Options} Options | ||
* @typedef {import('unified').Processor<any, any, any, any>} Processor | ||
* @typedef {import('unified').Parser<any>} Parser | ||
*/ | ||
var mdast2nlcst = require('mdast-util-to-nlcst') | ||
import {toNlcst} from 'mdast-util-to-nlcst' | ||
module.exports = remark2retext | ||
/** | ||
* Plugin to bridge or mutate to retext. | ||
* | ||
* If a destination processor is given, runs the destination with the new nlcst | ||
* tree (bridge-mode). | ||
* If a parser is given, returns the nlcst tree: further plugins run on that | ||
* tree (mutate-mode). | ||
* | ||
* @param destination | ||
* Either a processor (`unified().use(retextEnglish)…`) or a parser. | ||
* @param options | ||
* Configuration passed to `mdast-util-to-nlcst`. | ||
*/ | ||
const remarkRetext = | ||
/** | ||
* @type {(import('unified').Plugin<[Processor, Options?]|[Processor], MdastRoot, MdastRoot> & import('unified').Plugin<[Parser, Options?]|[Parser], MdastRoot, Node>)} | ||
*/ | ||
( | ||
/** | ||
* @param {Processor|Parser} destination | ||
* @param {Options|undefined} options | ||
*/ | ||
function (destination, options) { | ||
return destination && 'run' in destination | ||
? bridge(destination, options) | ||
: mutate(destination, options) | ||
} | ||
) | ||
// Attacher. | ||
// If a destination processor is given, runs the destination with the new nlcst | ||
// tree (bridge mode). | ||
// If a parser is given, returns the nlcst tree: further plugins run on that | ||
// tree (mutate mode). | ||
function remark2retext(destination, options) { | ||
var fn = destination && destination.run ? bridge : mutate | ||
return fn(destination, options) | ||
} | ||
export default remarkRetext | ||
// Mutate mode. | ||
// Further transformers run on the nlcst tree. | ||
/** | ||
* Mutate-mode. | ||
* Further transformers run on the nlcst tree. | ||
* | ||
* @type {import('unified').Plugin<[Parser, Options?], MdastRoot, Node>} | ||
*/ | ||
function mutate(parser, options) { | ||
return transformer | ||
function transformer(node, file) { | ||
return mdast2nlcst(node, file, parser, options) | ||
} | ||
// Assume the parser is a retext parser. | ||
const Parser = /** @type {ParserInstance|ParserConstructor} */ (parser) | ||
return (node, file) => toNlcst(node, file, Parser, options) | ||
} | ||
// Bridge mode. | ||
// Runs the destination with the new nlcst tree. | ||
/** | ||
* Bridge-mode. | ||
* Runs the destination with the new nlcst tree. | ||
* | ||
* @type {import('unified').Plugin<[Processor, Options?], MdastRoot>} | ||
*/ | ||
function bridge(destination, options) { | ||
return transformer | ||
function transformer(node, file, next) { | ||
var Parser = destination.freeze().Parser | ||
var tree = mdast2nlcst(node, file, Parser, options) | ||
destination.run(tree, file, done) | ||
function done(err) { | ||
next(err) | ||
} | ||
return (node, file, next) => { | ||
// Assume the parser is a retext parser. | ||
const Parser = /** @type {ParserConstructor|ParserInstance} */ ( | ||
destination.freeze().Parser | ||
) | ||
destination.run(toNlcst(node, file, Parser, options), file, (error) => { | ||
next(error) | ||
}) | ||
} | ||
} |
{ | ||
"name": "remark-retext", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "remark plugin to transform to retext", | ||
@@ -28,38 +28,39 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"mdast-util-to-nlcst": "^4.0.0" | ||
"@types/mdast": "^3.0.0", | ||
"@types/unist": "^2.0.0", | ||
"mdast-util-to-nlcst": "^5.0.0", | ||
"unified": "^10.0.0" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^16.0.0", | ||
"nyc": "^15.0.0", | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-parse": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"remark-stringify": "^7.0.0", | ||
"retext-english": "^3.0.0", | ||
"retext-stringify": "^2.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.0.0", | ||
"unified": "^8.0.0", | ||
"xo": "^0.28.0" | ||
"remark-cli": "^10.0.0", | ||
"remark-parse": "^10.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"remark-stringify": "^10.0.0", | ||
"retext-english": "^4.0.0", | ||
"retext-stringify": "^3.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.42.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify . -s remarkRetext > remark-retext.js", | ||
"build-mangle": "browserify . -s remarkRetext -p tinyify > remark-retext.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
"build": "rimraf \"*.d.ts\" && tsc && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node --conditions development test.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -74,7 +75,3 @@ "tabWidth": 2, | ||
"xo": { | ||
"prettier": true, | ||
"esnext": false, | ||
"ignores": [ | ||
"remark-retext.js" | ||
] | ||
"prettier": true | ||
}, | ||
@@ -85,3 +82,14 @@ "remarkConfig": { | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true, | ||
"#": "needed `any`s", | ||
"ignoreFiles": [ | ||
"index.d.ts", | ||
"index.js" | ||
] | ||
} | ||
} |
@@ -13,4 +13,13 @@ # remark-retext | ||
## Note! | ||
This plugin is ready for the new parser in remark | ||
([`remarkjs/remark#536`](https://github.com/remarkjs/remark/pull/536)). | ||
No change is needed: it works exactly the same now as it did previously! | ||
## Install | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
[npm][]: | ||
@@ -33,22 +42,20 @@ | ||
```js | ||
var vfile = require('to-vfile') | ||
var report = require('vfile-reporter') | ||
var unified = require('unified') | ||
var parse = require('remark-parse') | ||
var stringify = require('remark-stringify') | ||
var remark2retext = require('remark-retext') | ||
var english = require('retext-english') | ||
var equality = require('retext-equality') | ||
import {readSync} from 'to-vfile' | ||
import {reporter} from 'vfile-reporter' | ||
import {unified} from 'unified' | ||
import remarkParse from 'remark-parse' | ||
import remarkStringify from 'remark-stringify' | ||
import remarkRetext from 'remark-retext' | ||
import retextEnglish from 'retext-english' | ||
import retextEquality from 'retext-equality' | ||
const file = readSync('example.md') | ||
unified() | ||
.use(parse) | ||
.use( | ||
remark2retext, | ||
unified() | ||
.use(english) | ||
.use(equality) | ||
) | ||
.use(stringify) | ||
.process(vfile.readSync('example.md'), function(err, file) { | ||
console.error(report(err || file)) | ||
.use(remarkParse) | ||
.use(remarkRetext, unified().use(retextEnglish).use(retextEquality)) | ||
.use(remarkStringify) | ||
.process(file) | ||
.then((file) => { | ||
console.error(reporter(file)) | ||
}) | ||
@@ -61,3 +68,3 @@ ``` | ||
example.md | ||
1:10-1:14 warning `guys` may be insensitive, use `people`, `persons`, `folks` instead gals-men retext-equality | ||
1:10-1:14 warning `guys` may be insensitive, use `people`, `persons`, `folks` instead gals-man retext-equality | ||
@@ -69,4 +76,7 @@ ⚠ 1 warning | ||
### `origin.use(remark2retext, destination[, options])` | ||
This package exports no identifiers. | ||
The default export is `remarkRetext`. | ||
### `unified().use(remarkRetext, destination[, options])` | ||
[**remark**][remark] ([**mdast**][mdast]) plugin to bridge or mutate to | ||
@@ -124,5 +134,5 @@ [**retext**][retext] ([**nlcst**][nlcst]). | ||
[build-badge]: https://img.shields.io/travis/remarkjs/remark-retext/master.svg | ||
[build-badge]: https://github.com/remarkjs/remark-retext/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/remarkjs/remark-retext | ||
[build]: https://github.com/remarkjs/remark-retext/actions | ||
@@ -147,5 +157,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-retext.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[chat]: https://spectrum.chat/unified/remark | ||
[chat]: https://github.com/remarkjs/remark/discussions | ||
@@ -156,7 +166,7 @@ [npm]: https://docs.npmjs.com/cli/install | ||
[contributing]: https://github.com/remarkjs/.github/blob/master/contributing.md | ||
[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md | ||
[support]: https://github.com/remarkjs/.github/blob/master/support.md | ||
[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md | ||
[coc]: https://github.com/remarkjs/.github/blob/master/code-of-conduct.md | ||
[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md | ||
@@ -163,0 +173,0 @@ [license]: license |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12123
5
94
195
Yes
4
14
+ Added@types/mdast@^3.0.0
+ Added@types/unist@^2.0.0
+ Addedunified@^10.0.0
+ Added@types/mdast@3.0.15(transitive)
+ Added@types/nlcst@1.0.4(transitive)
+ Added@types/unist@2.0.11(transitive)
+ Addedbail@2.0.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedis-buffer@2.0.5(transitive)
+ Addedis-plain-obj@4.1.0(transitive)
+ Addedmdast-util-to-nlcst@5.2.1(transitive)
+ Addednlcst-to-string@3.1.1(transitive)
+ Addedtrough@2.2.0(transitive)
+ Addedunified@10.1.2(transitive)
+ Addedunist-util-position@4.0.4(transitive)
+ Addedunist-util-stringify-position@3.0.3(transitive)
+ Addedvfile@5.3.7(transitive)
+ Addedvfile-location@4.1.0(transitive)
+ Addedvfile-message@3.1.4(transitive)
- Removedmdast-util-to-nlcst@4.0.1(transitive)
- Removednlcst-to-string@2.0.4(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedunist-util-position@3.1.0(transitive)
- Removedvfile-location@3.2.0(transitive)
Updatedmdast-util-to-nlcst@^5.0.0