mdast-util-to-nlcst
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -1,5 +0,16 @@ | ||
<!--mdast setext--> | ||
<!--remark setext--> | ||
<!--lint disable no-multiple-toplevel-headings--> | ||
2.0.0 / 2016-01-12 | ||
================== | ||
* Fix implicit sentence detection ([1756f46](https://github.com/wooorm/mdast-util-to-nlcst/commit/1756f46)) | ||
* Remove support for component ([08e7b38](https://github.com/wooorm/mdast-util-to-nlcst/commit/08e7b38)) | ||
* Remove support for bower ([e8a41f6](https://github.com/wooorm/mdast-util-to-nlcst/commit/e8a41f6)) | ||
* Refactor npm test target ([379ee93](https://github.com/wooorm/mdast-util-to-nlcst/commit/379ee93)) | ||
* Refactor to replace mocha with tape ([1efd2ca](https://github.com/wooorm/mdast-util-to-nlcst/commit/1efd2ca)) | ||
* Update dependencies, dev-dependencies ([60235cd](https://github.com/wooorm/mdast-util-to-nlcst/commit/60235cd)) | ||
* Update `mdast` to `remark` ([ed96d00](https://github.com/wooorm/mdast-util-to-nlcst/commit/ed96d00)) | ||
1.0.0 / 2015-09-18 | ||
@@ -6,0 +17,0 @@ ================== |
56
index.js
/** | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer | ||
* @copyright 2015-2016 Titus Wormer | ||
* @license MIT | ||
@@ -18,4 +18,5 @@ * @module mdast:util:to-nlcst | ||
var range = require('mdast-range'); | ||
var range = require('remark-range'); | ||
var toString = require('nlcst-to-string'); | ||
var repeat = require('repeat-string'); | ||
@@ -38,3 +39,3 @@ /* | ||
var NON_NEWLINE = /[^\n]/; | ||
var C_NEWLINE = '\n'; | ||
@@ -134,9 +135,35 @@ /** | ||
var child; | ||
var node; | ||
var pos; | ||
var prevEndLine; | ||
var prevOffset; | ||
var endLine; | ||
while (++index < length) { | ||
child = one(children[index], index, parent, file, parser); | ||
node = children[index]; | ||
pos = node.position; | ||
endLine = pos.start.line; | ||
if (prevEndLine && endLine !== prevEndLine) { | ||
child = parser.tokenizeWhiteSpace( | ||
repeat(C_NEWLINE, endLine - prevEndLine) | ||
); | ||
patch([child], file, prevOffset); | ||
if (child.value.length < 2) { | ||
child.value = repeat(C_NEWLINE, 2); | ||
} | ||
result.push(child); | ||
} | ||
child = one(node, index, parent, file, parser); | ||
if (child) { | ||
result = result.concat(child); | ||
} | ||
prevEndLine = pos.end.line; | ||
prevOffset = pos.end.offset; | ||
} | ||
@@ -160,14 +187,7 @@ | ||
var type = node.type; | ||
var siblings = parent && parent.children; | ||
var prev = siblings && siblings[index - 1]; | ||
var pos = node.position; | ||
var start = pos.start; | ||
var end = pos.end; | ||
var final = prev && prev.position.end.offset; | ||
var replacement; | ||
var result; | ||
var space; | ||
space = final && file.toString().slice(final, start.offset); | ||
if (type in IGNORE) { | ||
@@ -201,16 +221,2 @@ return null; | ||
/** | ||
* There’s a difference between block-nodes with | ||
* lines between them. NLCST parsers need them to | ||
* differentiate between paragraphs. | ||
*/ | ||
if (replacement && space && !NON_NEWLINE.test(space)) { | ||
result = parser.tokenizeWhiteSpace(space); | ||
patch([result], file, final); | ||
replacement.unshift(result); | ||
} | ||
return replacement || null; | ||
@@ -217,0 +223,0 @@ }; |
{ | ||
"name": "mdast-util-to-nlcst", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Markdown to Natural Language", | ||
@@ -8,2 +8,3 @@ "license": "MIT", | ||
"mdast", | ||
"remark", | ||
"nlcst", | ||
@@ -15,4 +16,5 @@ "markdown", | ||
"dependencies": { | ||
"mdast-range": "^1.0.0", | ||
"nlcst-to-string": "^1.0.0" | ||
"nlcst-to-string": "^1.0.0", | ||
"remark-range": "^2.0.0", | ||
"repeat-string": "^1.5.2" | ||
}, | ||
@@ -32,35 +34,33 @@ "repository": { | ||
"devDependencies": { | ||
"browserify": "^11.0.0", | ||
"browserify": "^13.0.0", | ||
"eslint": "^1.1.0", | ||
"esmangle": "^1.0.0", | ||
"istanbul": "^0.3.0", | ||
"istanbul": "^0.4.0", | ||
"jscs": "^2.0.0", | ||
"jscs-jsdoc": "^1.0.0", | ||
"mdast": "^1.0.0", | ||
"mdast-comment-config": "^1.0.0", | ||
"mdast-github": "^1.0.0", | ||
"mdast-lint": "^1.0.0", | ||
"mdast-slug": "^2.0.0", | ||
"mdast-validate-links": "^1.0.0", | ||
"mocha": "^2.0.0", | ||
"parse-dutch": "^2.0.0", | ||
"parse-english": "^2.0.0", | ||
"parse-latin": "^2.0.0", | ||
"remark": "^3.0.0", | ||
"remark-comment-config": "^2.0.0", | ||
"remark-github": "^2.0.0", | ||
"remark-lint": "^2.0.0", | ||
"remark-slug": "^3.0.0", | ||
"remark-validate-links": "^2.0.0", | ||
"retext": "^1.0.0", | ||
"tape": "^4.4.0", | ||
"vfile": "^1.0.0" | ||
}, | ||
"scripts": { | ||
"test-api": "mocha --check-leaks test/index.js", | ||
"test-coveralls": "istanbul cover _mocha --report lcovonly -- --check-leaks test/index.js", | ||
"test-coverage": "istanbul cover _mocha -- test/index.js", | ||
"test-travis": "npm run test-coveralls", | ||
"test": "npm run test-api", | ||
"build-bundle": "browserify index.js --no-builtins -s mdastUtilToNLCST > mdast-util-to-nlcst.js", | ||
"build-mangle": "esmangle mdast-util-to-nlcst.js > mdast-util-to-nlcst.min.js", | ||
"build-md": "remark . --quiet --frail", | ||
"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", | ||
"make": "npm run lint && npm run test-coverage", | ||
"bundle": "browserify index.js --no-builtins -s mdastUtilToNLCST > mdast-util-to-nlcst.js", | ||
"postbundle": "esmangle mdast-util-to-nlcst.js > mdast-util-to-nlcst.min.js", | ||
"build-md": "mdast . --quiet", | ||
"build": "npm run bundle && npm run build-md" | ||
"test-api": "node test/index.js", | ||
"test-coverage": "istanbul cover test/index.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
} | ||
} |
257
readme.md
@@ -1,5 +0,5 @@ | ||
# mdast-util-to-nlcst [![Build Status](https://img.shields.io/travis/wooorm/mdast-util-to-nlcst.svg)](https://travis-ci.org/wooorm/mdast-util-to-nlcst) [![Coverage Status](https://img.shields.io/codecov/c/github/wooorm/mdast-util-to-nlcst.svg)](https://codecov.io/github/wooorm/mdast-util-to-nlcst) | ||
# mdast-util-to-nlcst [![Build Status][travis-badge]][travis] [![Coverage Status][coverage-badge]][coverage] | ||
[**mdast**](https://github.com/wooorm/mdast) utility to transform markdown | ||
into [**nlcst**](https://github.com/wooorm/nlcst), while keeping location | ||
[**mdast**][mdast] utility to transform markdown | ||
into [**nlcst**][nlcst], while keeping location | ||
information intact. | ||
@@ -10,9 +10,8 @@ | ||
> **Note** The interface is pretty rough. But in the future this will be built | ||
> into mdast/retext, something called “bridging”, so you won’t have to | ||
> use this library manually in the future :smile:! | ||
> **Note** You probably want to use | ||
> [remark-retext][]. | ||
## Installation | ||
[npm](https://docs.npmjs.com/cli/install): | ||
[npm][npm-install]: | ||
@@ -23,7 +22,5 @@ ```bash | ||
**mdast-util-to-nlcst** is also available for [bower](http://bower.io/#install-packages), | ||
[component](https://github.com/componentjs/component), and | ||
[duo](http://duojs.org/#getting-started), and as an AMD, CommonJS, and globals | ||
module, [uncompressed](mdast-util-to-nlcst.js) and | ||
[compressed](mdast-util-to-nlcst.min.js). | ||
**mdast-util-to-nlcst** is also available for [duo][], | ||
and as an AMD, CommonJS, and globals module, | ||
[uncompressed and compressed][releases]. | ||
@@ -33,8 +30,6 @@ ## Usage | ||
```js | ||
/* | ||
* Dependencies. | ||
*/ | ||
var mdast = require('mdast'); | ||
var toNLCST = require('mdast-util-to-nlcst'); | ||
var inspect = require('unist-util-inspect'); | ||
var remark = require('remark'); | ||
var retext = require('retext'); | ||
@@ -45,152 +40,21 @@ /* | ||
mdast.process('Some *foo*s-_ball_.', function (err, doc, file) { | ||
toNLCST(file); | ||
console.log(file.namespace('retext').cst); | ||
remark().process('Some *foo*s-_ball_.', function (err, file) { | ||
var tree = toNLCST(file, retext().Parser); | ||
console.log(inspect(tree)); | ||
/* | ||
* Yields: | ||
* | ||
* Object | ||
* ├─ type: "RootNode" | ||
* ├─ position: Object | ||
* | └─ start: Object | ||
* | | ├─ line: 1 | ||
* | | ├─ column: 1 | ||
* | | └─ offset: 0 | ||
* | └─ end: Object | ||
* | ├─ line: 1 | ||
* | ├─ column: 20 | ||
* | └─ offset: 19 | ||
* └─ children: Array[1] | ||
* └─ 0: Object | ||
* ├─ type: "ParagraphNode" | ||
* ├─ position: Object | ||
* | └─ start: Object | ||
* | | ├─ line: 1 | ||
* | | ├─ column: 1 | ||
* | | └─ offset: 0 | ||
* | └─ end: Object | ||
* | ├─ line: 1 | ||
* | ├─ column: 20 | ||
* | └─ offset: 19 | ||
* └─ children: Array[1] | ||
* └─ 0: Object | ||
* ├─ type: "SentenceNode" | ||
* ├─ position: Object | ||
* | └─ start: Object | ||
* | | ├─ line: 1 | ||
* | | ├─ column: 1 | ||
* | | └─ offset: 0 | ||
* | └─ end: Object | ||
* | ├─ line: 1 | ||
* | ├─ column: 20 | ||
* | └─ offset: 19 | ||
* └─ children: Array[4] | ||
* ├─ 0: Object | ||
* | ├─ type: "WordNode" | ||
* | ├─ position: Object | ||
* | | └─ start: Object | ||
* | | | ├─ line: 1 | ||
* | | | ├─ column: 1 | ||
* | | | └─ offset: 0 | ||
* | | └─ end: Object | ||
* | | ├─ line: 1 | ||
* | | ├─ column: 5 | ||
* | | └─ offset: 4 | ||
* | └─ children: Array[1] | ||
* | └─ 0: Object | ||
* | ├─ type: "TextNode" | ||
* | ├─ position: Object | ||
* | | └─ start: Object | ||
* | | | ├─ line: 1 | ||
* | | | ├─ column: 1 | ||
* | | | └─ offset: 0 | ||
* | | └─ end: Object | ||
* | | ├─ line: 1 | ||
* | | ├─ column: 5 | ||
* | | └─ offset: 4 | ||
* | └─ value: "Some" | ||
* ├─ 1: Object | ||
* | ├─ type: "WhiteSpaceNode" | ||
* | ├─ position: Object | ||
* | | └─ start: Object | ||
* | | | ├─ line: 1 | ||
* | | | ├─ column: 5 | ||
* | | | └─ offset: 4 | ||
* | | └─ end: Object | ||
* | | ├─ line: 1 | ||
* | | ├─ column: 6 | ||
* | | └─ offset: 5 | ||
* | └─ value: " " | ||
* ├─ 2: Object | ||
* | ├─ type: "WordNode" | ||
* | ├─ position: Object | ||
* | | └─ start: Object | ||
* | | | ├─ line: 1 | ||
* | | | ├─ column: 7 | ||
* | | | └─ offset: 6 | ||
* | | └─ end: Object | ||
* | | ├─ line: 1 | ||
* | | ├─ column: 18 | ||
* | | └─ offset: 17 | ||
* | └─ children: Array[4] | ||
* | ├─ 0: Object | ||
* | | ├─ type: "TextNode" | ||
* | | ├─ position: Object | ||
* | | | └─ start: Object | ||
* | | | | ├─ line: 1 | ||
* | | | | ├─ column: 7 | ||
* | | | | └─ offset: 6 | ||
* | | | └─ end: Object | ||
* | | | ├─ line: 1 | ||
* | | | ├─ column: 10 | ||
* | | | └─ offset: 9 | ||
* | | └─ value: "foo" | ||
* | ├─ 1: Object | ||
* | | ├─ type: "TextNode" | ||
* | | ├─ position: Object | ||
* | | | └─ start: Object | ||
* | | | | ├─ line: 1 | ||
* | | | | ├─ column: 11 | ||
* | | | | └─ offset: 10 | ||
* | | | └─ end: Object | ||
* | | | ├─ line: 1 | ||
* | | | ├─ column: 12 | ||
* | | | └─ offset: 11 | ||
* | | └─ value: "s" | ||
* | ├─ 2: Object | ||
* | | ├─ type: "PunctuationNode" | ||
* | | ├─ position: Object | ||
* | | | └─ start: Object | ||
* | | | | ├─ line: 1 | ||
* | | | | ├─ column: 12 | ||
* | | | | └─ offset: 11 | ||
* | | | └─ end: Object | ||
* | | | ├─ line: 1 | ||
* | | | ├─ column: 13 | ||
* | | | └─ offset: 12 | ||
* | | └─ value: "-" | ||
* | └─ 3: Object | ||
* | ├─ type: "TextNode" | ||
* | ├─ position: Object | ||
* | | └─ start: Object | ||
* | | | ├─ line: 1 | ||
* | | | ├─ column: 14 | ||
* | | | └─ offset: 13 | ||
* | | └─ end: Object | ||
* | | ├─ line: 1 | ||
* | | ├─ column: 18 | ||
* | | └─ offset: 17 | ||
* | └─ value: "ball" | ||
* └─ 3: Object | ||
* ├─ type: "PunctuationNode" | ||
* ├─ position: Object | ||
* | └─ start: Object | ||
* | | ├─ line: 1 | ||
* | | ├─ column: 19 | ||
* | | └─ offset: 18 | ||
* | └─ end: Object | ||
* | ├─ line: 1 | ||
* | ├─ column: 20 | ||
* | └─ offset: 19 | ||
* └─ value: "." | ||
* RootNode[1] (1:1-1:20, 0-19) | ||
* └─ ParagraphNode[1] (1:1-1:20, 0-19) | ||
* └─ SentenceNode[4] (1:1-1:20, 0-19) | ||
* ├─ WordNode[1] (1:1-1:5, 0-4) | ||
* │ └─ TextNode: "Some" (1:1-1:5, 0-4) | ||
* ├─ WhiteSpaceNode: " " (1:5-1:6, 4-5) | ||
* ├─ WordNode[4] (1:7-1:18, 6-17) | ||
* │ ├─ TextNode: "foo" (1:7-1:10, 6-9) | ||
* │ ├─ TextNode: "s" (1:11-1:12, 10-11) | ||
* │ ├─ PunctuationNode: "-" (1:12-1:13, 11-12) | ||
* │ └─ TextNode: "ball" (1:14-1:18, 13-17) | ||
* └─ PunctuationNode: "." (1:19-1:20, 18-19) | ||
*/ | ||
@@ -202,8 +66,8 @@ }); | ||
### toNLCST(file, Parser | parser) | ||
### `toNLCST(file, Parser | parser)` | ||
Transform a by [**mdast**](https://github.com/wooorm/mdast) processed | ||
[**virtual file**](https://github.com/wooorm/vfile) into a | ||
[NLCST](https://github.com/wooorm/nlcst) tree for | ||
[**retext**](https://github.com/wooorm/retext). | ||
Transform a by [**remark**][remark] processed | ||
[**virtual file**][vfile] into an | ||
[NLCST][nlcst] tree for | ||
[**retext**][retext]. | ||
@@ -213,17 +77,58 @@ Parameters: | ||
* `file` (`File`) | ||
— [Virtual file](https://github.com/wooorm/vfile), must be passed through | ||
[`parse()`](https://github.com/wooorm/mdast/blob/master/doc/mdast.3.md#mdastparsefile-options). | ||
— [Virtual file][vfile], must be passed through | ||
[`parse()`][remark-parse]. | ||
* `parser` (`Function` or `Parser`, optional) | ||
— You can pass the (constructor of) an NLCST parser, such as | ||
[**parse-english**](https://github.com/wooorm/parse-english), | ||
[**parse-dutch**](https://github.com/wooorm/parse-dutch), or | ||
[**parse-latin**](https://github.com/wooorm/parse-latin). | ||
[**parse-english**][parse-english], [**parse-dutch**][parse-dutch], | ||
or [**parse-latin**][parse-latin]. | ||
Returns: | ||
[`NLCSTNode`](https://github.com/wooorm/nlcst). | ||
[`NLCSTNode`][nlcst-node]. | ||
## License | ||
[MIT](LICENSE) © [Titus Wormer](http://wooorm.com) | ||
[MIT][license] © [Titus Wormer][home] | ||
<!-- Definitions --> | ||
[travis-badge]: https://img.shields.io/travis/wooorm/mdast-util-to-nlcst.svg | ||
[travis]: https://travis-ci.org/wooorm/mdast-util-to-nlcst | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/mdast-util-to-nlcst.svg | ||
[coverage]: https://codecov.io/github/wooorm/mdast-util-to-nlcst | ||
[vfile]: https://github.com/wooorm/vfile | ||
[remark]: https://github.com/wooorm/remark | ||
[retext]: https://github.com/wooorm/retext | ||
[mdast]: https://github.com/wooorm/mdast | ||
[nlcst]: https://github.com/wooorm/nlcst | ||
[remark-retext]: https://github.com/wooorm/remark-retext | ||
[npm-install]: https://docs.npmjs.com/cli/install | ||
[duo]: http://duojs.org/#getting-started | ||
[releases]: https://github.com/wooorm/mdast-util-to-nlcst/releases | ||
[remark-parse]: https://github.com/wooorm/remark/blob/master/doc/remark.3.md#remarkparsefile-options | ||
[nlcst-node]: https://github.com/wooorm/nlcst | ||
[parse-english]: https://github.com/wooorm/parse-english | ||
[parse-dutch]: https://github.com/wooorm/parse-dutch | ||
[parse-latin]: https://github.com/wooorm/parse-latin | ||
[license]: LICENSE | ||
[home]: http://wooorm.com |
Sorry, the diff of this file is not supported yet
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
236
14081
3
18
129
+ Addedremark-range@^2.0.0
+ Addedrepeat-string@^1.5.2
+ Addedremark-range@2.0.0(transitive)
+ Addedrepeat-string@1.6.1(transitive)
- Removedmdast-range@^1.0.0
- Removedmdast-range@1.0.1(transitive)