You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

mdast

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast - npm Package Compare versions

Comparing version

to
2.0.0

lib/cli/spinner.js

1

index.js

@@ -25,5 +25,4 @@ /**

'name': 'mdast',
'type': 'ast',
'Parser': Parser,
'Compiler': Compiler
});

@@ -22,2 +22,4 @@ /**

var pack = require('../../package.json');
var Cache = require('./watch-output-cache');
var Spinner = require('./spinner');

@@ -201,4 +203,4 @@ /*

console.log(' # Pass stdin through mdast, with settings, to stdout');
console.log(' $ cat readme.md | ' + COMMAND + ' -s "setext: true, ' +
'bullet: \"*\"" > readme-new.md');
console.log(' $ ' + COMMAND + ' -s "setext: true, ' +
'bullet: \\\"*\\\"" < readme.md > readme-new.md');
console.log();

@@ -233,2 +235,3 @@ console.log(' # Use a plugin (with options)');

.option('-e, --ext <extensions>', 'specify extensions', extensions, [])
.option('-w, --watch', 'watch for changes and reprocess', false)
.option('-a, --ast', 'output AST information', false)

@@ -264,2 +267,5 @@ .option('-q, --quiet', 'output only warnings and errors', false)

self.cache = new Cache();
self.spinner = new Spinner();
if ('length' in config) {

@@ -284,2 +290,3 @@ program.parse(argv);

self.ignorePath = program.ignorePath;
self.watch = program.watch;
} else {

@@ -302,2 +309,3 @@ self.globs = [].concat(config.files || []);

self.ignorePath = config.ignorePath;
self.watch = config.watch;
}

@@ -304,0 +312,0 @@

@@ -48,2 +48,5 @@ /**

var file = context.file;
var fileSet = context.fileSet;
var cli = fileSet.cli;
var sourcePaths = fileSet.sourcePaths;
var destinationPath;

@@ -77,7 +80,21 @@

debug('Writing document to `%s`', destinationPath);
/*
* When watching, `sourcePath`s are watched. Thus, we
* check if we are planning on writing to a watched
* file-path. In which case we exit.
*/
file.stored = true;
if (cli.watch && (sourcePaths.indexOf(destinationPath) !== -1)) {
debug('Caching document as `%s` is watched', destinationPath);
writeFile(destinationPath, file.toString(), done);
cli.cache.add(file);
done();
} else {
debug('Writing document to `%s`', destinationPath);
file.stored = true;
writeFile(destinationPath, file.toString(), done);
}
}

@@ -84,0 +101,0 @@

@@ -29,3 +29,3 @@ /**

*
* file.namespace('mdast').ast.type; // 'root'
* file.namespace('mdast').tree.type; // 'root'
*

@@ -32,0 +32,0 @@ * @param {Object} context

@@ -51,3 +51,3 @@ /**

value = JSON.stringify(file.namespace('mdast').ast, null, 2);
value = JSON.stringify(file.namespace('mdast').tree, null, 2);
} else {

@@ -54,0 +54,0 @@ value = context.processor.stringify(file, context.settings);

@@ -24,3 +24,3 @@ /**

*
* file.namespace('mdast').ast = {
* file.namespace('mdast').tree = {
* 'type': 'paragraph',

@@ -48,3 +48,3 @@ * 'children': [{

context.processor.run(file.namespace('mdast').ast, file, function (err) {
context.processor.run(file.namespace('mdast').tree, file, function (err) {
debug('Transformed document (error: %s)', err);

@@ -51,0 +51,0 @@

@@ -16,2 +16,3 @@ /**

var debug = require('debug')('mdast:cli:file-set-pipeline:stdin');
var fs = require('fs');
var toVFile = require('to-vfile');

@@ -24,4 +25,8 @@ var concat = require('concat-stream');

var expextPipeIn = !process.stdin.isTTY;
var isTTY = process.stdin.isTTY;
var isFIFO = fs.fstatSync(0).isFIFO();
var definitelyTTY = isTTY === true || isFIFO === true;
var expextPipeIn = !isTTY;
/**

@@ -41,3 +46,3 @@ * Read from standard in.

if (expextPipeIn) {
if (definitelyTTY && expextPipeIn) {
err = new Error('mdast does not accept both files and stdin');

@@ -56,3 +61,3 @@ } else if (program.filePath) {

if (!expextPipeIn) {
if (definitelyTTY && !expextPipeIn) {
callback(new Error('No input'));

@@ -59,0 +64,0 @@

@@ -71,7 +71,44 @@ /**

/**
* Files in the set.
*
* @member {Array.<VFile>} contents
*/
self.contents = [];
/**
* Number of files in the set.
*
* @member {number} length
*/
self.length = 0;
/**
* Number of processed files.
*
* @member {number} count
*/
self.count = 0;
/**
* File-paths to the original location of files in
* the set.
*
* @member {Array.<string>} soucePaths
*/
self.sourcePaths = [];
/**
* CLI executing the set.
*
* @member {CLI} cli
*/
self.cli = cli;
self.length = 0;
self.count = 0;
/**
* Pipeline to run when all files in the file-set
* are processed.
*
* @member {Ware} pipeline
*/
self.pipeline = ware();

