remark-yaml-config
Advanced tools
Comparing version 4.1.1 to 5.0.0
58
index.js
'use strict' | ||
var yaml = require('js-yaml') | ||
var warningIssued | ||
module.exports = yamlConfig | ||
var origin = 'remark-yaml-config:invalid-options' | ||
// Modify remark to read configuration from comments. | ||
function yamlConfig() { | ||
var Parser = this.Parser | ||
var Compiler = this.Compiler | ||
var parser = Parser && Parser.prototype.blockTokenizers | ||
var compiler = Compiler && Compiler.prototype.visitors | ||
var data = this.data() | ||
if (parser && parser.yamlFrontMatter) { | ||
parser.yamlFrontMatter = factory(parser.yamlFrontMatter) | ||
/* istanbul ignore next - old remark. */ | ||
if ( | ||
!warningIssued && | ||
this.Compiler && | ||
this.Compiler.prototype && | ||
this.Compiler.prototype.visitors | ||
) { | ||
warningIssued = true | ||
console.warn( | ||
'[remark-heading-gap] Warning: please upgrade to remark 13 to use this plugin' | ||
) | ||
} | ||
if (compiler && compiler.yaml) { | ||
compiler.yaml = factory(compiler.yaml) | ||
} | ||
} | ||
/* istanbul ignore next - other extensions */ | ||
if (!data.toMarkdownExtensions) data.toMarkdownExtensions = [] | ||
// Wrapper factory. | ||
function factory(original) { | ||
replacement.locator = original.locator | ||
data.toMarkdownExtensions.push({handlers: {yaml: yamlConfig}}) | ||
return replacement | ||
// Replacer for tokeniser or visitor. | ||
function replacement(node) { | ||
var self = this | ||
var result = original.apply(self, arguments) | ||
var marker = result && result.type ? result : node | ||
var data | ||
try { | ||
data = yaml.safeLoad(marker.value) | ||
data = data && data.remark | ||
if (data) { | ||
self.setOptions(data) | ||
} | ||
} catch (error) { | ||
self.file.fail(error.message, marker, origin) | ||
} | ||
return result | ||
function yamlConfig(node) { | ||
var data = yaml.safeLoad(node.value) | ||
Object.assign(this.options, (data && data.remark) || {}) | ||
// 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---' | ||
} | ||
} |
{ | ||
"name": "remark-yaml-config", | ||
"version": "4.1.1", | ||
"version": "5.0.0", | ||
"description": "remark plugin to configure it with YAML frontmatter", | ||
@@ -39,14 +39,14 @@ "license": "MIT", | ||
"prettier": "^2.0.0", | ||
"remark": "^11.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-frontmatter": "^1.0.0", | ||
"remark-html": "^10.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.0.0", | ||
"unified": "^8.0.0", | ||
"xo": "^0.28.0" | ||
"remark": "^13.0.0-alpha.1", | ||
"remark-cli": "^8.0.0", | ||
"remark-frontmatter": "^3.0.0", | ||
"remark-html": "^13.0.0", | ||
"remark-preset-wooorm": "^7.0.0", | ||
"tape": "^5.0.0", | ||
"tinyify": "^3.0.0", | ||
"unified": "^9.0.0", | ||
"xo": "^0.33.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"format": "remark . -qfo && prettier . --write && xo --fix", | ||
"build-bundle": "browserify . -s remarkYamlConfig > remark-yaml-config.js", | ||
@@ -53,0 +53,0 @@ "build-mangle": "browserify . -s remarkYamlConfig -p tinyify > remark-yaml-config.min.js", |
@@ -14,2 +14,10 @@ # remark-yaml-config | ||
## Important! | ||
This plugin is affected by the new parser in remark | ||
([`micromark`](https://github.com/micromark/micromark), | ||
see [`remarkjs/remark#536`](https://github.com/remarkjs/remark/pull/536)). | ||
Use version 4 while you’re still on remark 12. | ||
Use version 5 for remark 13+. | ||
## Install | ||
@@ -30,9 +38,6 @@ | ||
remark: | ||
commonmark: true | ||
bullet: "*" | ||
--- | ||
1) Commonmark list (this is a parse setting) | ||
* Hello (this is a stringify setting) | ||
- Hello | ||
``` | ||
@@ -62,9 +67,6 @@ | ||
remark: | ||
commonmark: true | ||
bullet: "*" | ||
--- | ||
1. Commonmark list (this is a parse setting) | ||
* Hello (this is a stringify setting) | ||
* Hello | ||
``` | ||
@@ -78,3 +80,3 @@ | ||
Takes the `'remark'` field in the frontmatter and passes it as configuration to | ||
[parse][parse-settings] and [stringify][stringify-settings]. | ||
[`remark-stringify`][stringify-settings]. | ||
@@ -113,3 +115,3 @@ Just like [`remark-comment-config`][remark-comment-config], but YAML is | ||
[build-badge]: https://img.shields.io/travis/remarkjs/remark-yaml-config/master.svg | ||
[build-badge]: https://img.shields.io/travis/remarkjs/remark-yaml-config.svg | ||
@@ -136,5 +138,5 @@ [build]: https://travis-ci.org/remarkjs/remark-yaml-config | ||
[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 | ||
@@ -145,7 +147,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 | ||
@@ -158,6 +160,4 @@ [license]: license | ||
[parse-settings]: https://github.com/remarkjs/remark/blob/master/packages/remark-parse/readme.md#options | ||
[stringify-settings]: https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/readme.md#options | ||
[stringify-settings]: https://github.com/remarkjs/remark/blob/master/packages/remark-stringify/readme.md#options | ||
[remark-comment-config]: https://github.com/remarkjs/remark-comment-config | ||
@@ -164,0 +164,0 @@ |
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
8340
30