remark-yaml-config
Advanced tools
Comparing version 3.0.2 to 4.0.0
103
index.js
@@ -1,82 +0,49 @@ | ||
/** | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer | ||
* @license MIT | ||
* @module remark:yaml-config | ||
* @fileoverview Configure remark with YAML front-matter. | ||
*/ | ||
'use strict'; | ||
/* eslint-env commonjs */ | ||
var jsYAML = require('js-yaml'); | ||
/* | ||
* Dependencies. | ||
*/ | ||
module.exports = yamlConfig; | ||
var jsYAML = require('js-yaml'); | ||
/* 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; | ||
/** | ||
* Wrapper factory. | ||
* | ||
* @param {Function} original - Spied on function. | ||
* @return {Function} - Spy. | ||
*/ | ||
function factory(original) { | ||
/** | ||
* Replacer for tokeniser or visitor. | ||
* | ||
* @param {Node|Function} node - Node, when visitor, | ||
* or `eat`. | ||
* @return {*} - Result of the spied on function. | ||
*/ | ||
function replacement(node) { | ||
var self = this; | ||
var result = original.apply(self, arguments); | ||
var marker = result && result.type ? result : node; | ||
var data; | ||
if (parser && parser.yamlFrontMatter) { | ||
parser.yamlFrontMatter = factory(parser.yamlFrontMatter); | ||
} | ||
try { | ||
data = jsYAML.safeLoad(marker.value); | ||
data = data && data.remark; | ||
if (compiler && compiler.yaml) { | ||
compiler.yaml = factory(compiler.yaml); | ||
} | ||
} | ||
if (data) { | ||
self.setOptions(data); | ||
} | ||
} catch (exception) { | ||
self.file.fail(exception.message, marker); | ||
} | ||
/* Wrapper factory. */ | ||
function factory(original) { | ||
replacement.locator = original.locator; | ||
return result; | ||
} | ||
return replacement; | ||
replacement.locator = original.locator; | ||
/* 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; | ||
return replacement; | ||
} | ||
try { | ||
data = jsYAML.safeLoad(marker.value); | ||
data = data && data.remark; | ||
/** | ||
* Modify remark to read configuration from comments. | ||
* | ||
* @param {Unified} processor - Instance. | ||
*/ | ||
function attacher(processor) { | ||
var Parser = processor.Parser; | ||
var Compiler = processor.Compiler; | ||
var parser = Parser && Parser.prototype.blockTokenizers; | ||
var compiler = Compiler && Compiler.prototype.visitors; | ||
if (parser && parser.yamlFrontMatter) { | ||
parser.yamlFrontMatter = factory(parser.yamlFrontMatter); | ||
if (data) { | ||
self.setOptions(data); | ||
} | ||
} catch (err) { | ||
self.file.fail(err.message, marker); | ||
} | ||
if (compiler && compiler.yaml) { | ||
compiler.yaml = factory(compiler.yaml); | ||
} | ||
return result; | ||
} | ||
} | ||
/* | ||
* Expose. | ||
*/ | ||
module.exports = attacher; |
{ | ||
"name": "remark-yaml-config", | ||
"version": "3.0.2", | ||
"version": "4.0.0", | ||
"description": "Configure remark with YAML front-matter", | ||
@@ -13,9 +13,3 @@ "license": "MIT", | ||
], | ||
"dependencies": { | ||
"js-yaml": "^3.5.2" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/wooorm/remark-yaml-config.git" | ||
}, | ||
"repository": "https://github.com/wooorm/remark-yaml-config", | ||
"bugs": "https://github.com/wooorm/remark-yaml-config/issues", | ||
@@ -26,26 +20,19 @@ "author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
], | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"js-yaml": "^3.5.2" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^13.0.0", | ||
"eslint": "^2.0.0", | ||
"browserify": "^14.0.0", | ||
"esmangle": "^1.0.0", | ||
"istanbul": "^0.4.0", | ||
"jscs": "^3.0.0", | ||
"jscs-jsdoc": "^2.0.0", | ||
"remark": "^5.0.0", | ||
"remark-cli": "^1.0.0", | ||
"remark-comment-config": "^4.0.0", | ||
"remark-github": "^5.0.0-alpha.1", | ||
"remark-html": "^4.0.0", | ||
"remark-lint": "^4.0.0", | ||
"remark-slug": "^4.0.0", | ||
"remark-usage": "^4.0.0-alpha.1", | ||
"remark-validate-links": "^4.0.0-alpha.1", | ||
"nyc": "^10.0.0", | ||
"remark": "^7.0.0", | ||
"remark-cli": "^3.0.0", | ||
"remark-html": "^6.0.0", | ||
"remark-preset-wooorm": "^2.0.0", | ||
"tape": "^4.0.0", | ||
"unified": "^4.1.2" | ||
"unified": "^5.0.0", | ||
"xo": "^0.17.1" | ||
}, | ||
@@ -55,11 +42,29 @@ "scripts": { | ||
"build-mangle": "esmangle remark-yaml-config.js > remark-yaml-config.min.js", | ||
"build-md": "remark . --quiet --frail", | ||
"build-md": "remark . -qfo", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint-api": "eslint .", | ||
"lint-style": "jscs --reporter inline .", | ||
"lint": "npm run lint-api && npm run lint-style", | ||
"lint": "xo", | ||
"test-api": "node test.js", | ||
"test-coverage": "istanbul cover test.js", | ||
"test-coverage": "nyc --reporter lcov tape test/index.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"xo": { | ||
"space": true, | ||
"rules": { | ||
"guard-for-in": "off", | ||
"no-eq-null": "off", | ||
"eqeqeq": "off" | ||
}, | ||
"ignores": [ | ||
"remark-yaml-config.js" | ||
] | ||
}, | ||
"remarkConfig": { | ||
"plugins": ["preset-wooorm"] | ||
} | ||
} |
@@ -13,29 +13,22 @@ # remark-yaml-config [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat] | ||
**remark-yaml-config** is also available as an AMD, CommonJS, and | ||
globals module, [uncompressed and compressed][releases]. | ||
## Usage | ||
Dependencies: | ||
```javascript | ||
var remark = require('remark'); | ||
var config = require('remark-yaml-config'); | ||
``` | ||
Process: | ||
var file = remark().use(config).processSync([ | ||
'---', | ||
'remark:', | ||
' commonmark: true', | ||
' bullet: "*"', | ||
'---', | ||
'', | ||
'1) Commonmark list (this is a parse setting)', | ||
'', | ||
'- Hello (this is a stringification setting)', | ||
'' | ||
].join('\n')); | ||
```javascript | ||
var file = remark().use(config).process([ | ||
'---', | ||
'remark:', | ||
' commonmark: true', | ||
' bullet: "*"', | ||
'---', | ||
'', | ||
'1) Commonmark list (this is a parse setting)', | ||
'', | ||
'- Hello (this is a stringification setting)', | ||
'' | ||
].join('\n')); | ||
console.log(String(file)); | ||
``` | ||
@@ -85,4 +78,2 @@ | ||
[releases]: https://github.com/wooorm/remark-yaml-config/releases | ||
[license]: LICENSE | ||
@@ -89,0 +80,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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
10
5935
38
90
1