@@ -78,0 +115,0 @@ }

@@ -16,2 +16,3 @@ /**

var chalk = require('chalk');
var chokidar = require('chokidar');
var CLI = require('./cli');

@@ -21,2 +22,32 @@ var fileSetPipeline = require('./file-set-pipeline');

/**
* Run the file set pipeline once.
*
* @param {CLI} cli - A CLI instance.
* @param {function(Error?, boolean)} done - Callback
* invoked when done.
*/
function run(cli, done) {
cli.spinner.stop();
fileSetPipeline.run(cli, function (err) {
/*
* Check if any file has failed.
*/
var hasFailed = (cli.files || []).some(function (file) {
return (file.messages || []).some(function (message) {
return message.fatal === true ||
(message.fatal === false && cli.frail);
});
});
done(err, !hasFailed);
if (!err && cli.watch) {
cli.spinner.start();
}
});
}
/**
* CLI engine. This is used by `bin/mdast`.

@@ -34,20 +65,56 @@ *

var enabled = chalk.enabled;
var watcher;
chalk.enabled = cli.color;
fileSetPipeline.run(cli, function (err) {
if (cli.watch) {
cli.stdout(chalk.bold('Watching...') + ' (press CTRL+C to exit)')
}
run(cli, function (err, success) {
chalk.enabled = enabled;
done(err, success);
/*
* Check if any file has failed.
* Exit when not-watching, or when an error
* has occurred.
*/
var hasFailed = (cli.files || []).some(function (file) {
return (file.messages || []).some(function (message) {
return message.fatal === true ||
(message.fatal === false && cli.frail);
});
});
if (err || !cli.watch) {
return;
}
chalk.enabled = enabled;
/*
* Trigger warning when files need to be cached.
*/
done(err, !hasFailed);
if (cli.cache.length) {
cli.stderr(
chalk.yellow('Warning') + ': mdast does not overwrite ' +
'watched files until exit.\nMessages and other files are ' +
'not affected.'
);
}
/*
* Watch files source-locations of files in
* the file-set.
*/
watcher = chokidar.watch(cli.fileSet.sourcePaths, {
'ignoreInitial': true
}).on('all', function (type) {
if (type === 'add' || type === 'change') {
run(cli, done);
}
}).on('error', done);
process.on('SIGINT', function () {
cli.cache.writeAll();
if (watcher) {
watcher.close();
}
});
});

@@ -54,0 +121,0 @@ }

