🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
87
node_modules/retext-smartypants/index.d.ts
generated
vendored
Normal file
87
node_modules/retext-smartypants/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* Plugin to replace dumb/straight/typewriter punctuation marks with smart/curly
|
||||
* punctuation marks.
|
||||
*
|
||||
* @type {import('unified').Plugin<[Options?]|[], Root>}
|
||||
*/
|
||||
export default function retextSmartypants(
|
||||
options?: Options | undefined
|
||||
):
|
||||
| void
|
||||
| import('unified').Transformer<import('nlcst').Root, import('nlcst').Root>
|
||||
export type Root = import('nlcst').Root
|
||||
export type Sentence = import('nlcst').Sentence
|
||||
export type Word = import('nlcst').Word
|
||||
export type Symbol = import('nlcst').Symbol
|
||||
export type Punctuation = import('nlcst').Punctuation
|
||||
export type SentenceContent = import('nlcst').SentenceContent
|
||||
/**
|
||||
* Quote characters.
|
||||
*/
|
||||
export type QuoteCharacterMap = {
|
||||
/**
|
||||
* Character to use for double quotes.
|
||||
*/
|
||||
double: string
|
||||
/**
|
||||
* Character to use for single quotes.
|
||||
*/
|
||||
single: string
|
||||
}
|
||||
/**
|
||||
* Configuration.
|
||||
*/
|
||||
export type Options = {
|
||||
/**
|
||||
* Create smart quotes.
|
||||
*
|
||||
* Converts straight double and single quotes to smart double or single
|
||||
* quotes.
|
||||
*/
|
||||
quotes?: boolean | undefined
|
||||
/**
|
||||
* Characters to use for opening double and single quotes.
|
||||
*/
|
||||
openingQuotes?: QuoteCharacterMap | undefined
|
||||
/**
|
||||
* Characters to use for closing double and single quotes.
|
||||
*/
|
||||
closingQuotes?: QuoteCharacterMap | undefined
|
||||
/**
|
||||
* Create smart ellipses.
|
||||
*
|
||||
* Converts triple dot characters (with or without spaces between) into a
|
||||
* single Unicode ellipsis character.
|
||||
*/
|
||||
ellipses?: boolean | undefined
|
||||
/**
|
||||
* Create smart quotes from backticks.
|
||||
*
|
||||
* When `true`, converts double back-ticks into an opening double quote, and
|
||||
* double straight single quotes into a closing double quote.
|
||||
*
|
||||
* When `'all'`: does the preceding and converts single back-ticks into an
|
||||
* opening single quote, and a straight single quote into a closing single
|
||||
* smart quote.
|
||||
*
|
||||
* Note: Quotes can not be `true` when `backticks` is `'all'`;
|
||||
*/
|
||||
backticks?: boolean | 'all' | undefined
|
||||
/**
|
||||
* Create smart dashes.
|
||||
*
|
||||
* When `true`, converts two dashes into an em-dash character.
|
||||
*
|
||||
* When `'oldschool'`, converts two dashes into an en-dash, and three dashes
|
||||
* into an em-dash.
|
||||
*
|
||||
* When `'inverted'`, converts two dashes into an em-dash, and three dashes
|
||||
* into an en-dash.
|
||||
*/
|
||||
dashes?: boolean | 'oldschool' | 'inverted' | undefined
|
||||
}
|
||||
export type Method = (
|
||||
node: Punctuation | Symbol,
|
||||
index: number,
|
||||
parent: Word | Sentence
|
||||
) => void
|
411
node_modules/retext-smartypants/index.js
generated
vendored
Normal file
411
node_modules/retext-smartypants/index.js
generated
vendored
Normal file
|
@ -0,0 +1,411 @@
|
|||
/**
|
||||
* @typedef {import('nlcst').Root} Root
|
||||
* @typedef {import('nlcst').Sentence} Sentence
|
||||
* @typedef {import('nlcst').Word} Word
|
||||
* @typedef {import('nlcst').Symbol} Symbol
|
||||
* @typedef {import('nlcst').Punctuation} Punctuation
|
||||
* @typedef {import('nlcst').SentenceContent} SentenceContent
|
||||
*
|
||||
* @typedef QuoteCharacterMap
|
||||
* Quote characters.
|
||||
* @property {string} double
|
||||
* Character to use for double quotes.
|
||||
* @property {string} single
|
||||
* Character to use for single quotes.
|
||||
*
|
||||
* @typedef Options
|
||||
* Configuration.
|
||||
* @property {boolean} [quotes=true]
|
||||
* Create smart quotes.
|
||||
*
|
||||
* Converts straight double and single quotes to smart double or single
|
||||
* quotes.
|
||||
* @property {QuoteCharacterMap} [openingQuotes]
|
||||
* Characters to use for opening double and single quotes.
|
||||
* @property {QuoteCharacterMap} [closingQuotes]
|
||||
* Characters to use for closing double and single quotes.
|
||||
* @property {boolean} [ellipses=true]
|
||||
* Create smart ellipses.
|
||||
*
|
||||
* Converts triple dot characters (with or without spaces between) into a
|
||||
* single Unicode ellipsis character.
|
||||
* @property {boolean|'all'} [backticks=true]
|
||||
* Create smart quotes from backticks.
|
||||
*
|
||||
* When `true`, converts double back-ticks into an opening double quote, and
|
||||
* double straight single quotes into a closing double quote.
|
||||
*
|
||||
* When `'all'`: does the preceding and converts single back-ticks into an
|
||||
* opening single quote, and a straight single quote into a closing single
|
||||
* smart quote.
|
||||
*
|
||||
* Note: Quotes can not be `true` when `backticks` is `'all'`;
|
||||
* @property {boolean|'oldschool'|'inverted'} [dashes=true]
|
||||
* Create smart dashes.
|
||||
*
|
||||
* When `true`, converts two dashes into an em-dash character.
|
||||
*
|
||||
* When `'oldschool'`, converts two dashes into an en-dash, and three dashes
|
||||
* into an em-dash.
|
||||
*
|
||||
* When `'inverted'`, converts two dashes into an em-dash, and three dashes
|
||||
* into an en-dash.
|
||||
*
|
||||
* @callback Method
|
||||
* @param {Punctuation|Symbol} node
|
||||
* @param {number} index
|
||||
* @param {Word|Sentence} parent
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
import {visit} from 'unist-util-visit'
|
||||
import {toString} from 'nlcst-to-string'
|
||||
|
||||
const defaultClosingQuotes = {'"': '”', "'": '’'}
|
||||
const defaultOpeningQuotes = {'"': '“', "'": '‘'}
|
||||
|
||||
/**
|
||||
* @param {Options} options
|
||||
*/
|
||||
function createEducators(options) {
|
||||
const closingQuotes = options.closingQuotes
|
||||
? {'"': options.closingQuotes.double, "'": options.closingQuotes.single}
|
||||
: defaultClosingQuotes
|
||||
const openingQuotes = options.openingQuotes
|
||||
? {'"': options.openingQuotes.double, "'": options.openingQuotes.single}
|
||||
: defaultOpeningQuotes
|
||||
|
||||
const educators = {
|
||||
dashes: {
|
||||
/**
|
||||
* Transform two dahes into an em-dash.
|
||||
*
|
||||
* @type {Method}
|
||||
*/
|
||||
true(node) {
|
||||
if (node.value === '--') {
|
||||
node.value = '—'
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Transform three dahes into an em-dash, and two into an en-dash.
|
||||
*
|
||||
* @type {Method}
|
||||
*/
|
||||
oldschool(node) {
|
||||
if (node.value === '---') {
|
||||
node.value = '—'
|
||||
} else if (node.value === '--') {
|
||||
node.value = '–'
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Transform three dahes into an en-dash, and two into an em-dash.
|
||||
*
|
||||
* @type {Method}
|
||||
*/
|
||||
inverted(node) {
|
||||
if (node.value === '---') {
|
||||
node.value = '–'
|
||||
} else if (node.value === '--') {
|
||||
node.value = '—'
|
||||
}
|
||||
}
|
||||
},
|
||||
backticks: {
|
||||
/**
|
||||
* Transform double backticks and single quotes into smart quotes.
|
||||
*
|
||||
* @type {Method}
|
||||
*/
|
||||
true(node) {
|
||||
if (node.value === '``') {
|
||||
node.value = '“'
|
||||
} else if (node.value === "''") {
|
||||
node.value = '”'
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Transform single and double backticks and single quotes into smart quotes.
|
||||
*
|
||||
* @type {Method}
|
||||
*/
|
||||
all(node, index, parent) {
|
||||
educators.backticks.true(node, index, parent)
|
||||
|
||||
if (node.value === '`') {
|
||||
node.value = '‘'
|
||||
} else if (node.value === "'") {
|
||||
node.value = '’'
|
||||
}
|
||||
}
|
||||
},
|
||||
ellipses: {
|
||||
/**
|
||||
* Transform multiple dots into unicode ellipses.
|
||||
*
|
||||
* @type {Method}
|
||||
*/
|
||||
true(node, index, parent) {
|
||||
const value = node.value
|
||||
const siblings = parent.children
|
||||
|
||||
// Simple node with three dots and without white-space.
|
||||
if (/^\.{3,}$/.test(node.value)) {
|
||||
node.value = '…'
|
||||
return
|
||||
}
|
||||
|
||||
if (!/^\.+$/.test(value)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Search for dot-nodes with white-space between.
|
||||
/** @type {Array<SentenceContent>} */
|
||||
const nodes = []
|
||||
let position = index
|
||||
let count = 1
|
||||
|
||||
// It’s possible that the node is merged with an adjacent word-node. In that
|
||||
// code, we cannot transform it because there’s no reference to the
|
||||
// grandparent.
|
||||
while (--position > 0) {
|
||||
let sibling = siblings[position]
|
||||
|
||||
if (sibling.type !== 'WhiteSpaceNode') {
|
||||
break
|
||||
}
|
||||
|
||||
const queue = sibling
|
||||
sibling = siblings[--position]
|
||||
|
||||
if (
|
||||
sibling &&
|
||||
(sibling.type === 'PunctuationNode' ||
|
||||
sibling.type === 'SymbolNode') &&
|
||||
/^\.+$/.test(sibling.value)
|
||||
) {
|
||||
nodes.push(queue, sibling)
|
||||
|
||||
count++
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
if (count < 3) {
|
||||
return
|
||||
}
|
||||
|
||||
siblings.splice(index - nodes.length, nodes.length)
|
||||
|
||||
node.value = '…'
|
||||
}
|
||||
},
|
||||
quotes: {
|
||||
/**
|
||||
* Transform straight single- and double quotes into smart quotes.
|
||||
*
|
||||
* @type {Method}
|
||||
*/
|
||||
// eslint-disable-next-line complexity
|
||||
true(node, index, parent) {
|
||||
const siblings = parent.children
|
||||
const value = node.value
|
||||
|
||||
if (value !== '"' && value !== "'") {
|
||||
return
|
||||
}
|
||||
|
||||
const previous = siblings[index - 1]
|
||||
const next = siblings[index + 1]
|
||||
const nextNext = siblings[index + 2]
|
||||
const nextValue = next && toString(next)
|
||||
|
||||
if (
|
||||
next &&
|
||||
nextNext &&
|
||||
(next.type === 'PunctuationNode' || next.type === 'SymbolNode') &&
|
||||
nextNext.type !== 'WordNode'
|
||||
) {
|
||||
// Special case if the very first character is a quote followed by
|
||||
// punctuation at a non-word-break. Close the quotes by brute force.
|
||||
node.value = closingQuotes[value]
|
||||
} else if (
|
||||
nextNext &&
|
||||
(nextValue === '"' || nextValue === "'") &&
|
||||
nextNext.type === 'WordNode'
|
||||
) {
|
||||
// Special case for double sets of quotes:
|
||||
// `He said, "'Quoted' words in a larger quote."`
|
||||
node.value = openingQuotes[value]
|
||||
// @ts-expect-error: it’s a literal.
|
||||
next.value = openingQuotes[nextValue]
|
||||
} else if (next && /^\d\ds$/.test(nextValue)) {
|
||||
// Special case for decade abbreviations: `the '80s`
|
||||
node.value = closingQuotes[value]
|
||||
} else if (
|
||||
previous &&
|
||||
next &&
|
||||
(previous.type === 'WhiteSpaceNode' ||
|
||||
previous.type === 'PunctuationNode' ||
|
||||
previous.type === 'SymbolNode') &&
|
||||
next.type === 'WordNode'
|
||||
) {
|
||||
// Get most opening single quotes.
|
||||
node.value = openingQuotes[value]
|
||||
} else if (
|
||||
previous &&
|
||||
previous.type !== 'WhiteSpaceNode' &&
|
||||
previous.type !== 'SymbolNode' &&
|
||||
previous.type !== 'PunctuationNode'
|
||||
) {
|
||||
// Closing quotes.
|
||||
node.value = closingQuotes[value]
|
||||
} else if (
|
||||
!next ||
|
||||
next.type === 'WhiteSpaceNode' ||
|
||||
(value === "'" && nextValue === 's')
|
||||
) {
|
||||
node.value = closingQuotes[value]
|
||||
} else {
|
||||
node.value = openingQuotes[value]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return educators
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin to replace dumb/straight/typewriter punctuation marks with smart/curly
|
||||
* punctuation marks.
|
||||
*
|
||||
* @type {import('unified').Plugin<[Options?]|[], Root>}
|
||||
*/
|
||||
export default function retextSmartypants(options = {}) {
|
||||
/** @type {Array<Method>} */
|
||||
const methods = []
|
||||
/** @type {Options['quotes']} */
|
||||
let quotes
|
||||
/** @type {Options['ellipses']} */
|
||||
let ellipses
|
||||
/** @type {Options['backticks']} */
|
||||
let backticks
|
||||
/** @type {Options['dashes']} */
|
||||
let dashes
|
||||
|
||||
if ('quotes' in options) {
|
||||
quotes = options.quotes
|
||||
|
||||
if (quotes !== Boolean(quotes)) {
|
||||
throw new TypeError(
|
||||
'Illegal invocation: `' +
|
||||
quotes +
|
||||
'` ' +
|
||||
'is not a valid value for `quotes` in ' +
|
||||
'`smartypants`'
|
||||
)
|
||||
}
|
||||
} else {
|
||||
quotes = true
|
||||
}
|
||||
|
||||
if ('ellipses' in options) {
|
||||
ellipses = options.ellipses
|
||||
|
||||
if (ellipses !== Boolean(ellipses)) {
|
||||
throw new TypeError(
|
||||
'Illegal invocation: `' +
|
||||
ellipses +
|
||||
'` ' +
|
||||
'is not a valid value for `ellipses` in ' +
|
||||
'`smartypants`'
|
||||
)
|
||||
}
|
||||
} else {
|
||||
ellipses = true
|
||||
}
|
||||
|
||||
if ('backticks' in options) {
|
||||
backticks = options.backticks
|
||||
|
||||
if (backticks !== Boolean(backticks) && backticks !== 'all') {
|
||||
throw new TypeError(
|
||||
'Illegal invocation: `' +
|
||||
backticks +
|
||||
'` ' +
|
||||
'is not a valid value for `backticks` in ' +
|
||||
'`smartypants`'
|
||||
)
|
||||
}
|
||||
|
||||
if (backticks === 'all' && quotes === true) {
|
||||
throw new TypeError(
|
||||
'Illegal invocation: `backticks: ' +
|
||||
backticks +
|
||||
'` is not a valid value ' +
|
||||
'when `quotes: ' +
|
||||
quotes +
|
||||
'` in ' +
|
||||
'`smartypants`'
|
||||
)
|
||||
}
|
||||
} else {
|
||||
backticks = true
|
||||
}
|
||||
|
||||
if ('dashes' in options) {
|
||||
dashes = options.dashes
|
||||
|
||||
if (
|
||||
dashes !== Boolean(dashes) &&
|
||||
dashes !== 'oldschool' &&
|
||||
dashes !== 'inverted'
|
||||
) {
|
||||
throw new TypeError(
|
||||
'Illegal invocation: `' +
|
||||
dashes +
|
||||
'` ' +
|
||||
'is not a valid value for `dahes` in ' +
|
||||
'`smartypants`'
|
||||
)
|
||||
}
|
||||
} else {
|
||||
dashes = true
|
||||
}
|
||||
|
||||
const educators = createEducators(options)
|
||||
|
||||
if (quotes !== false) {
|
||||
methods.push(educators.quotes.true)
|
||||
}
|
||||
|
||||
if (ellipses !== false) {
|
||||
methods.push(educators.ellipses.true)
|
||||
}
|
||||
|
||||
if (backticks !== false) {
|
||||
methods.push(educators.backticks[backticks === true ? 'true' : backticks])
|
||||
}
|
||||
|
||||
if (dashes !== false) {
|
||||
methods.push(educators.dashes[dashes === true ? 'true' : dashes])
|
||||
}
|
||||
|
||||
return (tree) => {
|
||||
visit(tree, (node, position, parent) => {
|
||||
let index = -1
|
||||
|
||||
if (node.type === 'PunctuationNode' || node.type === 'SymbolNode') {
|
||||
while (++index < methods.length) {
|
||||
// @ts-expect-error: they’re literals.
|
||||
methods[index](node, position, parent)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
22
node_modules/retext-smartypants/license
generated
vendored
Normal file
22
node_modules/retext-smartypants/license
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
82
node_modules/retext-smartypants/package.json
generated
vendored
Normal file
82
node_modules/retext-smartypants/package.json
generated
vendored
Normal file
|
@ -0,0 +1,82 @@
|
|||
{
|
||||
"name": "retext-smartypants",
|
||||
"version": "5.2.0",
|
||||
"description": "retext plugin to implement SmartyPants",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unified",
|
||||
"retext",
|
||||
"retext-plugin",
|
||||
"smartypants",
|
||||
"typography",
|
||||
"quotes",
|
||||
"dashes",
|
||||
"ellipses"
|
||||
],
|
||||
"repository": "retextjs/retext-smartypants",
|
||||
"bugs": "https://github.com/retextjs/retext-smartypants/issues",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/nlcst": "^1.0.0",
|
||||
"nlcst-to-string": "^3.0.0",
|
||||
"unified": "^10.0.0",
|
||||
"unist-util-visit": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/tape": "^4.0.0",
|
||||
"c8": "^7.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^10.0.0",
|
||||
"remark-preset-wooorm": "^9.0.0",
|
||||
"retext": "^8.0.0",
|
||||
"rimraf": "^3.0.0",
|
||||
"tape": "^5.0.0",
|
||||
"type-coverage": "^2.0.0",
|
||||
"typescript": "^4.0.0",
|
||||
"xo": "^0.50.0"
|
||||
},
|
||||
"scripts": {
|
||||
"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 node --conditions development test.js",
|
||||
"test": "npm run build && npm run format && npm run test-coverage"
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
},
|
||||
"typeCoverage": {
|
||||
"atLeast": 100,
|
||||
"detail": true,
|
||||
"strict": true,
|
||||
"ignoreCatch": true
|
||||
}
|
||||
}
|
219
node_modules/retext-smartypants/readme.md
generated
vendored
Normal file
219
node_modules/retext-smartypants/readme.md
generated
vendored
Normal file
|
@ -0,0 +1,219 @@
|
|||
# retext-smartypants
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
[![Sponsors][sponsors-badge]][collective]
|
||||
[![Backers][backers-badge]][collective]
|
||||
[![Chat][chat-badge]][chat]
|
||||
|
||||
**[retext][]** plugin to apply [SmartyPants][].
|
||||
|
||||
## Contents
|
||||
|
||||
* [What is this?](#what-is-this)
|
||||
* [When should I use this?](#when-should-i-use-this)
|
||||
* [Install](#install)
|
||||
* [Use](#use)
|
||||
* [API](#api)
|
||||
* [`unified().use(retextSmartypants[, options])`](#unifieduseretextsmartypants-options)
|
||||
* [Types](#types)
|
||||
* [Compatibility](#compatibility)
|
||||
* [Contribute](#contribute)
|
||||
* [License](#license)
|
||||
|
||||
## What is this?
|
||||
|
||||
This package is a [unified][] ([retext][]) plugin to apply [SmartyPants][] to
|
||||
the syntax tree.
|
||||
It replaces straight/typewriter punctuation marks and symbols with smart/curly
|
||||
marks and symbols.
|
||||
|
||||
## When should I use this?
|
||||
|
||||
You can use this plugin any time there straight marks and symbols in prose,
|
||||
but you want to use smart ones instead.
|
||||
|
||||
## Install
|
||||
|
||||
This package is [ESM only][esm].
|
||||
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
|
||||
|
||||
```sh
|
||||
npm install retext-smartypants
|
||||
```
|
||||
|
||||
In Deno with [`esm.sh`][esmsh]:
|
||||
|
||||
```js
|
||||
import retextSmartypants from 'https://esm.sh/retext-smartypants@5'
|
||||
```
|
||||
|
||||
In browsers with [`esm.sh`][esmsh]:
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import retextSmartypants from 'https://esm.sh/retext-smartypants@5?bundle'
|
||||
</script>
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
import {retext} from 'retext'
|
||||
import retextSmartypants from 'retext-smartypants'
|
||||
|
||||
const file = await retext()
|
||||
.use(retextSmartypants)
|
||||
.process('He said, "A \'simple\' english sentence. . ."')
|
||||
|
||||
console.log(String(file))
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```txt
|
||||
He said, “A ‘simple’ english sentence…”
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
This package exports no identifiers.
|
||||
The default export is `retextSmartypants`.
|
||||
|
||||
### `unified().use(retextSmartypants[, options])`
|
||||
|
||||
Apply [SmartyPants][].
|
||||
|
||||
##### `options`
|
||||
|
||||
Configuration (optional).
|
||||
|
||||
###### `options.quotes`
|
||||
|
||||
Create smart quotes (`boolean`, default: `true`).
|
||||
|
||||
Converts straight double and single quotes to smart double or single quotes.
|
||||
The options `options.openingQuotes` and `options.closingQuotes` affect which
|
||||
quotes are considered smart.
|
||||
|
||||
###### `options.openingQuotes`
|
||||
|
||||
Characters to use for opening quotes `{single: '‘', double: '“'}`.
|
||||
|
||||
###### `options.closingQuotes`
|
||||
|
||||
Characters to use for closing quotes `{single: '’', double: '”'}`.
|
||||
|
||||
###### `options.ellipses`
|
||||
|
||||
Create smart ellipses (`boolean`, default: `true`).
|
||||
|
||||
Converts triple dot characters (with or without spaces) into a single unicode
|
||||
ellipsis character.
|
||||
|
||||
###### `options.backticks`
|
||||
|
||||
Create smart quotes from backticks (`boolean` or `'all'`, default: `true`).
|
||||
|
||||
When `true`, converts double backticks into an opening double quote, and
|
||||
double straight single quotes into a closing double quote.
|
||||
|
||||
When `'all'`: does the what `true` does with the addition of converting single
|
||||
backticks into an opening single quote, and a straight single quote into a
|
||||
closing single smart quote.
|
||||
|
||||
> 👉 **Note**: `options.quotes` can not be `true` when `backticks` is `'all'`.
|
||||
|
||||
###### `options.dashes`
|
||||
|
||||
Create smart dashes (`boolean` or `'oldschool'`, `'inverted'`, default: `true`).
|
||||
|
||||
When `true`, converts two dashes into an em dash character.
|
||||
|
||||
When `'oldschool'`, converts two dashes into an en dash, and three dashes into
|
||||
an em dash.
|
||||
|
||||
When `'inverted'`, converts two dashes into an em dash, and three dashes into
|
||||
an en dash.
|
||||
|
||||
## Types
|
||||
|
||||
This package is fully typed with [TypeScript][].
|
||||
It exports the additional types `Options` and `QuoteCharacterMap`.
|
||||
|
||||
## 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.
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md`][contributing] in [`retextjs/.github`][health] for ways
|
||||
to get started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
This project has a [code of conduct][coc].
|
||||
By interacting with this repository, organization, or community you agree to
|
||||
abide by its terms.
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://github.com/retextjs/retext-smartypants/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/retextjs/retext-smartypants/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/retextjs/retext-smartypants.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/retextjs/retext-smartypants
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/retext-smartypants.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/retext-smartypants
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/retext-smartypants.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=retext-smartypants
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[collective]: https://opencollective.com/unified
|
||||
|
||||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
|
||||
|
||||
[chat]: https://github.com/retextjs/retext/discussions
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
||||
|
||||
[esmsh]: https://esm.sh
|
||||
|
||||
[typescript]: https://www.typescriptlang.org
|
||||
|
||||
[health]: https://github.com/retextjs/.github
|
||||
|
||||
[contributing]: https://github.com/retextjs/.github/blob/main/contributing.md
|
||||
|
||||
[support]: https://github.com/retextjs/.github/blob/main/support.md
|
||||
|
||||
[coc]: https://github.com/retextjs/.github/blob/main/code-of-conduct.md
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[unified]: https://github.com/unifiedjs/unified
|
||||
|
||||
[retext]: https://github.com/retextjs/retext
|
||||
|
||||
[smartypants]: https://daringfireball.net/projects/smartypants
|
Loading…
Add table
Add a link
Reference in a new issue