Comparing version 0.13.0 to 0.14.0-rc.1
@@ -0,1 +1,9 @@ | ||
0.14.0-rc.1 / 2015-03-24 | ||
======================== | ||
* Refactor plugin mechanism ([7dc23a6](https://github.com/wooorm/mdast/commit/7dc23a6)) | ||
* Remove plugins from `.mdastrc` for the time being ([204e32a](https://github.com/wooorm/mdast/commit/204e32a)) | ||
* Add support for `--quiet` flag in CLI ([64f9ed1](https://github.com/wooorm/mdast/commit/64f9ed1)) | ||
* Add support for `--ext` flag in CLI ([fa0c1d7](https://github.com/wooorm/mdast/commit/fa0c1d7)) | ||
0.13.0 / 2015-03-22 | ||
@@ -2,0 +10,0 @@ =================== |
67
index.js
'use strict'; | ||
/* | ||
* Dependencies.. | ||
* Dependencies. | ||
*/ | ||
var Ware = require('ware'); | ||
var parse = require('./lib/parse.js'); | ||
var stringify = require('./lib/stringify.js'); | ||
var utilities = require('./lib/utilities.js'); | ||
/* | ||
* Components. | ||
* Methods. | ||
*/ | ||
var parse = require('./lib/parse.js'); | ||
var stringify = require('./lib/stringify.js'); | ||
var clone = require('./lib/utilities.js').clone; | ||
var clone = utilities.clone; | ||
var Parser = parse.Parser; | ||
@@ -124,2 +124,3 @@ var parseProto = Parser.prototype; | ||
this.ware = new Ware(); | ||
this.attachers = []; | ||
@@ -131,11 +132,15 @@ this.Parser = constructParser(); | ||
/** | ||
* Apply plugins to `node`. | ||
* Apply transformers to `node`. | ||
* | ||
* @param {Node} node | ||
* @param {Node} ast | ||
* @param {Object?} options | ||
* @return {Node} - `node`. | ||
* @return {Node} - `ast`. | ||
*/ | ||
function run(node, options) { | ||
function run(ast, options) { | ||
var self = this; | ||
if (typeof ast !== 'object' && typeof ast.type !== 'string') { | ||
utilities.raise(ast, 'ast'); | ||
} | ||
/* | ||
@@ -146,16 +151,18 @@ * Only run when this is an instance of MDAST. | ||
if (self.ware) { | ||
self.ware.run(node, options || {}, self, fail); | ||
self.ware.run(ast, options || {}, self, fail); | ||
} | ||
return node; | ||
return ast; | ||
} | ||
/** | ||
* Construct an MDAST instance and use a plugin. | ||
* Attach a plugin. | ||
* | ||
* @param {Function} plugin | ||
* @param {Function|Array.<Function>} attach | ||
* @return {MDAST} | ||
*/ | ||
function use(plugin) { | ||
function use(attach, options) { | ||
var self = this; | ||
var index; | ||
var transformer; | ||
@@ -166,8 +173,30 @@ if (!(self instanceof MDAST)) { | ||
self.ware.use(plugin); | ||
/* | ||
* Multiple attachers. | ||
*/ | ||
if (plugin && 'attach' in plugin) { | ||
plugin.attach(self); | ||
if ('length' in attach && typeof attach !== 'function') { | ||
index = attach.length; | ||
while (attach[--index]) { | ||
self.use(attach[index]); | ||
} | ||
return self; | ||
} | ||
/* | ||
* Single plugin. | ||
*/ | ||
if (self.attachers.indexOf(attach) === -1) { | ||
transformer = attach(self, options); | ||
self.attachers.push(attach); | ||
if (transformer) { | ||
self.ware.use(transformer); | ||
} | ||
} | ||
return self; | ||
@@ -177,3 +206,3 @@ } | ||
/** | ||
* Parse a value and apply plugins. | ||
* Parse a value and apply transformers. | ||
* | ||
@@ -180,0 +209,0 @@ * @return {Root} |
@@ -130,2 +130,14 @@ 'use strict'; | ||
/** | ||
* Bound `console.log`. | ||
*/ | ||
function consoleLog() { | ||
console.log.apply(console, arguments); | ||
} | ||
/** | ||
* Noop | ||
*/ | ||
function noop() {} | ||
/** | ||
* CLI engine. | ||
@@ -138,2 +150,4 @@ * | ||
var cli = program.parse(argv); | ||
var extensions = [].concat(cli.ext, EXTENSIONS); | ||
var log = cli.quiet ? noop : consoleLog; | ||
var files = cli.args; | ||
@@ -184,3 +198,3 @@ var multiFileMode; | ||
traverser = new Traverser(EXTENSIONS, ignore.getPatterns()); | ||
traverser = new Traverser(extensions, ignore.getPatterns()); | ||
@@ -259,3 +273,3 @@ files = traverser.traverse(files); | ||
if (multiFileMode) { | ||
console.log(chalk.yellow(' Rewrote `' + filepath + '`')); | ||
log(chalk.yellow(' Rewrote `' + filepath + '`')); | ||
} | ||
@@ -308,5 +322,4 @@ }); | ||
if (multiFileMode) { | ||
console.log(); | ||
console.log(chalk.bold('Processing...')); | ||
console.log(); | ||
log(chalk.bold('Processing...')); | ||
log(); | ||
} | ||
@@ -313,0 +326,0 @@ |
@@ -71,2 +71,13 @@ 'use strict'; | ||
/** | ||
* Parse extensions into a list. | ||
* | ||
* @param {string} extension | ||
* @param {Array.<string>} cache | ||
* @return {Array.<string>} | ||
*/ | ||
function extensions(extension, cache) { | ||
return cache.concat(extension.split(SPLITTER)); | ||
} | ||
/** | ||
* Help. | ||
@@ -154,5 +165,7 @@ */ | ||
.option('-u, --use <plugins>', 'use transform plugin(s)', plugins, []) | ||
.option('-e, --ext <extensions>', 'specify extensions', extensions, []) | ||
.option('-a, --ast', 'output AST information', false) | ||
.option('--no-rc', 'Disable configuration from .mdastrc', false) | ||
.option('--no-ignore', 'Disable ignore from .mdastignore', false) | ||
.option('-q, --quiet', 'output less messages', false) | ||
.option('--no-rc', 'disable configuration from .mdastrc', false) | ||
.option('--no-ignore', 'disable ignore from .mdastignore', false) | ||
.option('--settings', 'output available settings', false); | ||
@@ -159,0 +172,0 @@ |
{ | ||
"name": "mdast", | ||
"version": "0.13.0", | ||
"version": "0.14.0-rc.1", | ||
"description": "Speedy Markdown parser/stringifier for multipurpose analysis", | ||
@@ -81,4 +81,4 @@ "license": "MIT", | ||
"build-expressions": "node script/build-expressions.js", | ||
"build-md": "bin/mdast . -o", | ||
"build-history": "bin/mdast History.md --no-ignore --setting setext -o", | ||
"build-md": "bin/mdast . --output --quiet", | ||
"build-history": "bin/mdast History.md --no-ignore --setting setext --output", | ||
"build-options": "node script/build-options.js", | ||
@@ -85,0 +85,0 @@ "build-bundle": "browserify index.js -s mdast > mdast.js", |
@@ -404,3 +404,5 @@ # ![mdast](https://cdn.rawgit.com/wooorm/mdast/master/logo.svg) | ||
-u, --use <plugins> use transform plugin(s) | ||
-e, --ext <extensions> specify extensions | ||
-a, --ast output AST information | ||
-q, --quiet output less messages | ||
--no-rc Disable configuration from .mdastrc | ||
@@ -407,0 +409,0 @@ --no-ignore Disable ignore from .mdastignore |
Sorry, the diff of this file is not supported yet
187921
4135
451