remark-yaml-config
Advanced tools
Comparing version 6.0.1 to 7.0.0
@@ -1,11 +0,1 @@ | ||
/** | ||
* Plugin to configure it with YAML frontmatter. | ||
* | ||
* @type {import('unified').Plugin<void[], Root>} | ||
*/ | ||
export default function remarkYamlConfig(): | ||
| void | ||
| import('unified').Transformer<import('mdast').Root, import('mdast').Root> | ||
export type Root = import('mdast').Root | ||
export type YAML = import('mdast').YAML | ||
export type Extension = import('mdast-util-to-markdown').Options | ||
export { default } from "./lib/index.js"; |
46
index.js
@@ -1,45 +0,1 @@ | ||
/** | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {import('mdast').YAML} YAML | ||
* @typedef {import('mdast-util-to-markdown').Options} Extension | ||
*/ | ||
import jsYaml from 'js-yaml' | ||
/** | ||
* Plugin to configure it with YAML frontmatter. | ||
* | ||
* @type {import('unified').Plugin<void[], Root>} | ||
*/ | ||
export default function remarkYamlConfig() { | ||
const data = this.data() | ||
/** @type {Extension} */ | ||
const yamlConfig = { | ||
handlers: { | ||
/** @param {YAML} node */ | ||
yaml(node) { | ||
const data = jsYaml.load(node.value) | ||
/** @type {object|undefined} */ | ||
const config = | ||
data && typeof data === 'object' && 'remark' in data | ||
? // @ts-expect-error: hush we just checked. | ||
data.remark | ||
: undefined | ||
Object.assign(this.options, config || {}) | ||
// Like the source: | ||
// <https://github.com/syntax-tree/mdast-util-frontmatter/blob/583ae25/lib/to-markdown.js#L28> | ||
return '---' + (node.value ? '\n' + node.value : '') + '\n---' | ||
} | ||
} | ||
} | ||
const extensions = /** @type {Extension[]} */ ( | ||
// Other extensions | ||
/* c8 ignore next 2 */ | ||
data.toMarkdownExtensions | ||
? data.toMarkdownExtensions | ||
: (data.toMarkdownExtensions = []) | ||
) | ||
extensions.push(yamlConfig) | ||
} | ||
export {default} from './lib/index.js' |
{ | ||
"name": "remark-yaml-config", | ||
"version": "6.0.1", | ||
"version": "7.0.0", | ||
"description": "remark plugin to configure it with YAML frontmatter", | ||
"license": "MIT", | ||
"keywords": [ | ||
"unified", | ||
"config", | ||
"frontmatter", | ||
"markdown", | ||
"mdast", | ||
"options", | ||
"plugin", | ||
"remark", | ||
"remark-plugin", | ||
"plugin", | ||
"mdast", | ||
"markdown", | ||
"yaml", | ||
"frontmatter", | ||
"options", | ||
"config", | ||
"settings" | ||
"settings", | ||
"unified", | ||
"yaml" | ||
], | ||
@@ -31,5 +31,5 @@ "repository": "remarkjs/remark-yaml-config", | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"exports": "./index.js", | ||
"files": [ | ||
"lib/", | ||
"index.d.ts", | ||
@@ -39,43 +39,39 @@ "index.js" | ||
"dependencies": { | ||
"@types/mdast": "^3.0.0", | ||
"js-yaml": "^4.0.0", | ||
"mdast-util-to-markdown": "^1.0.0", | ||
"unified": "^10.0.0" | ||
"@types/mdast": "^4.0.0", | ||
"unified": "^11.0.0", | ||
"yaml": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
"prettier": "^2.0.0", | ||
"remark": "^14.0.0", | ||
"remark-cli": "^10.0.0", | ||
"remark-frontmatter": "^4.0.0", | ||
"remark-html": "^15.0.0", | ||
"@types/node": "^20.0.0", | ||
"c8": "^8.0.0", | ||
"prettier": "^3.0.0", | ||
"rehype-stringify": "^10.0.0", | ||
"remark": "^15.0.0", | ||
"remark-cli": "^11.0.0", | ||
"remark-frontmatter": "^5.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"remark-rehype": "^11.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.46.0" | ||
"typescript": "^5.0.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" | ||
] | ||
@@ -86,5 +82,8 @@ }, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"xo": { | ||
"prettier": true | ||
} | ||
} |
100
readme.md
@@ -33,8 +33,2 @@ # remark-yaml-config | ||
**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 configures how `remark-stringify` serializes mdast. | ||
## When should I use this? | ||
@@ -54,4 +48,4 @@ | ||
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][]: | ||
@@ -62,13 +56,13 @@ ```sh | ||
In Deno with [Skypack][]: | ||
In Deno with [`esm.sh`][esmsh]: | ||
```js | ||
import remarkYamlConfig from 'https://cdn.skypack.dev/remark-yaml-config@6?dts' | ||
import remarkYamlConfig from 'https://esm.sh/remark-yaml-config@7' | ||
``` | ||
In browsers with [Skypack][]: | ||
In browsers with [`esm.sh`][esmsh]: | ||
```html | ||
<script type="module"> | ||
import remarkYamlConfig from 'https://cdn.skypack.dev/remark-yaml-config@6?min' | ||
import remarkYamlConfig from 'https://esm.sh/remark-yaml-config@7?bundle' | ||
</script> | ||
@@ -87,29 +81,25 @@ ``` | ||
- Hello | ||
- Triton | ||
``` | ||
And our module `example.js` looks as follows: | ||
…and a module `example.js`: | ||
```js | ||
import {read} from 'to-vfile' | ||
import {remark} from 'remark' | ||
import remarkFrontmatter from 'remark-frontmatter' | ||
import remarkYamlConfig from 'remark-yaml-config' | ||
import {read} from 'to-vfile' | ||
main() | ||
const file = await remark() | ||
.use(remarkFrontmatter) | ||
.use(remarkYamlConfig) | ||
.process(await read('example.md')) | ||
async function main() { | ||
const file = await remark() | ||
.use(remarkFrontmatter) | ||
.use(remarkYamlConfig) | ||
.process(await read('example.md')) | ||
console.log(String(file)) | ||
} | ||
console.log(String(file)) | ||
``` | ||
> ⚠️ **Important**: [`remark-frontmatter`][remark-frontmatter] is required to | ||
> ⚠️ **Important**: [`remark-frontmatter`][remark-frontmatter] is needed to | ||
> support YAML frontmatter in markdown. | ||
Now running `node example.js` yields: | ||
…then running `node example.js` yields: | ||
@@ -119,6 +109,6 @@ ```markdown | ||
remark: | ||
bullet: "*" | ||
bullet: "+" | ||
--- | ||
+ Hello | ||
+ Triton | ||
``` | ||
@@ -129,3 +119,3 @@ | ||
This package exports no identifiers. | ||
The default export is `remarkYamlConfig`. | ||
The default export is [`remarkYamlConfig`][api-remark-yaml-config]. | ||
@@ -135,19 +125,29 @@ ### `unified().use(remarkYamlConfig)` | ||
Configure remark with YAML frontmatter. | ||
There are no options | ||
Parses YAML frontmatter and takes the value of the `remark` field as settings. | ||
The settings are passed to [`remark-stringify`][stringify-settings]. | ||
The settings are passed to [`remark-stringify`][remark-stringify-options]. | ||
###### Parameters | ||
There are no parameters. | ||
###### Returns | ||
Nothing (`undefined`). | ||
## Types | ||
This package is fully typed with [TypeScript][]. | ||
There are no extra exported types. | ||
It exports no additional types. | ||
## 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-yaml-config@^7`, | ||
compatible with Node.js 16. | ||
This plugin works with `remark` version 13+. | ||
@@ -160,3 +160,3 @@ Version 5 (and lower) worked with older versions of remark. | ||
If the markdown is user provided, this may open you up to a | ||
[cross-site scripting (XSS)][xss] attack. | ||
[cross-site scripting (XSS)][wiki-xss] attack. | ||
@@ -198,5 +198,5 @@ ## Related | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-yaml-config.svg | ||
[size-badge]: https://img.shields.io/bundlejs/size/remark-yaml-config | ||
[size]: https://bundlephobia.com/result?p=remark-yaml-config | ||
[size]: https://bundlejs.com/?q=remark-yaml-config | ||
@@ -215,11 +215,13 @@ [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 | ||
[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md | ||
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md | ||
[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md | ||
[support]: https://github.com/remarkjs/.github/blob/main/support.md | ||
[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md | ||
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md | ||
@@ -232,12 +234,14 @@ [license]: license | ||
[unified]: https://github.com/unifiedjs/unified | ||
[remark-frontmatter]: https://github.com/remarkjs/remark-frontmatter | ||
[remark-comment-config]: https://github.com/remarkjs/remark-comment-config | ||
[remark-stringify-options]: https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/readme.md#options | ||
[typescript]: https://www.typescriptlang.org | ||
[stringify-settings]: https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/readme.md#options | ||
[unified]: https://github.com/unifiedjs/unified | ||
[remark-comment-config]: https://github.com/remarkjs/remark-comment-config | ||
[wiki-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting | ||
[remark-frontmatter]: https://github.com/remarkjs/remark-frontmatter | ||
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting | ||
[api-remark-yaml-config]: #unifieduseremarkyamlconfig |
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
11226
3
12
7
59
237
+ Addedyaml@^2.0.0
+ Added@types/mdast@4.0.4(transitive)
+ Added@types/unist@3.0.3(transitive)
+ Addeddequal@2.0.3(transitive)
+ Addeddevlop@1.1.0(transitive)
+ Addedunified@11.0.5(transitive)
+ Addedunist-util-stringify-position@4.0.0(transitive)
+ Addedvfile@6.0.3(transitive)
+ Addedvfile-message@4.0.2(transitive)
+ Addedyaml@2.6.1(transitive)
- Removedjs-yaml@^4.0.0
- Removedmdast-util-to-markdown@^1.0.0
- Removed@types/mdast@3.0.15(transitive)
- Removed@types/unist@2.0.11(transitive)
- Removedargparse@2.0.1(transitive)
- Removedcharacter-entities@2.0.2(transitive)
- Removeddecode-named-character-reference@1.0.2(transitive)
- Removedis-buffer@2.0.5(transitive)
- Removedjs-yaml@4.1.0(transitive)
- Removedlongest-streak@3.1.0(transitive)
- Removedmdast-util-phrasing@3.0.1(transitive)
- Removedmdast-util-to-markdown@1.5.0(transitive)
- Removedmdast-util-to-string@3.2.0(transitive)
- Removedmicromark-util-character@1.2.0(transitive)
- Removedmicromark-util-decode-numeric-character-reference@1.1.0(transitive)
- Removedmicromark-util-decode-string@1.1.0(transitive)
- Removedmicromark-util-symbol@1.1.0(transitive)
- Removedmicromark-util-types@1.1.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)
- Removedzwitch@2.0.4(transitive)
Updated@types/mdast@^4.0.0
Updatedunified@^11.0.0