@@ -1748,3 +1748,3 @@ /**

*
* file.namespace('mdast').ast = {
* file.namespace('mdast').tree = {
* type: 'strong',

@@ -1764,3 +1764,3 @@ * children: [{

compilerPrototype.compile = function () {
return this.visit(this.file.namespace('mdast').ast);
return this.visit(this.file.namespace('mdast').tree);
};

@@ -1767,0 +1767,0 @@

{
"name": "mdast",
"version": "1.2.0",
"version": "2.0.0",
"description": "Markdown processor powered by plugins",

@@ -23,2 +23,4 @@ "license": "MIT",

"chalk": "^1.0.0",
"charm": "^1.0.0",
"chokidar": "^1.0.5",
"collapse-white-space": "^1.0.0",

@@ -28,4 +30,6 @@ "commander": "^2.0.0",

"debug": "^2.0.0",
"elegant-spinner": "^1.0.0",
"extend.js": "0.0.2",
"he": "^0.5.0",
"log-update": "^1.0.1",
"longest-streak": "^1.0.0",

@@ -40,3 +44,3 @@ "markdown-table": "^0.4.0",

"trim-trailing-lines": "^1.0.0",
"unified": "^1.0.0",
"unified": "^2.0.0",
"user-home": "^2.0.0",

@@ -75,9 +79,9 @@ "vfile": "^1.1.0",

"jscs-jsdoc": "^1.0.0",
"matcha": "^0.6.0",
"mdast-comment-config": "^1.0.0",
"mdast-github": "^1.0.0",
"mdast-html": "^1.2.1",
"mdast-lint": "^1.0.0",
"mdast-man": "^1.0.0",
"mdast-toc": "^1.0.0",
"mdast-usage": "^1.0.0",
"mdast-usage": "^1.0.1",
"mdast-validate-links": "^1.0.0",

@@ -98,3 +102,2 @@ "mdast-yaml-config": "^1.0.0",

"make": "npm run lint && npm run test-coverage",
"benchmark": "matcha benchmark.js",
"regenerate": "node script/regenerate-fixtures.js",

@@ -101,0 +104,0 @@ "build-man": "bin/mdast doc/*.?.md -c .mdastrc-man -q",

@@ -32,4 +32,2 @@ # ![mdast](https://cdn.rawgit.com/wooorm/mdast/master/logo.svg)

* [Benchmark](#benchmark)
* [License](#license)

@@ -45,54 +43,31 @@

[Component.js](https://github.com/componentjs/component):
[Read more about alternatives ways to install and use »](doc/getting-started.md).
```bash
component install wooorm/mdast
```
## Usage
[Bower](http://bower.io/#install-packages):
Load dependencies:
```bash
bower install mdast
```
[Duo](http://duojs.org/#getting-started):
```javascript
var mdast = require('wooorm/mdast');
```
UMD (globals/AMD/CommonJS) ([uncompressed](mdast.js) and
[compressed](mdast.min.js)):
```html
<script src="path/to/mdast.js" charset="utf-8"></script>
<script>
mdast.process('*hello* __world__'); // _hello_ **world**
</script>
```
## Usage
```javascript
var mdast = require('mdast');
var html = require('mdast-html');
var yamlConfig = require('mdast-yaml-config');
```
Use a plugin. mdast-yaml-config allows settings in YAML frontmatter.
Use plugins:
```javascript
var processor = mdast().use(yamlConfig);
var processor = mdast().use(yamlConfig).use(html);
```
Parse, modify, and stringify the document:
Process the document:
```javascript
var doc = processor.process(
'---\n' +
'mdast:\n' +
' commonmark: true\n' +
'---\n' +
'\n' +
'2) Some *emphasis*, **strongness**, and `code`.\n'
);
var doc = processor.process([
'---',
'mdast:',
' commonmark: true',
'---',
'',
'2) Some *emphasis*, **strongness**, and `code`.'
].join('\n'));
```

@@ -102,9 +77,6 @@

```markdown
---
mdast:
commonmark: true
---
2. Some _emphasis_, **strongness**, and `code`.
```html
<ol start="2">
<li>Some <em>emphasis</em>, <strong>strongness</strong>, and <code>code</code>.</li>
</ol>
```

@@ -115,22 +87,4 @@

This section only covers the interface you’ll use most often. See
[mdast(3) documentation](doc/mdast.3.md) for a more complete description:
[**mdast**(3) documentation](doc/mdast.3.md) for a more complete description.
* [mdast.parse(file, options?)](doc/mdast.3.md#mdastparsefile-options)
— Parses markdown into an abstract syntax tree;
* [mdast.run(ast, file, done?)](doc/mdast.3.md#mdastrunnode-file-done)
— Applies plugins to the syntax tree;
* [mdast.stringify(ast, options?)](doc/mdast.3.md#mdaststringifynode-file-options)
— Compiles the syntax tree into a string;
* [mdast.process(file, options?, done?)](doc/mdast.3.md#mdastprocessfile-options-done)
— More detailed than [below](#mdastprocessvalue-options-done);
* [mdast.use(plugin, options?)](doc/mdast.3.md#mdastuseplugin-options)
— More detailed than [below](#mdastuseplugin-options);
* [function done(err?, doc?, file?)](doc/mdast.3.md#function-doneerr-doc-file)
— Callback passed to `run()` and `process()`.
### [mdast](#api).process(value, [options](doc/mdastsetting.7.md)?, done?)

@@ -187,3 +141,3 @@

`done` should’ve been passed (don’t worry: plugin creators make sure you know
its async).
its async).

@@ -238,2 +192,3 @@ ### [mdast](#api).use([plugin](doc/plugins.md#plugins), options?)

-e, --ext <extensions> specify extensions
-w, --watch watch for changes and reprocess
-a, --ast output AST information

@@ -255,3 +210,3 @@ -q, --quiet output only warnings and errors

# Pass stdin through mdast, with settings, to stdout
$ cat readme.md | mdast -s "setext: true, bullet: "*"" > readme-new.md
$ mdast -s "setext: true, bullet: \"*\"" < readme.md > readme-new.md

@@ -270,16 +225,2 @@ # Use a plugin (with options)

## Benchmark
On a MacBook Air, it parses ± 322Kb of markdown (in 214 documents) per second.
```text
214 fixtures (total: 80.62Kb)
4 op/s » mdast.parse w/ `gfm: true`, and `yaml: true`
69 op/s » mdast.stringify w/ `gfm: true`, and `yaml: true`
4 op/s » mdast.parse w/ `gfm: false`, and `yaml: false`
70 op/s » mdast.stringify w/ `gfm: false`, and `yaml: false`
4 op/s » mdast.parse w/ `gfm: true`, `yaml: true`, and `commonmark: true`
72 op/s » mdast.stringify w/ `gfm: true`, `yaml: true`, and `commonmark: true`
```
## License

@@ -286,0 +227,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet