remark-textr
Advanced tools
Comparing version 5.0.1 to 6.0.0
@@ -1,31 +0,3 @@ | ||
/** | ||
* Plugin to improve typography with Textr. | ||
* | ||
* @type {import('unified').Plugin<[Options?]|void[], Root>} | ||
*/ | ||
export default function remarkTextr( | ||
options?: void | Options | undefined | ||
): | ||
| void | ||
| import('unified').Transformer<import('mdast').Root, import('mdast').Root> | ||
export type Root = import('mdast').Root | ||
/** | ||
* A textr plugin. | ||
*/ | ||
export type TextrPlugin = ( | ||
value: string, | ||
options?: object | undefined | ||
) => string | void | ||
/** | ||
* Configuration. | ||
*/ | ||
export type Options = { | ||
/** | ||
* Textr plugins. | ||
*/ | ||
plugins?: (string | TextrPlugin)[] | undefined | ||
/** | ||
* Configuration passed to `textr`. | ||
*/ | ||
options?: object | undefined | ||
} | ||
export { default } from "./lib/index.js"; | ||
export type Options = import('./lib/index.js').Options; | ||
export type TextrPlugin = import('./lib/index.js').TextrPlugin; |
48
index.js
/** | ||
* @typedef {import('mdast').Root} Root | ||
* | ||
* @callback TextrPlugin | ||
* A textr plugin. | ||
* @param {string} value | ||
* Value to transform. | ||
* @param {object} [options] | ||
* Global configuration passed to textr. | ||
* @returns {string|void} | ||
* Changed text (optional). | ||
* | ||
* @typedef Options | ||
* Configuration. | ||
* @property {Array.<string|TextrPlugin>} [plugins] | ||
* Textr plugins. | ||
* @property {object} [options] | ||
* Configuration passed to `textr`. | ||
* @typedef {import('./lib/index.js').Options} Options | ||
* @typedef {import('./lib/index.js').TextrPlugin} TextrPlugin | ||
*/ | ||
import {visit} from 'unist-util-visit' | ||
import textr from 'textr' | ||
/** | ||
* Plugin to improve typography with Textr. | ||
* | ||
* @type {import('unified').Plugin<[Options?]|void[], Root>} | ||
*/ | ||
export default function remarkTextr(options = {}) { | ||
const plugins = options.plugins || [] | ||
const promise = Promise.all( | ||
plugins.map( | ||
/** | ||
* @returns {Promise<TextrPlugin>} | ||
*/ | ||
// Default is an `any`. | ||
// type-coverage:ignore-next-line | ||
async (fn) => (typeof fn === 'string' ? (await import(fn)).default : fn) | ||
) | ||
).then((list) => textr(options.options || {}).use(...list)) | ||
return async (tree) => { | ||
const typography = await promise | ||
visit(tree, 'text', (node) => { | ||
node.value = typography.exec(node.value) | ||
}) | ||
} | ||
} | ||
export {default} from './lib/index.js' |
{ | ||
"name": "remark-textr", | ||
"version": "5.0.1", | ||
"version": "6.0.0", | ||
"description": "remark plugin to improve typography with Textr", | ||
"license": "MIT", | ||
"keywords": [ | ||
"unified", | ||
"markdown", | ||
"mdast", | ||
"plugin", | ||
"remark", | ||
"remark-plugin", | ||
"plugin", | ||
"mdast", | ||
"markdown", | ||
"text", | ||
"textr", | ||
"typo", | ||
"typographic", | ||
"typography", | ||
"typographic", | ||
"typo", | ||
"textr" | ||
"unified" | ||
], | ||
@@ -34,5 +34,5 @@ "repository": "remarkjs/remark-textr", | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"exports": "./index.js", | ||
"files": [ | ||
"lib/", | ||
"index.d.ts", | ||
@@ -42,44 +42,39 @@ "index.js" | ||
"dependencies": { | ||
"@types/mdast": "^3.0.0", | ||
"@types/mdast": "^4.0.0", | ||
"textr": "^0.3.0", | ||
"unified": "^10.0.0", | ||
"unist-util-visit": "^4.0.0" | ||
"unist-util-visit": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/tape": "^4.0.0", | ||
"@types/node": "^20.0.0", | ||
"@types/textr": "^0.3.0", | ||
"c8": "^7.0.0", | ||
"prettier": "^2.0.0", | ||
"remark": "^14.0.0", | ||
"remark-cli": "^10.0.0", | ||
"c8": "^8.0.0", | ||
"prettier": "^3.0.0", | ||
"remark": "^15.0.0", | ||
"remark-cli": "^11.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"typescript": "^5.0.0", | ||
"typographic-ellipses": "^1.0.0", | ||
"typographic-quotes": "^2.0.0", | ||
"xo": "^0.45.0" | ||
"xo": "^0.56.0" | ||
}, | ||
"scripts": { | ||
"build": "rimraf \"*.d.ts\" && tsc && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"build": "tsc --build --clean && tsc --build && type-coverage", | ||
"format": "remark . --frail --output --quiet && prettier . --log-level warn --write && xo --fix", | ||
"prepack": "npm run build && npm run format", | ||
"test": "npm run build && npm run format && npm run test-coverage", | ||
"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" | ||
"test-coverage": "c8 --100 --reporter lcov npm run test-api" | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"bracketSpacing": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
"tabWidth": 2, | ||
"trailingComma": "none", | ||
"useTabs": false | ||
}, | ||
"xo": { | ||
"prettier": true | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
"remark-preset-wooorm" | ||
] | ||
@@ -90,5 +85,11 @@ }, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"xo": { | ||
"prettier": true, | ||
"rules": { | ||
"unicorn/prefer-string-replace-all": "off" | ||
} | ||
} | ||
} |
151
readme.md
@@ -12,3 +12,3 @@ # remark-textr | ||
**[remark][]** plugin to [improve typography][typewriter-habits] with | ||
[**Textr**][textr]. | ||
**[Textr][]**. | ||
@@ -23,2 +23,4 @@ ## Contents | ||
* [`unified().use(remarkTextr[, options])`](#unifieduseremarktextr-options) | ||
* [`Options`](#options) | ||
* [`TextrPlugin`](#textrplugin) | ||
* [Types](#types) | ||
@@ -34,8 +36,2 @@ * [Compatibility](#compatibility) | ||
**unified** is a project that transforms content with abstract syntax trees | ||
(ASTs). | ||
**remark** adds support for markdown to unified. | ||
**mdast** is the markdown AST that remark uses. | ||
This is a remark plugin that transforms mdast with Textr. | ||
## When should I use this? | ||
@@ -47,8 +43,8 @@ | ||
On the other hand, ASTs are powerful, so some things are better done with | ||
custom plugins: see [Create a plugin][create-a-plugin]. | ||
custom plugins: see [Create a plugin][unified-create-a-plugin]. | ||
## Install | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). | ||
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: | ||
This package is [ESM only][esm]. | ||
In Node.js (version 16+), install with [npm][]: | ||
@@ -59,13 +55,13 @@ ```sh | ||
In Deno with [Skypack][]: | ||
In Deno with [`esm.sh`][esmsh]: | ||
```js | ||
import remarkTextr from 'https://cdn.skypack.dev/remark-textr@5?dts' | ||
import remarkTextr from 'https://esm.sh/remark-textr@6' | ||
``` | ||
In browsers with [Skypack][]: | ||
In browsers with [`esm.sh`][esmsh]: | ||
```html | ||
<script type="module"> | ||
import remarkTextr from 'https://cdn.skypack.dev/remark-textr@5?min' | ||
import remarkTextr from 'https://esm.sh/remark-textr@6?bundle' | ||
</script> | ||
@@ -76,3 +72,3 @@ ``` | ||
Say we have the following file, `example.md`: | ||
Say we have the following file `example.md`: | ||
@@ -87,23 +83,23 @@ ````markdown | ||
And our module `example.js` looks as follows: | ||
…and a module `example.js`: | ||
```js | ||
import {read} from 'to-vfile' | ||
/** | ||
* @typedef {import('remark-textr').TextrPlugin} TextrPlugin | ||
*/ | ||
import {remark} from 'remark' | ||
import remarkTextr from 'remark-textr' | ||
import {read} from 'to-vfile' | ||
main() | ||
const file = await remark() | ||
.use(remarkTextr, {plugins: [ellipses]}) | ||
.process(await read('example.md')) | ||
async function main() { | ||
const file = await remark() | ||
.use(remarkTextr, {plugins: [ellipses]}) | ||
.process(await read('example.md')) | ||
console.log(String(file)) | ||
console.log(String(file)) | ||
} | ||
/** | ||
* Textr plugin: a function that replaces triple dots with ellipses. | ||
* Replace triple dots with ellipses. | ||
* | ||
* @type {import('remark-textr').TextrPlugin} | ||
* @type {TextrPlugin} | ||
*/ | ||
@@ -115,3 +111,3 @@ function ellipses(input) { | ||
Yields: | ||
…then running `node example.js` yields: | ||
@@ -129,16 +125,36 @@ ````markdown | ||
This package exports no identifiers. | ||
The default export is `remarkTextr`. | ||
The default export is [`remarkTextr`][api-remark-text]. | ||
### `unified().use(remarkTextr[, options])` | ||
Plugin to [improve typography][typewriter-habits] with [**Textr**][textr]. | ||
[Improve typography][typewriter-habits] with [Textr][]. | ||
##### `options` | ||
###### Parameters | ||
Configuration. | ||
* `options` ([`Options`][api-options], optional) | ||
— configuration | ||
###### `options.plugins` | ||
###### Returns | ||
List of [Textr][] plugins (`Array.<string|Function>?`). | ||
If strings are passed in, those are loaded with `import`. | ||
Transform ([`Transformer`][unified-transformer]). | ||
### `Options` | ||
Configuration (TypeScript type). | ||
###### Fields | ||
* `options` (`object`, optional) | ||
— configuration passed to `textr`; | ||
for example, you may want to set the ISO 639-1 [locale code][textr-locale] | ||
of the content, which is important for stuff like the correct primary and | ||
secondary quotes | ||
* `plugins` (`Array<TextrPlugin | string>`, optional) | ||
— textr plugins; | ||
if strings are passed in, those are loaded with `import` | ||
### `TextrPlugin` | ||
Textr plugin (TypeScript type). | ||
Textr plugins are available on npm labelled with a [`textr`][textr-plugins] | ||
@@ -148,22 +164,29 @@ keyword. | ||
###### `options.options` | ||
###### Parameters | ||
[Textr][] options (`Object?`). | ||
For example, you may want to set the [ISO 639-1][iso] [locale code][locale] of | ||
the content, which is important for stuff like the correct primary and secondary | ||
quotes. | ||
* `value` (`string`) | ||
— value to transform | ||
* `options` (`object`) | ||
— global configuration passed to textr | ||
###### Returns | ||
Changed text (`string`, optional). | ||
## Types | ||
This package is fully typed with [TypeScript][]. | ||
It exports `Options` and `TextrPlugin` types, which specify the interface of the | ||
accepted options and Textr plugins. | ||
It exports the additional types [`Options`][api-options] and | ||
[`TextrPlugin`][api-textr-plugin]. | ||
## Compatibility | ||
Projects maintained by the unified collective are compatible with all maintained | ||
Projects maintained by the unified collective are compatible with maintained | ||
versions of Node.js. | ||
As of now, that is Node.js 12.20+, 14.14+, and 16.0+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
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-textr@^6`, | ||
compatible with Node.js 16. | ||
This plugin works with `unified` version 6+ and `remark` version 7+. | ||
@@ -173,4 +196,4 @@ | ||
Use of `remark-textr` does not involve [**rehype**][rehype] ([**hast**][hast]) | ||
or user content so there are no openings for [cross-site scripting (XSS)][xss] | ||
Use of `remark-textr` does not involve **[rehype][]** (**[hast][]**) or user | ||
content so there are no openings for [cross-site scripting (XSS)][wiki-xss] | ||
attacks. | ||
@@ -207,5 +230,5 @@ [Textr][] operates on text nodes, which are always escaped by remark. | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-textr.svg | ||
[size-badge]: https://img.shields.io/bundlejs/size/remark-textr | ||
[size]: https://bundlephobia.com/result?p=remark-textr | ||
[size]: https://bundlejs.com/?q=remark-textr | ||
@@ -224,4 +247,6 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[skypack]: https://www.skypack.dev | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[esmsh]: https://esm.sh | ||
[health]: https://github.com/remarkjs/.github | ||
@@ -239,24 +264,30 @@ | ||
[hast]: https://github.com/syntax-tree/hast | ||
[rehype]: https://github.com/rehypejs/rehype | ||
[remark]: https://github.com/remarkjs/remark | ||
[unified]: https://github.com/unifiedjs/unified | ||
[textr]: https://github.com/A/textr | ||
[textr-locale]: https://github.com/A/textr#locale-option-consistence | ||
[textr-plugins]: https://www.npmjs.com/browse/keyword/textr | ||
[locale]: https://github.com/A/textr#locale-option-consistence | ||
[typescript]: https://www.typescriptlang.org | ||
[iso]: https://www.wikiwand.com/en/List_of_ISO_639-1_codes | ||
[typewriter-habits]: https://practicaltypography.com/typewriter-habits.html | ||
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting | ||
[unified]: https://github.com/unifiedjs/unified | ||
[typescript]: https://www.typescriptlang.org | ||
[unified-create-a-plugin]: https://unifiedjs.com/learn/guide/create-a-plugin/ | ||
[rehype]: https://github.com/rehypejs/rehype | ||
[unified-transformer]: https://github.com/unifiedjs/unified#transformer | ||
[hast]: https://github.com/syntax-tree/hast | ||
[wiki-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting | ||
[create-a-plugin]: https://unifiedjs.com/learn/guide/create-a-plugin/ | ||
[api-options]: #options | ||
[api-remark-text]: #unifieduseremarktextr-options | ||
[api-textr-plugin]: #textrplugin |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13722
3
12
7
111
280
1
+ Added@types/mdast@4.0.4(transitive)
+ Added@types/unist@3.0.2(transitive)
+ Addedunist-util-is@6.0.0(transitive)
+ Addedunist-util-visit@5.0.0(transitive)
+ Addedunist-util-visit-parents@6.0.1(transitive)
- Removedunified@^10.0.0
- Removed@types/mdast@3.0.15(transitive)
- Removed@types/unist@2.0.10(transitive)
- Removedbail@2.0.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedis-buffer@2.0.5(transitive)
- Removedis-plain-obj@4.1.0(transitive)
- Removedtrough@2.2.0(transitive)
- Removedunified@10.1.2(transitive)
- Removedunist-util-is@5.2.1(transitive)
- Removedunist-util-stringify-position@3.0.3(transitive)
- Removedunist-util-visit@4.1.2(transitive)
- Removedunist-util-visit-parents@5.1.3(transitive)
- Removedvfile@5.3.7(transitive)
- Removedvfile-message@3.1.4(transitive)
Updated@types/mdast@^4.0.0
Updatedunist-util-visit@^5.0.0