mdast-zone
Advanced tools
Comparing version 3.0.1 to 3.0.2
71
index.js
@@ -1,34 +0,30 @@ | ||
'use strict'; | ||
'use strict' | ||
/* Expose. */ | ||
module.exports = zone; | ||
var commentMarker = require('mdast-comment-marker') | ||
var visit = require('unist-util-visit') | ||
/* Dependencies. */ | ||
var commentMarker = require('mdast-comment-marker'); | ||
var visit = require('unist-util-visit'); | ||
module.exports = zone | ||
/* Methods. */ | ||
var splice = [].splice; | ||
var splice = [].splice | ||
/* Run factory. */ | ||
function zone(node, name, callback) { | ||
var nodes = []; | ||
var start = null; | ||
var scope = null; | ||
var level = 0; | ||
var position; | ||
var nodes = [] | ||
var start = null | ||
var scope = null | ||
var level = 0 | ||
var position | ||
visit(node, gather); | ||
visit(node, gather) | ||
/* Gather one dimensional zones. */ | ||
function gather(node, index, parent) { | ||
var type = test(node); | ||
var type = test(node) | ||
if (scope && parent === scope) { | ||
if (type === 'start') { | ||
level++; | ||
level++ | ||
} | ||
if (type === 'end') { | ||
level--; | ||
level-- | ||
} | ||
@@ -41,14 +37,17 @@ | ||
parent: scope | ||
}); | ||
}) | ||
if (nodes) { | ||
splice.apply(scope.children, [position, index - position + 1].concat(nodes)); | ||
splice.apply( | ||
scope.children, | ||
[position, index - position + 1].concat(nodes) | ||
) | ||
} | ||
start = null; | ||
scope = null; | ||
position = null; | ||
nodes = []; | ||
start = null | ||
scope = null | ||
position = null | ||
nodes = [] | ||
} else { | ||
nodes.push(node); | ||
nodes.push(node) | ||
} | ||
@@ -58,6 +57,6 @@ } | ||
if (!scope && type === 'start') { | ||
level = 1; | ||
position = index; | ||
start = node; | ||
scope = parent; | ||
level = 1 | ||
position = index | ||
start = node | ||
scope = parent | ||
} | ||
@@ -68,15 +67,15 @@ } | ||
function test(node) { | ||
var marker = commentMarker(node); | ||
var attributes; | ||
var head; | ||
var marker = commentMarker(node) | ||
var attributes | ||
var head | ||
if (!marker || marker.name !== name) { | ||
return null; | ||
return null | ||
} | ||
attributes = marker.attributes; | ||
head = attributes.match(/(start|end)\b/); | ||
attributes = marker.attributes | ||
head = attributes.match(/(start|end)\b/) | ||
return head ? head[0] : null; | ||
return head ? head[0] : null | ||
} | ||
} |
{ | ||
"name": "mdast-zone", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "HTML comments as ranges in remark", | ||
@@ -15,3 +15,3 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/syntax-tree/mdast-zone", | ||
"repository": "syntax-tree/mdast-zone", | ||
"bugs": "https://github.com/syntax-tree/mdast-zone/issues", | ||
@@ -30,22 +30,22 @@ "author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
"devDependencies": { | ||
"browserify": "^14.0.0", | ||
"esmangle": "^1.0.0", | ||
"browserify": "^16.0.0", | ||
"is-hidden": "^1.0.1", | ||
"negate": "^1.0.0", | ||
"nyc": "^11.0.0", | ||
"remark": "^7.0.0", | ||
"remark-cli": "^3.0.0", | ||
"remark-preset-wooorm": "^3.0.0", | ||
"nyc": "^12.0.0", | ||
"prettier": "^1.14.2", | ||
"remark": "^9.0.0", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"tape": "^4.0.0", | ||
"xo": "^0.18.0" | ||
"tinyify": "^2.4.3", | ||
"xo": "^0.22.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark . -qfo", | ||
"build-bundle": "browserify index.js --bare -s mdastZone > mdast-zone.js", | ||
"build-mangle": "esmangle mdast-zone.js > mdast-zone.min.js", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint": "xo", | ||
"test-api": "node test/index.js", | ||
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", | ||
"build-bundle": "browserify . -s mdastZone > mdast-zone.js", | ||
"build-mangle": "browserify . -s mdastZone -p tinyify > mdast-zone.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test/index.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
}, | ||
@@ -58,4 +58,12 @@ "nyc": { | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"prettier": true, | ||
"esnext": false, | ||
@@ -62,0 +70,0 @@ "ignores": [ |
@@ -29,18 +29,20 @@ # mdast-zone [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] [![Chat][chat-badge]][chat] | ||
```javascript | ||
var vfile = require('to-vfile'); | ||
var remark = require('remark'); | ||
var zone = require('mdast-zone'); | ||
var vfile = require('to-vfile') | ||
var remark = require('remark') | ||
var zone = require('mdast-zone') | ||
remark() | ||
.use(plugin) | ||
.process(vfile.readSync('example.md'), function (err, file) { | ||
if (err) throw err; | ||
console.log(String(file)); | ||
}); | ||
.process(vfile.readSync('example.md'), function(err, file) { | ||
if (err) throw err | ||
console.log(String(file)) | ||
}) | ||
function plugin() { | ||
return transformer; | ||
function transformer(tree) { | ||
zone(tree, 'foo', mutate); | ||
return transform | ||
function transform(tree) { | ||
zone(tree, 'foo', mutate) | ||
} | ||
function mutate(start, nodes, end) { | ||
@@ -51,3 +53,3 @@ return [ | ||
end | ||
]; | ||
] | ||
} | ||
@@ -95,2 +97,10 @@ } | ||
## Contribute | ||
See [`contributing.md` in `syntax-tree/mdast`][contributing] for ways to get | ||
started. | ||
This organisation has a [Code of Conduct][coc]. By interacting with this | ||
repository, organisation, or community you agree to abide by its terms. | ||
## License | ||
@@ -125,1 +135,5 @@ | ||
[handler]: #function-handlerstart-nodes-end | ||
[contributing]: https://github.com/syntax-tree/mdast/blob/master/contributing.md | ||
[coc]: https://github.com/syntax-tree/mdast/blob/master/code-of-conduct.md |
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
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
7403
136
11
62