mdast-range
Advanced tools
Comparing version 1.0.1 to 2.0.0
{ | ||
"name": "mdast-range", | ||
"version": "1.0.1", | ||
"description": "Patch index-based ranges on mdast nodes", | ||
"license": "MIT", | ||
"keywords": [ | ||
"range", | ||
"location", | ||
"position", | ||
"node", | ||
"mdast" | ||
], | ||
"dependencies": { | ||
"unist-util-visit": "^1.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/wooorm/mdast-range.git" | ||
}, | ||
"author": "Titus Wormer <tituswormer@gmail.com>", | ||
"files": [ | ||
"index.js", | ||
"LICENSE" | ||
], | ||
"devDependencies": { | ||
"browserify": "^11.0.0", | ||
"eslint": "^1.0.0", | ||
"esmangle": "^1.0.0", | ||
"istanbul": "^0.3.0", | ||
"jscs": "^2.0.0", | ||
"jscs-jsdoc": "^1.0.0", | ||
"mdast": "^1.0.0", | ||
"mdast-github": "^1.0.0", | ||
"mdast-lint": "^1.0.0", | ||
"mdast-toc": "^1.0.0", | ||
"mdast-usage": "^1.0.0", | ||
"mdast-comment-config": "^1.0.0", | ||
"mocha": "^2.0.0" | ||
}, | ||
"scripts": { | ||
"test-api": "mocha --check-leaks test.js", | ||
"test-coverage": "istanbul cover _mocha -- test.js", | ||
"test-travis": "npm run test-coverage", | ||
"test": "npm run test-api", | ||
"lint-api": "eslint .", | ||
"lint-style": "jscs --reporter inline .", | ||
"lint": "npm run lint-api && npm run lint-style", | ||
"make": "npm run lint && npm run test-coverage", | ||
"bundle": "browserify --no-builtins index.js -s mdastRange > mdast-range.js", | ||
"postbundle": "esmangle mdast-range.js > mdast-range.min.js", | ||
"build-md": "mdast . --quiet", | ||
"build": "npm run bundle && npm run build-md" | ||
} | ||
} | ||
"version": "2.0.0", | ||
"description": "Renamed to remark-range" | ||
} |
343
readme.md
@@ -1,342 +0,3 @@ | ||
# mdast-range [![Build Status](https://img.shields.io/travis/wooorm/mdast-range.svg)](https://travis-ci.org/wooorm/mdast-range) [![Coverage Status](https://img.shields.io/codecov/c/github/wooorm/mdast-range.svg)](https://codecov.io/github/wooorm/mdast-range) | ||
# mdast-range | ||
Patch index-based ranges on **mdast** nodes, so you can slice sources! | ||
## Installation | ||
[npm](https://docs.npmjs.com/cli/install) | ||
```bash | ||
npm install mdast-range | ||
``` | ||
[Component.js](https://github.com/componentjs/component) | ||
```bash | ||
component install wooorm/mdast-range | ||
``` | ||
[Bower](http://bower.io/#install-packages) | ||
```bash | ||
bower install mdast-range | ||
``` | ||
[Duo](http://duojs.org/#getting-started) | ||
```javascript | ||
var range = require('wooorm/mdast-range'); | ||
``` | ||
UMD: globals, AMD, and CommonJS ([uncompressed](mdast-range.js) and [compressed](mdast-range.min.js)): | ||
```html | ||
<script src="path/to/mdast.js"></script> | ||
<script src="path/to/mdast-range.js"></script> | ||
<script> | ||
mdast.use(mdastRange); | ||
</script> | ||
``` | ||
## Table of Contents | ||
* [Usage](#usage) | ||
* [API](#api) | ||
* [mdast.use(range)](#mdastuserange) | ||
* [License](#license) | ||
## Usage | ||
Dependencies and input: | ||
```javascript | ||
var range = require('mdast-range'); | ||
var mdast = require('mdast').use(range); | ||
var doc = 'Some *emphasis*,\n**strongness**,\nand `code`.'; | ||
``` | ||
And when the plugin is run, the ast looks as follows: | ||
```javascript | ||
mdast.process(doc); | ||
``` | ||
Note the `offset` properties. | ||
```json | ||
{ | ||
"type": "root", | ||
"children": [ | ||
{ | ||
"type": "paragraph", | ||
"children": [ | ||
{ | ||
"type": "text", | ||
"value": "Some ", | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 1, | ||
"offset": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 6, | ||
"offset": 5 | ||
}, | ||
"indent": [] | ||
} | ||
}, | ||
{ | ||
"type": "emphasis", | ||
"children": [ | ||
{ | ||
"type": "text", | ||
"value": "emphasis", | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 7, | ||
"offset": 6 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 15, | ||
"offset": 14 | ||
}, | ||
"indent": [] | ||
} | ||
} | ||
], | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 6, | ||
"offset": 5 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 16, | ||
"offset": 15 | ||
}, | ||
"indent": [] | ||
} | ||
}, | ||
{ | ||
"type": "text", | ||
"value": ",\n", | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 16, | ||
"offset": 15 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 1, | ||
"offset": 17 | ||
}, | ||
"indent": [ | ||
1 | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "strong", | ||
"children": [ | ||
{ | ||
"type": "text", | ||
"value": "strongness", | ||
"position": { | ||
"start": { | ||
"line": 2, | ||
"column": 3, | ||
"offset": 19 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 13, | ||
"offset": 29 | ||
}, | ||
"indent": [] | ||
} | ||
} | ||
], | ||
"position": { | ||
"start": { | ||
"line": 2, | ||
"column": 1, | ||
"offset": 17 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 15, | ||
"offset": 31 | ||
}, | ||
"indent": [] | ||
} | ||
}, | ||
{ | ||
"type": "text", | ||
"value": ",\nand ", | ||
"position": { | ||
"start": { | ||
"line": 2, | ||
"column": 15, | ||
"offset": 31 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 5, | ||
"offset": 37 | ||
}, | ||
"indent": [ | ||
1 | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "inlineCode", | ||
"value": "code", | ||
"position": { | ||
"start": { | ||
"line": 3, | ||
"column": 5, | ||
"offset": 37 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 11, | ||
"offset": 43 | ||
}, | ||
"indent": [] | ||
} | ||
}, | ||
{ | ||
"type": "text", | ||
"value": ".", | ||
"position": { | ||
"start": { | ||
"line": 3, | ||
"column": 11, | ||
"offset": 43 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 12, | ||
"offset": 44 | ||
}, | ||
"indent": [] | ||
} | ||
} | ||
], | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 1, | ||
"offset": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 12, | ||
"offset": 44 | ||
}, | ||
"indent": [ | ||
1, | ||
1 | ||
] | ||
} | ||
} | ||
], | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 1, | ||
"offset": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 12, | ||
"offset": 44 | ||
} | ||
} | ||
} | ||
``` | ||
## API | ||
### [mdast](https://github.com/wooorm/mdast#api).[use](https://github.com/wooorm/mdast#mdastuseplugin-options)(range) | ||
Adds `offset` to each node’s [**Position**](https://github.com/wooorm/mdast/blob/master/doc/Nodes.md#location). | ||
Where normally nodes have a line based positional information, such as: | ||
```json | ||
{ | ||
"type": "break", | ||
"position": { | ||
"start": { | ||
"line": 2, | ||
"column": 5 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 1 | ||
} | ||
} | ||
} | ||
``` | ||
...this plugin adds absolute positional information: | ||
```json | ||
{ | ||
"type": "break", | ||
"position": { | ||
"start": { | ||
"line": 2, | ||
"column": 5, | ||
"offset": 25 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 1, | ||
"offset": 26 | ||
} | ||
} | ||
} | ||
``` | ||
...so you can slice (or syntax highlight) the source: | ||
```javascript | ||
var line = doc.slice(node.position.start.offset, node.position.end.offset); | ||
// Yields: `"\n"` | ||
``` | ||
To reverse an `offset` into a position, pass it into `file.offsetToPosition()`: | ||
```javascript | ||
mdast.use(range).process('foo', function (err, doc, file) { | ||
file.offsetToPosition(0); | ||
// Yields: `{line: 1, column: 1}` | ||
}); | ||
``` | ||
To turn any position object, use `file.positionToOffset()`: | ||
```javascript | ||
mdast.use(range).process('foo', function (err, doc, file) { | ||
var pos = file.offsetToPosition(0); | ||
file.positionToOffset(pos); | ||
// Yields: `0`. | ||
}); | ||
``` | ||
## License | ||
[MIT](LICENSE) © [Titus Wormer](http://wooorm.com) | ||
Renamed to [remark-range](http://npmjs.com/remark-range). |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
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
0
0
166
2
1
0
3
1
4
1
1
- Removedunist-util-visit@^1.0.0
- Removedunist-util-is@3.0.0(transitive)
- Removedunist-util-visit@1.4.1(transitive)
- Removedunist-util-visit-parents@2.1.2(transitive)