Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mdast-util-to-nlcst

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-to-nlcst - npm Package Compare versions

Comparing version 3.0.1 to 3.1.0

87

index.js

@@ -1,9 +0,1 @@

/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module mdast:to-nlcst
* @fileoverview Transform MDAST to NLCST.
*/
'use strict';

@@ -14,2 +6,3 @@

var vfileLocation = require('vfile-location');
var position = require('unist-util-position');
var toString = require('nlcst-to-string');

@@ -32,11 +25,3 @@

/**
* Transform `ast` into `nlcst`.
*
* @param {Node} tree - MDAST node.
* @param {File} file - Virtual file.
* @param {Parser|Function} Parser - (Instance of) NLCST
* parser.
* @return {NLCSTNode} - NLCST.
*/
/* Transform `tree` into `nlcst`. */
function toNLCST(tree, file, Parser) {

@@ -79,19 +64,8 @@ var parser;

/**
* Convert `node` into NLCST.
*
* @param {MDASTNode} node - Node.
* @param {number?} index - Position of `node` in `parent`.
* @param {MDASTNode?} parent - Parent node of `node`.
* @param {File} file - Virtual file.
* @param {Object} location - Bound location info.
* @param {Parser} parser - NLCST parser.
* @return {Array.<NLCSTNode>?} - A list of NLCST nodes, if
* `node` could be converted.
*/
/* Convert `node` into NLCST. */
function one(node, index, parent, file, location, parser) {
var type = node.type;
var pos = node.position;
var start = location.toOffset(pos.start);
var end = location.toOffset(pos.end);
var doc = String(file);
var start = location.toOffset(position.start(node));
var end = location.toOffset(position.end(node));
var replacement;

@@ -109,5 +83,3 @@

) {
replacement = patch(
parser.tokenize(node.alt), location, start + 2
);
replacement = patch(parser.tokenize(node.alt), location, start + 2);
} else if (

@@ -117,13 +89,7 @@ type === 'text' ||

) {
replacement = patch(
parser.tokenize(node.value), location, start
);
replacement = patch(parser.tokenize(node.value), location, start);
} else if (node.type === 'break') {
replacement = patch([
parser.tokenizeWhiteSpace('\n')
], location, start);
replacement = patch([parser.tokenizeWhiteSpace('\n')], location, start);
} else if (node.type === 'inlineCode') {
replacement = patch([parser.tokenizeSource(
file.toString().slice(start, end)
)], location, start);
replacement = patch([parser.tokenizeSource(doc.slice(start, end))], location, start);
}

@@ -134,12 +100,3 @@

/**
* Convert all nodes in `parent` (mdast) into NLCST.
*
* @param {MDASTNode} parent - Parent node.
* @param {File} file - Virtual file.
* @param {Object} location - Bound location info.
* @param {Parser} parser - NLCST parser.
* @return {Array.<NLCSTNode>} - Concatenation of calling
* `one` on each MDASTNode in `parent`.
*/
/* Convert all nodes in `parent` (mdast) into NLCST. */
function all(parent, file, location, parser) {

@@ -160,3 +117,3 @@ var children = parent.children;

pos = node.position;
endLine = pos.start.line;
endLine = position.start(node).line;

@@ -183,4 +140,5 @@ if (prevEndLine && endLine !== prevEndLine) {

prevEndLine = pos.end.line;
prevOffset = pos.end.offset;
pos = position.end(node);
prevEndLine = pos.line;
prevOffset = pos.offset;
}

@@ -191,16 +149,5 @@

/**
* Patch a position on each node in `nodes`.
/* Patch a position on each node in `nodes`.
* `offset` is the offset in `file` this run of content
* starts at.
*
* Note that NLCST nodes are concrete, meaning that their
* starting and ending positions can be inferred from their
* content.
*
* @param {Array.<NLCSTNode>} nodes - NLCST nodes.
* @param {Object} location - Bound location info.
* @param {number} offset - Starting offset for `nodes`.
* @return {Array.<NLCSTNode>} - `nodes`.
*/
* starts at. */
function patch(nodes, location, offset) {

@@ -207,0 +154,0 @@ var length = nodes.length;

30

package.json
{
"name": "mdast-util-to-nlcst",
"version": "3.0.1",
"version": "3.1.0",
"description": "Transform MDAST to NLCST",

@@ -15,4 +15,4 @@ "license": "MIT",

],
"repository": "https://github.com/wooorm/mdast-util-to-nlcst",
"bugs": "https://github.com/wooorm/mdast-util-to-nlcst/issues",
"repository": "https://github.com/syntax-tree/mdast-util-to-nlcst",
"bugs": "https://github.com/syntax-tree/mdast-util-to-nlcst/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",

@@ -28,22 +28,23 @@ "contributors": [

"repeat-string": "^1.5.2",
"unist-util-position": "^3.0.0",
"vfile-location": "^2.0.0"
},
"devDependencies": {
"browserify": "^13.0.1",
"browserify": "^14.0.0",
"esmangle": "^1.0.1",
"is-hidden": "^1.0.1",
"negate": "^1.0.0",
"nyc": "^8.3.0",
"parse-dutch": "^3.0.0",
"parse-english": "^3.0.0",
"parse-latin": "^3.1.1",
"remark": "^6.0.0",
"remark-cli": "^2.0.0",
"remark-preset-wooorm": "^1.0.0",
"nyc": "^10.0.0",
"parse-dutch": "^4.0.0",
"parse-english": "^4.0.0",
"parse-latin": "^4.0.0",
"remark": "^7.0.0",
"remark-cli": "^3.0.0",
"remark-preset-wooorm": "^2.0.0",
"tape": "^4.0.0",
"vfile": "^2.0.0",
"xo": "^0.16.0"
"xo": "^0.17.0"
},
"scripts": {
"build-md": "remark *.md --quiet --frail",
"build-md": "remark *.md -qfo",
"build-bundle": "browserify index.js --bare -s mdastUtilToNLCST > mdast-util-to-nlcst.js",

@@ -73,5 +74,4 @@ "build-mangle": "esmangle mdast-util-to-nlcst.js > mdast-util-to-nlcst.min.js",

"remarkConfig": {
"output": true,
"presets": "wooorm"
"plugins": ["preset-wooorm"]
}
}
# mdast-util-to-nlcst [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]
<!--lint disable heading-increment list-item-spacing-->
Transform [MDAST][] to [NLCST][].

@@ -11,3 +9,3 @@

[npm][npm-install]:
[npm][]:

@@ -28,18 +26,12 @@ ```bash

var vfile = require('vfile');
```
Process:
```javascript
var file = vfile('Some *foo*sball.');
var tree = remark().parse(file);
```
Stringify:
var nlcst = toNLCST(tree, file, English);
```javascript
var nlcst = toNLCST(tree, file, English);
console.log(inspect(nlcst));
```
Which, when inspecting, yields:
Yields:

@@ -86,11 +78,11 @@ ```txt

[travis-badge]: https://img.shields.io/travis/wooorm/mdast-util-to-nlcst.svg
[travis-badge]: https://img.shields.io/travis/syntax-tree/mdast-util-to-nlcst.svg
[travis]: https://travis-ci.org/wooorm/mdast-util-to-nlcst
[travis]: https://travis-ci.org/syntax-tree/mdast-util-to-nlcst
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/mdast-util-to-nlcst.svg
[codecov-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-to-nlcst.svg
[codecov]: https://codecov.io/github/wooorm/mdast-util-to-nlcst
[codecov]: https://codecov.io/github/syntax-tree/mdast-util-to-nlcst
[npm-install]: https://docs.npmjs.com/cli/install
[npm]: https://docs.npmjs.com/cli/install

@@ -101,9 +93,9 @@ [license]: LICENSE

[mdast]: https://github.com/wooorm/mdast
[mdast]: https://github.com/syntax-tree/mdast
[nlcst]: https://github.com/wooorm/nlcst
[nlcst]: https://github.com/syntax-tree/nlcst
[remark-retext]: https://github.com/wooorm/remark-retext
[vfile]: https://github.com/wooorm/vfile
[vfile]: https://github.com/vfile/vfile

@@ -110,0 +102,0 @@ [english]: https://github.com/wooorm/parse-english

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc