Comparing version 1.2.0 to 2.0.0
@@ -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", |
105
readme.md
@@ -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
337633
45
6723
27
225
11
+ Addedcharm@^1.0.0
+ Addedchokidar@^1.0.5
+ Addedelegant-spinner@^1.0.0
+ Addedlog-update@^1.0.1
+ Addedansi-escapes@1.4.0(transitive)
+ Addedanymatch@1.3.2(transitive)
+ Addedarr-diff@2.0.04.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedarray-unique@0.2.10.3.2(transitive)
+ Addedassign-symbols@1.0.0(transitive)
+ Addedasync-each@1.0.6(transitive)
+ Addedatob@2.1.2(transitive)
+ Addedbase@0.11.2(transitive)
+ Addedbinary-extensions@1.13.1(transitive)
+ Addedbindings@1.5.0(transitive)
+ Addedbraces@1.8.52.3.2(transitive)
+ Addedcache-base@1.0.1(transitive)
+ Addedcharm@1.0.2(transitive)
+ Addedchokidar@1.7.0(transitive)
+ Addedclass-utils@0.3.6(transitive)
+ Addedcli-cursor@1.0.2(transitive)
+ Addedcollection-visit@1.0.0(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedcopy-descriptor@0.1.1(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddefine-property@0.2.51.0.02.0.2(transitive)
+ Addedelegant-spinner@1.0.1(transitive)
+ Addedexit-hook@1.1.1(transitive)
+ Addedexpand-brackets@0.1.52.1.4(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextend-shallow@2.0.13.0.2(transitive)
+ Addedextglob@0.3.22.0.4(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedfilename-regex@2.0.1(transitive)
+ Addedfill-range@2.2.44.0.0(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedfragment-cache@0.2.1(transitive)
+ Addedfsevents@1.2.13(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-value@2.0.6(transitive)
+ Addedglob-base@0.3.0(transitive)
+ Addedglob-parent@2.0.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-value@0.3.11.0.0(transitive)
+ Addedhas-values@0.1.41.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-accessor-descriptor@1.0.1(transitive)
+ Addedis-binary-path@1.0.1(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-data-descriptor@1.0.1(transitive)
+ Addedis-descriptor@0.1.71.0.3(transitive)
+ Addedis-dotfile@1.0.3(transitive)
+ Addedis-equal-shallow@0.1.3(transitive)
+ Addedis-extendable@0.1.11.0.1(transitive)
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-glob@2.0.1(transitive)
+ Addedis-number@2.1.03.0.04.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedis-posix-bracket@0.1.1(transitive)
+ Addedis-primitive@2.0.0(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisobject@2.1.03.0.1(transitive)
+ Addedkind-of@3.2.24.0.06.0.3(transitive)
+ Addedlog-update@1.0.2(transitive)
+ Addedmap-cache@0.2.2(transitive)
+ Addedmap-visit@1.0.0(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmicromatch@2.3.113.1.10(transitive)
+ Addedmixin-deep@1.3.2(transitive)
+ Addednan@2.22.0(transitive)
+ Addednanomatch@1.2.13(transitive)
+ Addednormalize-path@2.1.1(transitive)
+ Addedobject-copy@0.1.0(transitive)
+ Addedobject-visit@1.0.1(transitive)
+ Addedobject.omit@2.0.1(transitive)
+ Addedobject.pick@1.3.0(transitive)
+ Addedonetime@1.1.0(transitive)
+ Addedparse-glob@3.0.4(transitive)
+ Addedpascalcase@0.1.1(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedposix-character-classes@0.1.1(transitive)
+ Addedpreserve@0.2.0(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedreaddirp@2.2.1(transitive)
+ Addedregex-cache@0.4.4(transitive)
+ Addedregex-not@1.0.2(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedresolve-url@0.2.1(transitive)
+ Addedrestore-cursor@1.0.1(transitive)
+ Addedret@0.1.15(transitive)
+ Addedsafe-regex@1.1.0(transitive)
+ Addedset-value@2.0.1(transitive)
+ Addedsnapdragon@0.8.2(transitive)
+ Addedsnapdragon-node@2.1.1(transitive)
+ Addedsnapdragon-util@3.0.1(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedsource-map-resolve@0.5.3(transitive)
+ Addedsource-map-url@0.4.1(transitive)
+ Addedsplit-string@3.1.0(transitive)
+ Addedstatic-extend@0.1.2(transitive)
+ Addedto-object-path@0.3.0(transitive)
+ Addedto-regex@3.0.2(transitive)
+ Addedto-regex-range@2.1.1(transitive)
+ Addedunified@2.1.4(transitive)
+ Addedunion-value@1.0.1(transitive)
+ Addedunset-value@1.0.0(transitive)
+ Addedurix@0.1.0(transitive)
+ Addeduse@3.1.1(transitive)
- Removedunified@1.0.0(transitive)
Updatedunified@^2.0.0