Comparing version 0.26.2 to 0.27.0-rc.1
@@ -10,2 +10,12 @@ --- | ||
0.27.0-rc.1 / 2015-07-17 | ||
======================== | ||
* Add CLI-pipelines ([ee5e603](https://github.com/wooorm/mdast/commit/ee5e603)) | ||
* Fix order of multiple attachers in `mdast#use` ([070d664](https://github.com/wooorm/mdast/commit/070d664)) | ||
* Remove travis deploy ([f693521](https://github.com/wooorm/mdast/commit/f693521)) | ||
* Update `doc/plugins.md` ([be77bef](https://github.com/wooorm/mdast/commit/be77bef)) | ||
* Fix invalid build-script ([a5738a1](https://github.com/wooorm/mdast/commit/a5738a1)) | ||
* Refactor to externalise utilities ([09dfec2](https://github.com/wooorm/mdast/commit/09dfec2)) | ||
0.26.2 / 2015-07-06 | ||
@@ -12,0 +22,0 @@ =================== |
26
index.js
@@ -8,2 +8,3 @@ 'use strict'; | ||
var Ware = require('ware'); | ||
var extend = require('extend.js'); | ||
var parser = require('./lib/parse.js'); | ||
@@ -18,3 +19,2 @@ var stringifier = require('./lib/stringify.js'); | ||
var clone = utilities.clone; | ||
var Parser = parser.Parser; | ||
@@ -74,6 +74,6 @@ var parseProto = Parser.prototype; | ||
customProto.blockTokenizers = clone(parseProto.blockTokenizers); | ||
customProto.blockMethods = clone(parseProto.blockMethods); | ||
customProto.inlineTokenizers = clone(parseProto.inlineTokenizers); | ||
customProto.inlineMethods = clone(parseProto.inlineMethods); | ||
customProto.blockTokenizers = extend({}, parseProto.blockTokenizers); | ||
customProto.blockMethods = extend([], parseProto.blockMethods); | ||
customProto.inlineTokenizers = extend({}, parseProto.inlineTokenizers); | ||
customProto.inlineMethods = extend([], parseProto.inlineMethods); | ||
@@ -84,3 +84,3 @@ expressions = parseProto.expressions; | ||
for (key in expressions) { | ||
customProto.expressions[key] = clone(expressions[key]); | ||
customProto.expressions[key] = extend({}, expressions[key]); | ||
} | ||
@@ -143,6 +143,8 @@ | ||
* @param {Function|Array.<Function>} attach | ||
* @param {Object?} options | ||
* @param {Object?} [options] | ||
* @param {FileSet?} [fileSet] - Optional file-set, | ||
* passed by the CLI. | ||
* @return {MDAST} | ||
*/ | ||
function use(attach, options) { | ||
function use(attach, options, fileSet) { | ||
var self = this; | ||
@@ -161,6 +163,6 @@ var index; | ||
if ('length' in attach && typeof attach !== 'function') { | ||
index = attach.length; | ||
index = -1; | ||
while (attach[--index]) { | ||
self.use(attach[index]); | ||
while (attach[++index]) { | ||
self.use(attach[index], options, fileSet); | ||
} | ||
@@ -176,3 +178,3 @@ | ||
if (self.attachers.indexOf(attach) === -1) { | ||
transformer = attach(self, options); | ||
transformer = attach(self, options, fileSet); | ||
@@ -179,0 +181,0 @@ self.attachers.push(attach); |
/** | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer. All rights reserved. | ||
* @module Configuration | ||
* @module mdast:cli:configuration | ||
* @fileoverview Find mdast rc files. | ||
@@ -16,6 +16,6 @@ */ | ||
var path = require('path'); | ||
var debug = require('debug'); | ||
var debug = require('debug')('mdast:cli:configuration'); | ||
var home = require('user-home'); | ||
var extend = require('extend.js'); | ||
var defaults = require('../defaults'); | ||
var utilities = require('../utilities'); | ||
var Finder = require('./finder'); | ||
@@ -32,3 +32,2 @@ | ||
var PERSONAL_CONFIGURATION = home ? path.join(home, RC_NAME) : null; | ||
var cwd = process.cwd(); | ||
@@ -48,4 +47,2 @@ /* | ||
debug = debug('mdast:configuration'); | ||
var base = { | ||
@@ -55,4 +52,4 @@ 'settings': {} | ||
utilities.copy(base.settings, defaults.parse); | ||
utilities.copy(base.settings, defaults.stringify); | ||
extend(base.settings, defaults.parse); | ||
extend(base.settings, defaults.stringify); | ||
@@ -135,3 +132,3 @@ /** | ||
exception.message = 'Cannot read configuration file: ' + | ||
filePath + '\n' + 'Error: ' + exception.message; | ||
filePath + '\n' + exception.message; | ||
@@ -229,5 +226,7 @@ throw exception; | ||
self.cwd = settings.cwd || process.cwd(); | ||
self.settings = settings.settings || {}; | ||
self.plugins = settings.plugins || {}; | ||
self.useRC = settings.useRC; | ||
self.detectRC = settings.detectRC; | ||
@@ -237,3 +236,3 @@ if (file) { | ||
cliConfiguration = load(path.resolve(cwd, file)); | ||
cliConfiguration = load(path.resolve(self.cwd, file)); | ||
} | ||
@@ -243,3 +242,3 @@ | ||
self.finder = new Finder([RC_NAME, PACKAGE_NAME]); | ||
self.finder = new Finder([RC_NAME, PACKAGE_NAME], self.cwd); | ||
} | ||
@@ -265,6 +264,6 @@ | ||
var self = this; | ||
var directory = filePath ? path.dirname(filePath) : cwd; | ||
var directory = filePath ? path.dirname(filePath) : self.cwd; | ||
var configuration = self.cache[directory]; | ||
debug('Constructing configuration for `' + (filePath || cwd) + '`'); | ||
debug('Constructing configuration for `' + (filePath || self.cwd) + '`'); | ||
@@ -276,3 +275,3 @@ if (!configuration) { | ||
if (!self.useRC) { | ||
if (!self.detectRC) { | ||
debug('Ignoring .rc files'); | ||
@@ -279,0 +278,0 @@ } else { |
/** | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer. All rights reserved. | ||
* @module Finder | ||
* @module mdast:cli:finder | ||
* @fileoverview Find one or more files by searching | ||
@@ -28,8 +28,2 @@ * the file system. | ||
/* | ||
* Constants. | ||
*/ | ||
var cwd = process.cwd(); | ||
/** | ||
@@ -63,5 +57,7 @@ * Get the entries for a directory. | ||
* @param {Array.<string>} files - Files to search for. | ||
* @param {string?} cwd - Current working directory. | ||
*/ | ||
function Finder(files) { | ||
function Finder(files, cwd) { | ||
this.filenames = files; | ||
this.cwd = cwd || process.cwd(); | ||
@@ -87,3 +83,3 @@ this.cache = {}; | ||
var cache = self.cache; | ||
var currentDirectory = directory ? resolve(directory) : cwd; | ||
var currentDirectory = directory ? resolve(directory) : self.cwd; | ||
var child; | ||
@@ -90,0 +86,0 @@ var directories; |
/** | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer. All rights reserved. | ||
* @module Ignore | ||
* @module mdast:cli:ignore | ||
* @fileoverview Find mdast ignore files. | ||
@@ -16,3 +16,3 @@ */ | ||
var path = require('path'); | ||
var debug = require('debug'); | ||
var debug = require('debug')('mdast:cli:ignore'); | ||
var Finder = require('./finder'); | ||
@@ -38,10 +38,2 @@ | ||
/* | ||
* Set-up. | ||
*/ | ||
var cwd = process.cwd(); | ||
debug = debug('mdast:ignore'); | ||
/** | ||
@@ -110,5 +102,6 @@ * Check if a pattern-like line is an applicable pattern. | ||
self.cache = {}; | ||
self.finder = new Finder([IGNORE_NAME]); | ||
self.cwd = options.cwd || process.cwd(); | ||
self.finder = new Finder([IGNORE_NAME], self.cwd); | ||
self.useIgnore = settings.useIgnore; | ||
self.detectIgnore = settings.detectIgnore; | ||
@@ -118,3 +111,3 @@ if (file) { | ||
self.cliIgnore = load(resolve(cwd, file)); | ||
self.cliIgnore = load(resolve(self.cwd, file)); | ||
} | ||
@@ -137,6 +130,6 @@ } | ||
var self = this; | ||
var directory = filePath ? path.dirname(filePath) : cwd; | ||
var directory = filePath ? path.dirname(filePath) : self.cwd; | ||
var ignore = self.cache[directory]; | ||
debug('Constructing ignore for `' + (filePath || cwd) + '`'); | ||
debug('Constructing ignore for `' + (filePath || self.cwd) + '`'); | ||
@@ -147,3 +140,3 @@ if (self.cliIgnore) { | ||
ignore = self.cliIgnore.concat(self.defaults); | ||
} else if (!self.useIgnore) { | ||
} else if (!self.detectIgnore) { | ||
ignore = self.defaults; | ||
@@ -150,0 +143,0 @@ } else if (!has.call(self.cache, directory)) { |
/** | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer. All rights reserved. | ||
* @module Engine | ||
* @module mdast:cli | ||
* @fileoverview CLI Engine. | ||
@@ -14,199 +14,7 @@ */ | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var debug = require('debug')('mdast'); | ||
var chalk = require('chalk'); | ||
var concat = require('concat-stream'); | ||
var mdast = require('../..'); | ||
var Configuration = require('./configuration'); | ||
var program = require('./program'); | ||
var format = require('./formatter'); | ||
var Traverser = require('./traverse'); | ||
var Ignore = require('./ignore'); | ||
var File = require('../file'); | ||
var CLI = require('./cli'); | ||
var fileSetPipeline = require('./file-set-pipeline'); | ||
/* | ||
* Methods. | ||
*/ | ||
var exists = fs.existsSync || path.existsSync; | ||
var resolve = path.resolve; | ||
var join = path.join; | ||
var stat = fs.statSync; | ||
var read = fs.readFile; | ||
var write = fs.writeFile; | ||
var basename = path.basename; | ||
var extname = path.extname; | ||
var dirname = path.dirname; | ||
var stdout = process.stdout; | ||
var stdin = process.stdin; | ||
var stderr = process.stderr; | ||
var underline = chalk.underline; | ||
var yellow = chalk.yellow; | ||
var green = chalk.green; | ||
/* | ||
* Constants. | ||
*/ | ||
var ENCODING = 'utf-8'; | ||
var EXTENSIONS = ['md', 'markdown', 'mkd', 'mkdn', 'mkdown', 'ron']; | ||
var cwd = process.cwd(); | ||
var expextPipeIn = !stdin.isTTY; | ||
var seperator = path.sep; | ||
/** | ||
* Find root of a node module: parent directory of | ||
* `package.json`, or, the given directory if no | ||
* ancestral `package.json` is found. | ||
* | ||
* @example | ||
* findRoot('mdast/test'); // 'mdast' | ||
* | ||
* @param {string} base - Path to directory. | ||
* @return {string} - Path to an ancestral project | ||
* directory. | ||
*/ | ||
function findRoot(base) { | ||
var location = base; | ||
var parts = base.split(seperator); | ||
while (!exists(join(location, 'package.json')) && parts.length > 1) { | ||
parts.pop(); | ||
location = parts.join(seperator); | ||
} | ||
return parts.length ? location : base; | ||
} | ||
/* | ||
* Root. | ||
*/ | ||
var root = findRoot(cwd); | ||
debug('Using root: `%s`', root); | ||
/** | ||
* Require a plugin. Checks, in this order: | ||
* | ||
* - `$package/$pathlike`; | ||
* - `$package/$pathlike.js`; | ||
* - `$package/node_modules/$pathlike`; | ||
* - `$package/node_modules/mdast-$pathlike`; | ||
* - `$cwd/node_modules/$pathlike`; | ||
* - `$cwd/node_modules/mdast-$pathlike`; | ||
* - `$plugin`. | ||
* | ||
* Where `$package` is an ancestral package directory and | ||
* `$cwd` is the current working directory. | ||
* | ||
* @example | ||
* var plugin = findPlugin('toc'); | ||
* | ||
* @throws {Error} - Fails when `pathlike` cannot be | ||
* resolved. | ||
* @param {string} pathlike - Reference to plugin. | ||
* @return {Object} - Result of `require`ing `plugin`. | ||
*/ | ||
function findPlugin(pathlike) { | ||
var local = resolve(root, pathlike); | ||
var npm = resolve(root, 'node_modules', pathlike); | ||
var npmPrefixed = resolve(root, 'node_modules', 'mdast-' + pathlike); | ||
var current = resolve(cwd, 'node_modules', pathlike); | ||
var currentPrefixed = resolve(cwd, 'node_modules', 'mdast-' + pathlike); | ||
var plugin; | ||
if (exists(local) || exists(local + '.js')) { | ||
plugin = local; | ||
} else if (exists(npm)) { | ||
plugin = npm; | ||
} else if (exists(npmPrefixed)) { | ||
plugin = npmPrefixed; | ||
} else if (exists(current)) { | ||
plugin = current; | ||
} else if (exists(currentPrefixed)) { | ||
plugin = currentPrefixed; | ||
} else { | ||
plugin = pathlike; | ||
} | ||
debug('Using plug-in `%s` at `%s`', pathlike, plugin); | ||
return require(plugin); | ||
} | ||
/** | ||
* Process a file. This is the interface between mdast(1) | ||
* and mdast(3). | ||
* | ||
* @example | ||
* var file = new File('Foo bar baz'); | ||
* var configurtion = new Configuration(); | ||
* run(file, configurtion, true, console.log); | ||
* | ||
* @param {File} file - Input file. | ||
* @param {Configuration} configuration - Configuration to | ||
* use. | ||
* @param {boolean} stringify - Whether to stringify, or | ||
* to expose the tree. | ||
* @param {function(Error?, string?, File?)} done | ||
*/ | ||
function run(file, configuration, stringify, done) { | ||
var processor = mdast(); | ||
var options = configuration.getConfiguration(file.filePath()); | ||
var plugins; | ||
var ast; | ||
debug('Using settings `%j`', options.settings); | ||
plugins = Object.keys(options.plugins); | ||
debug('Using plug-ins `%j`', plugins); | ||
/* | ||
* Use, with options. | ||
*/ | ||
plugins.forEach(function (name) { | ||
var option = options.plugins[name]; | ||
var plugin = findPlugin(name); | ||
debug('Applying options `%j` to `%s`', option, name); | ||
processor = processor.use(plugin, option); | ||
}); | ||
debug('Parsing document'); | ||
if (stringify) { | ||
processor.process(file, options.settings, done); | ||
} else { | ||
ast = processor.parse(file, options.settings); | ||
processor.run(ast, file, function (exception) { | ||
if (exception) { | ||
done(exception); | ||
} else { | ||
done(null, JSON.stringify(ast, null, 2), file); | ||
} | ||
}); | ||
} | ||
} | ||
/** | ||
* Bound `console.log`. | ||
*/ | ||
function consoleLog() { | ||
console.log.apply(console, arguments); | ||
} | ||
/** | ||
* No-operation. | ||
*/ | ||
function noop() {} | ||
/** | ||
* CLI engine. This is used by `bin/mdast`. | ||
@@ -217,299 +25,25 @@ * | ||
* | ||
* @throws {Error} - When both stdin and files are used. | ||
* @throws {Error} - When multiple files and a single | ||
* output location is given. | ||
* @param {Array.<*>} argv - CLI arguments. | ||
* @param {function(Error?)} fail - Callback invoked when | ||
* a fatal error occured. Note that uncaught errors do | ||
* also occur: those should be treated as being passed | ||
* to this function. | ||
* @param {Array.<*>|Object} argv - CLI arguments. | ||
* @param {function(Error?, boolean)} done - Callback | ||
* invoked when done. | ||
*/ | ||
function engine(argv, fail) { | ||
var cli = program.parse(argv); | ||
var extensions = [].concat(cli.ext, EXTENSIONS); | ||
var log = cli.silent || cli.quiet ? noop : consoleLog; | ||
var files = cli.args; | ||
var multiFileMode; | ||
var traverser; | ||
var ignore; | ||
function engine(argv, done) { | ||
var cli = new CLI(argv); | ||
var enabled = chalk.enabled; | ||
chalk.enabled = program.color; | ||
chalk.enabled = cli.color; | ||
var configuration = new Configuration({ | ||
'useRC': cli.rc, | ||
'file': cli.configPath, | ||
'settings': cli.setting, | ||
'plugins': cli.use | ||
}); | ||
if (!expextPipeIn && !files.length) { | ||
if (cli.output && cli.output !== true) { | ||
debug('Using output `%s` as input', cli.output); | ||
files.push(cli.output); | ||
} else { | ||
cli.outputHelp(); | ||
fail(); | ||
return; | ||
} | ||
} | ||
ignore = new Ignore({ | ||
'file': cli.ignorePath, | ||
'useIgnore': cli.ignore | ||
}); | ||
traverser = new Traverser(extensions, ignore.getPatterns()); | ||
files = traverser.traverse(files); | ||
multiFileMode = files.length > 1; | ||
if (files.length && expextPipeIn) { | ||
throw new Error('mdast does not accept both files and stdin'); | ||
} | ||
if (cli.filePath && files.length) { | ||
throw new Error( | ||
'mdast does not accept `--file-path` for real files.\n' + | ||
'Did you mean to pass STDIN?' | ||
); | ||
} | ||
/** | ||
* Log `file` warnings and errors, or a success | ||
* message. | ||
* | ||
* @example | ||
* var file = new File(); | ||
* file.warn('Something went wrong!'); | ||
* done(file); | ||
* | ||
* @param {File} file - File to report. | ||
* @param {boolean?} [didWrite] - Whether `file` | ||
* was written to stdout or to thefile system, | ||
* or not. | ||
* @param {string?} fromPath - Path where the file was | ||
* read from. | ||
*/ | ||
function done(file, didWrite, fromPath) { | ||
var hasFailed = file.hasFailed(); | ||
var result; | ||
var filePath; | ||
fileSetPipeline.run(cli, function (err) { | ||
/* | ||
* Remove non-fatal messages in silent mode. | ||
* Check if any file has failed. | ||
*/ | ||
if (program.silent) { | ||
file.messages = file.messages.filter(function (message) { | ||
return message.fatal === true; | ||
}); | ||
} | ||
if (!file.filename) { | ||
file.filename = '<stdin>'; | ||
file.extension = ''; | ||
} | ||
filePath = file.filePath(); | ||
result = format([file]); | ||
/* | ||
* Ensure we exit with `1` if a `fatal` error. | ||
* exists in `file`. | ||
*/ | ||
if (result) { | ||
stderr.write(result + '\n'); | ||
if (hasFailed) { | ||
fail(); | ||
} | ||
} else if (!didWrite) { | ||
log(underline(filePath) + ': ' + yellow('done') + '.'); | ||
} else { | ||
log( | ||
underline(fromPath || filePath) + | ||
(filePath !== fromPath ? ' > ' + green(filePath) : '') + | ||
': ' + green('written') + '.' | ||
); | ||
} | ||
} | ||
/** | ||
* Output result after processing. | ||
* | ||
* @example | ||
* output(new Error('Foo')); | ||
* output(null, 'foo', new File()); | ||
* | ||
* @param {Error?} exception - Error which occurred | ||
* during processing. | ||
* @param {string?} [doc] - Processed document. | ||
* @param {File?} [file] - Processed file. | ||
*/ | ||
function output(exception, doc, file) { | ||
var outpath = cli.output; | ||
var currentPath; | ||
var extension; | ||
var isDir; | ||
if (exception) { | ||
fail(exception); | ||
return; | ||
} | ||
/* | ||
* `stdout`. | ||
*/ | ||
if (!multiFileMode && !outpath) { | ||
debug('Writing document to standard out'); | ||
done(file); | ||
stdout.write(doc); | ||
return; | ||
} | ||
currentPath = file.filePath(); | ||
if (!outpath) { | ||
done(file); | ||
return; | ||
} | ||
if (outpath !== true) { | ||
try { | ||
isDir = stat(resolve(outpath)).isDirectory(); | ||
} catch (err) { | ||
if ( | ||
err.code !== 'ENOENT' || | ||
outpath.charAt(outpath.length - 1) === seperator | ||
) { | ||
throw err; | ||
} | ||
/* | ||
* This throws, or the parent exists, which | ||
* is a directory, but we should keep the | ||
* filename and extension of the given | ||
* file. | ||
*/ | ||
stat(resolve(dirname(outpath))).isDirectory(); | ||
isDir = false; | ||
} | ||
if (!isDir && multiFileMode) { | ||
throw new Error( | ||
'Cannot write multiple files to single output: ' + outpath | ||
); | ||
} | ||
extension = extname(outpath); | ||
file.move({ | ||
'extension': isDir ? '' : extension ? extension.slice(1) : '', | ||
'filename': isDir ? '' : basename(outpath, extension), | ||
'directory': isDir ? outpath : dirname(outpath) | ||
}); | ||
} | ||
debug('Writing document to `%s`', file.filePath()); | ||
write(file.filePath(), doc, function (err) { | ||
if (err) { | ||
file.fail(err); | ||
} | ||
done(file, true, currentPath); | ||
var hasFailed = (cli.files || []).some(function (file) { | ||
return file.hasFailed(); | ||
}); | ||
} | ||
/** | ||
* Factory for `check`. Used as a callback to results | ||
* from `stdin` and file system. | ||
* | ||
* @example | ||
* var check = checkFactory(new File('Foo'), false); | ||
* check('Bar'); | ||
* | ||
* @param {File} file | ||
* @param {boolean?} [canFail] - `false` if the first | ||
* parameter passed `check` is not an error, but | ||
* the actual value. | ||
* @return {function(Error?, string?)} | ||
*/ | ||
function checkFactory(file, canFail) { | ||
/** | ||
* Safely process a document. | ||
* | ||
* @param {Error?} exception | ||
* @param {string?} [doc] | ||
*/ | ||
function check(exception, doc) { | ||
if (canFail === false) { | ||
doc = exception; | ||
exception = null; | ||
} | ||
chalk.enabled = enabled; | ||
file.contents = doc || ''; | ||
if (exception) { | ||
file.fail(exception); | ||
done(file); | ||
return; | ||
} | ||
try { | ||
run(file, configuration, !cli.ast, output); | ||
} catch (failure) { | ||
file.fail(failure); | ||
done(file); | ||
} | ||
} | ||
return check; | ||
} | ||
if (files.length) { | ||
files.forEach(function (file) { | ||
if (!file.isFile || file.hasFailed()) { | ||
done(file); | ||
} else { | ||
debug('Reading `%s` in `%s`', file.filePath(), ENCODING); | ||
read(file.filePath(), ENCODING, checkFactory(file)); | ||
} | ||
}); | ||
} else { | ||
debug('Reading from stdin'); | ||
process.stdin.pipe(concat({ | ||
'encoding': 'string' | ||
}, function (value) { | ||
var extension = cli.filePath && extname(cli.filePath); | ||
var file = new File(cli.filePath ? { | ||
'directory': dirname(cli.filePath), | ||
'filename': basename(cli.filePath, extension), | ||
'extension': extension.slice(1) | ||
} : {}); | ||
file.quiet = true; | ||
file.exists = true; | ||
file.isFile = true; | ||
checkFactory(file, false)(value); | ||
})); | ||
} | ||
done(err, !hasFailed); | ||
}); | ||
} | ||
@@ -516,0 +50,0 @@ |
@@ -18,2 +18,5 @@ /** | ||
var repeat = require('repeat-string'); | ||
var extend = require('extend.js'); | ||
var ccount = require('ccount'); | ||
var longesStreak = require('longest-streak'); | ||
var utilities = require('./utilities.js'); | ||
@@ -26,7 +29,4 @@ var defaultOptions = require('./defaults.js').stringify; | ||
var clone = utilities.clone; | ||
var raise = utilities.raise; | ||
var validate = utilities.validate; | ||
var count = utilities.countCharacter; | ||
var objectCreate = utilities.create; | ||
@@ -98,3 +98,3 @@ /* | ||
var ENTITY_OPTIONS = objectCreate(); | ||
var ENTITY_OPTIONS = {}; | ||
@@ -110,3 +110,3 @@ ENTITY_OPTIONS.true = true; | ||
var LIST_BULLETS = objectCreate(); | ||
var LIST_BULLETS = {}; | ||
@@ -121,3 +121,3 @@ LIST_BULLETS[ASTERISK] = true; | ||
var HORIZONTAL_RULE_BULLETS = objectCreate(); | ||
var HORIZONTAL_RULE_BULLETS = {}; | ||
@@ -132,3 +132,3 @@ HORIZONTAL_RULE_BULLETS[ASTERISK] = true; | ||
var EMPHASIS_MARKERS = objectCreate(); | ||
var EMPHASIS_MARKERS = {}; | ||
@@ -142,3 +142,3 @@ EMPHASIS_MARKERS[UNDERSCORE] = true; | ||
var FENCE_MARKERS = objectCreate(); | ||
var FENCE_MARKERS = {}; | ||
@@ -152,3 +152,3 @@ FENCE_MARKERS[TICK] = true; | ||
var ORDERED_MAP = objectCreate(); | ||
var ORDERED_MAP = {}; | ||
@@ -162,3 +162,3 @@ ORDERED_MAP.true = 'visitOrderedItems'; | ||
var LIST_ITEM_INDENTS = objectCreate(); | ||
var LIST_ITEM_INDENTS = {}; | ||
@@ -177,3 +177,3 @@ var LIST_ITEM_TAB = 'tab'; | ||
var CHECKBOX_MAP = objectCreate(); | ||
var CHECKBOX_MAP = {}; | ||
@@ -300,3 +300,3 @@ CHECKBOX_MAP.null = EMPTY; | ||
EXPRESSIONS_WHITE_SPACE.test(uri) || | ||
count(uri, PARENTHESIS_OPEN) !== count(uri, PARENTHESIS_CLOSE) | ||
ccount(uri, PARENTHESIS_OPEN) !== ccount(uri, PARENTHESIS_CLOSE) | ||
) { | ||
@@ -339,40 +339,2 @@ return ANGLE_BRACKET_OPEN + uri + ANGLE_BRACKET_CLOSE; | ||
/** | ||
* Get the count of the longest repeating streak | ||
* of `character` in `value`. | ||
* | ||
* @example | ||
* getLongestRepetition('` foo `` bar `', '`') // 2 | ||
* | ||
* @param {string} value - Content. | ||
* @param {string} character - Single character to look | ||
* for. | ||
* @return {number} - Number of characters at the place | ||
* where `character` occurs in its longest streak in | ||
* `value`. | ||
*/ | ||
function getLongestRepetition(value, character) { | ||
var highestCount = 0; | ||
var index = -1; | ||
var length = value.length; | ||
var currentCount = 0; | ||
var currentCharacter; | ||
while (++index < length) { | ||
currentCharacter = value.charAt(index); | ||
if (currentCharacter === character) { | ||
currentCount++; | ||
if (currentCount > highestCount) { | ||
highestCount = currentCount; | ||
} | ||
} else { | ||
currentCount = 0; | ||
} | ||
} | ||
return highestCount; | ||
} | ||
/** | ||
* Pad `value` with `level * INDENT` spaces. Respects | ||
@@ -423,3 +385,3 @@ * lines. | ||
self.options = clone(self.options); | ||
self.options = extend({}, self.options); | ||
@@ -477,3 +439,3 @@ self.setOptions(options); | ||
} else if (typeof options === 'object') { | ||
options = clone(options); | ||
options = extend({}, options); | ||
} else { | ||
@@ -1066,3 +1028,3 @@ raise(options, 'options'); | ||
var value = token.value; | ||
var ticks = repeat(TICK, getLongestRepetition(value, TICK) + 1); | ||
var ticks = repeat(TICK, longesStreak(value, TICK) + 1); | ||
var start = ticks; | ||
@@ -1164,3 +1126,3 @@ var end = ticks; | ||
fence = getLongestRepetition(value, marker) + 1; | ||
fence = longesStreak(value, marker) + 1; | ||
@@ -1167,0 +1129,0 @@ fence = repeat(marker, Math.max(fence, MINIMUM_CODE_FENCE_LENGTH)); |
@@ -12,6 +12,6 @@ /** | ||
/* | ||
* Methods. | ||
* Dependencies. | ||
*/ | ||
var has = Object.prototype.hasOwnProperty; | ||
var collapseWhiteSpace = require('collapse-white-space'); | ||
@@ -22,52 +22,7 @@ /* | ||
var WHITE_SPACE_FINAL = /\s+$/; | ||
var NEW_LINES_FINAL = /\n+$/; | ||
var WHITE_SPACE_INITIAL = /^\s+/; | ||
var EXPRESSION_LINE_BREAKS = /\r\n|\r/g; | ||
var EXPRESSION_SYMBOL_FOR_NEW_LINE = /\u2424/g; | ||
var WHITE_SPACE_COLLAPSABLE = /[ \t\n]+/g; | ||
var EXPRESSION_BOM = /^\ufeff/; | ||
/** | ||
* Shallow copy `context` into `target`. | ||
* | ||
* @example | ||
* var target = {}; | ||
* copy(target, {foo: 'bar'}); // target | ||
* | ||
* @param {Object} target - Object to copy into. | ||
* @param {Object} context - Object to copy from. | ||
* @return {Object} - `target`. | ||
*/ | ||
function copy(target, context) { | ||
var key; | ||
for (key in context) { | ||
if (has.call(context, key)) { | ||
target[key] = context[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
/** | ||
* Shallow clone `context`. | ||
* | ||
* @example | ||
* clone({foo: 'bar'}) // {foo: 'bar'} | ||
* clone(['foo', 'bar']) // ['foo', 'bar'] | ||
* | ||
* @return {Object|Array} context - Object to clone. | ||
* @return {Object|Array} - Shallow clone of `context`. | ||
*/ | ||
function clone(context) { | ||
if ('concat' in context) { | ||
return context.concat(); | ||
} | ||
return copy({}, context); | ||
} | ||
/** | ||
* Throw an exception with in its `message` `value` | ||
@@ -179,67 +134,2 @@ * and `name`. | ||
/** | ||
* Remove final white space from `value`. | ||
* | ||
* @example | ||
* trimRight('foo '); // 'foo' | ||
* | ||
* @param {string} value - Content to trim. | ||
* @return {string} - Trimmed content. | ||
*/ | ||
function trimRight(value) { | ||
return String(value).replace(WHITE_SPACE_FINAL, ''); | ||
} | ||
/** | ||
* Remove final new line characters from `value`. | ||
* | ||
* @example | ||
* trimRightLines('foo\n\n'); // 'foo' | ||
* | ||
* @param {string} value - Content to trim. | ||
* @return {string} - Trimmed content. | ||
*/ | ||
function trimRightLines(value) { | ||
return String(value).replace(NEW_LINES_FINAL, ''); | ||
} | ||
/** | ||
* Remove initial white space from `value`. | ||
* | ||
* @example | ||
* trimLeft(' foo'); // 'foo' | ||
* | ||
* @param {string} value - Content to trim. | ||
* @return {string} - Trimmed content. | ||
*/ | ||
function trimLeft(value) { | ||
return String(value).replace(WHITE_SPACE_INITIAL, ''); | ||
} | ||
/** | ||
* Remove initial and final white space from `value`. | ||
* | ||
* @example | ||
* trim(' foo '); // 'foo' | ||
* | ||
* @param {string} value - Content to trim. | ||
* @return {string} - Trimmed content. | ||
*/ | ||
function trim(value) { | ||
return trimLeft(trimRight(value)); | ||
} | ||
/** | ||
* Collapse white space. | ||
* | ||
* @example | ||
* collapse('foo\t bar'); // 'foo bar' | ||
* | ||
* @param {string} value - Content to collapse. | ||
* @return {string} - Collapsed content. | ||
*/ | ||
function collapse(value) { | ||
return String(value).replace(WHITE_SPACE_COLLAPSABLE, ' '); | ||
} | ||
/** | ||
* Clean a string in preperation of parsing. | ||
@@ -273,61 +163,6 @@ * | ||
function normalizeIdentifier(value) { | ||
return collapse(value).toLowerCase(); | ||
return collapseWhiteSpace(value).toLowerCase(); | ||
} | ||
/** | ||
* Count how many characters `character` occur in `value`. | ||
* | ||
* @example | ||
* countCharacter('foo(bar(baz)', '(') // 2 | ||
* countCharacter('foo(bar(baz)', ')') // 1 | ||
* | ||
* @param {string} value - Content to search in. | ||
* @param {string} character - Character to search for. | ||
* @return {number} - Count. | ||
*/ | ||
function countCharacter(value, character) { | ||
var index = -1; | ||
var length = value.length; | ||
var count = 0; | ||
while (++index < length) { | ||
if (value.charAt(index) === character) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
/** | ||
* Create an empty object. | ||
* | ||
* @example | ||
* objectObject(); // Same as `{}`. | ||
* | ||
* @return {Object} | ||
*/ | ||
function objectObject() { | ||
return {}; | ||
} | ||
/* | ||
* Break coverage. | ||
*/ | ||
objectObject(); | ||
/** | ||
* Create an object without prototype. | ||
* | ||
* @example | ||
* objectNull(); // New object without prototype. | ||
* | ||
* @return {Object} | ||
*/ | ||
function objectNull() { | ||
return Object.create(null); | ||
} | ||
/* | ||
* Expose `validate`. | ||
@@ -346,19 +181,4 @@ */ | ||
exports.trim = trim; | ||
exports.trimLeft = trimLeft; | ||
exports.trimRight = trimRight; | ||
exports.trimRightLines = trimRightLines; | ||
exports.collapse = collapse; | ||
exports.normalizeIdentifier = normalizeIdentifier; | ||
exports.clean = clean; | ||
exports.raise = raise; | ||
exports.copy = copy; | ||
exports.clone = clone; | ||
exports.countCharacter = countCharacter; | ||
/* istanbul ignore else */ | ||
if ('create' in Object) { | ||
exports.create = objectNull; | ||
} else { | ||
exports.create = objectObject; | ||
} |
{ | ||
"name": "mdast", | ||
"version": "0.26.2", | ||
"version": "0.27.0-rc.1", | ||
"description": "Markdown processor powered by plugins", | ||
@@ -21,7 +21,11 @@ "license": "MIT", | ||
"camelcase": "^1.0.0", | ||
"ccount": "^1.0.0", | ||
"chalk": "^1.0.0", | ||
"collapse-white-space": "^1.0.0", | ||
"commander": "^2.0.0", | ||
"concat-stream": "^1.0.0", | ||
"debug": "^2.0.0", | ||
"extend.js": "0.0.2", | ||
"he": "^0.5.0", | ||
"longest-streak": "^1.0.0", | ||
"markdown-table": "^0.4.0", | ||
@@ -31,2 +35,4 @@ "minimatch": "^2.0.0", | ||
"text-table": "^0.2.0", | ||
"trim": "^0.0.1", | ||
"trim-trailing-lines": "^1.0.0", | ||
"user-home": "^2.0.0", | ||
@@ -67,3 +73,3 @@ "ware": "^1.2.0" | ||
"mdast-lint": "^0.4.0", | ||
"mdast-man": "^0.3.0", | ||
"mdast-man": "^0.4.0", | ||
"mdast-toc": "^0.5.0", | ||
@@ -70,0 +76,0 @@ "mdast-usage": "^0.3.0", |
Sorry, the diff of this file is not supported yet
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
287644
40
6898
18
8
+ Addedccount@^1.0.0
+ Addedcollapse-white-space@^1.0.0
+ Addedextend.js@0.0.2
+ Addedlongest-streak@^1.0.0
+ Addedtrim@^0.0.1
+ Addedtrim-trailing-lines@^1.0.0
+ Addedccount@1.1.0(transitive)
+ Addedcollapse-white-space@1.0.6(transitive)
+ Addedextend.js@0.0.2(transitive)
+ Addedlongest-streak@1.0.0(transitive)
+ Addedtrim@0.0.1(transitive)
+ Addedtrim-trailing-lines@1.1.4(transitive)