Comparing version 0.17.1 to 0.18.0
@@ -6,2 +6,14 @@ --- | ||
0.18.0 / 2015-04-12 | ||
=================== | ||
* Add list of plugins to `doc/Plugins.md` ([175b242](https://github.com/wooorm/mdast/commit/175b242)) | ||
* Refactor tokenizers to return tokenized node ([cce3ec9](https://github.com/wooorm/mdast/commit/cce3ec9)) | ||
* Remove mergin of HTML nodes into a single token ([6d529d9](https://github.com/wooorm/mdast/commit/6d529d9)) | ||
* Add support for plugin options to mdast(1) ([361f7dd](https://github.com/wooorm/mdast/commit/361f7dd)) | ||
* Fix variable name ([1590bff](https://github.com/wooorm/mdast/commit/1590bff)) | ||
* Update mdast-toc ([8e51ace](https://github.com/wooorm/mdast/commit/8e51ace)) | ||
* Add `loose` property on lists ([e071484](https://github.com/wooorm/mdast/commit/e071484)) | ||
* Add support for plug-in options to `mdasrc` files ([cc178f0](https://github.com/wooorm/mdast/commit/cc178f0)) | ||
0.17.1 / 2015-04-08 | ||
@@ -8,0 +20,0 @@ =================== |
@@ -69,3 +69,3 @@ 'use strict'; | ||
if (!result) { | ||
result = []; | ||
result = {}; | ||
@@ -75,9 +75,13 @@ target[key] = result; | ||
index = -1; | ||
length = value.length; | ||
if ('length' in value) { | ||
index = -1; | ||
length = value.length; | ||
while (++index < length) { | ||
if (result.indexOf(value[index]) === -1) { | ||
result.push(value[index]); | ||
while (++index < length) { | ||
if (!(value[index] in result)) { | ||
result[value[index]] = null; | ||
} | ||
} | ||
} else { | ||
target[key] = merge(result || {}, value); | ||
} | ||
@@ -84,0 +88,0 @@ } else if (typeof value === 'object' && value !== null) { |
@@ -99,3 +99,3 @@ 'use strict'; | ||
debug('Using plugin `%s` at `%s`', pathlike, plugin); | ||
debug('Using plug-in `%s` at `%s`', pathlike, plugin); | ||
@@ -124,8 +124,16 @@ return require(plugin); | ||
plugins = options.plugins.map(findPlugin); | ||
plugins = Object.keys(options.plugins); | ||
debug('Using plug-ins `%j`', options.plugins); | ||
debug('Using plug-ins `%j`', plugins); | ||
processor.use(plugins); | ||
/* | ||
* Use, with options. | ||
*/ | ||
plugins.forEach(function (plugin) { | ||
var option = options.plugins[plugin]; | ||
processor = processor.use(findPlugin(plugin), option); | ||
}); | ||
debug('Parsing document'); | ||
@@ -132,0 +140,0 @@ |
@@ -60,10 +60,37 @@ 'use strict'; | ||
/** | ||
* Parse a plugin into its name and options. | ||
* | ||
* @param {string} plugin | ||
*/ | ||
function parsePlugin(plugin) { | ||
var index = plugin.indexOf('='); | ||
var name; | ||
var value; | ||
if (index === -1) { | ||
name = plugin; | ||
value = null; | ||
} else { | ||
name = plugin.slice(0, index); | ||
value = options(plugin.slice(index + 1), {}); | ||
} | ||
return { | ||
'name': name, | ||
'value': value | ||
}; | ||
} | ||
/** | ||
* Parse plugins into a list. | ||
* | ||
* @param {string} plugin | ||
* @param {Array.<string>} cache | ||
* @return {Array.<string>} | ||
* @param {Object} cache | ||
*/ | ||
function plugins(plugin, cache) { | ||
return cache.concat(plugin.split(SPLITTER)); | ||
plugin = parsePlugin(plugin); | ||
cache[plugin.name] = plugin.value; | ||
return cache; | ||
} | ||
@@ -92,8 +119,9 @@ | ||
console.log(' # Pass stdin through mdast, with settings, to stdout'); | ||
console.log(' $ cat Readme.md | ' + COMMAND + ' --setting ' + | ||
'"setext, bullet: *" > Readme-new.md'); | ||
console.log(' $ cat Readme.md | ' + COMMAND + ' -s "setext, bullet: *"' + | ||
' > Readme-new.md'); | ||
console.log(); | ||
console.log(' # Use a plugin'); | ||
console.log(' # Use a plugin (with options)'); | ||
console.log(' $ npm install mdast-toc'); | ||
console.log(' $ ' + COMMAND + ' --use mdast-toc Readme.md -o'); | ||
console.log(' $ ' + COMMAND + ' --use toc=heading:contents Readme.md ' + | ||
'-o'); | ||
console.log(); | ||
@@ -122,3 +150,3 @@ console.log(' # Rewrite markdown in a directory'); | ||
.option('-s, --setting <settings>', 'specify settings', options, {}) | ||
.option('-u, --use <plugins>', 'use transform plugin(s)', plugins, []) | ||
.option('-u, --use <plugins>', 'use transform plugin(s)', plugins, {}) | ||
.option('-e, --ext <extensions>', 'specify extensions', extensions, []) | ||
@@ -125,0 +153,0 @@ .option('-a, --ast', 'output AST information', false) |
175
lib/parse.js
@@ -395,15 +395,2 @@ 'use strict'; | ||
/** | ||
* Merge two HTML nodes: `token` into `prev`. | ||
* | ||
* @param {Object} prev | ||
* @param {Object} token | ||
* @return {Object} `prev`. | ||
*/ | ||
MERGEABLE_NODES.html = function (prev, token) { | ||
prev.value += NEW_LINE + NEW_LINE + token.value; | ||
return prev; | ||
}; | ||
/** | ||
* Merge two text nodes: `token` into `prev`. | ||
@@ -479,2 +466,3 @@ * | ||
* @param {string} $0 - Whole code. | ||
* @return {Node} | ||
*/ | ||
@@ -484,3 +472,5 @@ function tokenizeCode(eat, $0) { | ||
eat($0)(this.renderCodeBlock(removeIndentation($0, TAB_SIZE), null, eat)); | ||
return eat($0)(this.renderCodeBlock( | ||
removeIndentation($0, TAB_SIZE), null, eat) | ||
); | ||
} | ||
@@ -498,2 +488,3 @@ | ||
* @param {string} $5 - Content. | ||
* @return {Node} | ||
*/ | ||
@@ -515,3 +506,3 @@ function tokenizeFences(eat, $0, $1, $2, $3, $4, $5) { | ||
eat($0)(this.renderCodeBlock($5, $4, eat)); | ||
return eat($0)(this.renderCodeBlock($5, $4, eat)); | ||
} | ||
@@ -528,2 +519,3 @@ | ||
* @param {string} $4 - Content. | ||
* @return {Node} | ||
*/ | ||
@@ -537,3 +529,3 @@ function tokenizeHeading(eat, $0, $1, $2, $3, $4) { | ||
eat($0)(this.renderHeading($4, $2.length)); | ||
return eat($0)(this.renderHeading($4, $2.length)); | ||
} | ||
@@ -549,6 +541,8 @@ | ||
* @param {string} $3 - Underline marker. | ||
* @return {Node} | ||
*/ | ||
function tokenizeLineHeading(eat, $0, $1, $2, $3) { | ||
eat($1); | ||
eat($0)(this.renderHeading($2, $3 === EQUALS ? 1 : 2)); | ||
return eat($0)(this.renderHeading($2, $3 === EQUALS ? 1 : 2)); | ||
} | ||
@@ -561,5 +555,6 @@ | ||
* @param {string} $0 - Whole rule. | ||
* @return {Node} | ||
*/ | ||
function tokenizeHorizontalRule(eat, $0) { | ||
eat($0)(this.renderVoid(HORIZONTAL_RULE)); | ||
return eat($0)(this.renderVoid(HORIZONTAL_RULE)); | ||
} | ||
@@ -572,2 +567,3 @@ | ||
* @param {string} $0 - Whole blockquote. | ||
* @return {Node} | ||
*/ | ||
@@ -579,3 +575,3 @@ function tokenizeBlockquote(eat, $0) { | ||
eat($0)(this.renderBlockquote($0, now)); | ||
return eat($0)(this.renderBlockquote($0, now)); | ||
} | ||
@@ -590,2 +586,3 @@ | ||
* @param {string} $2 - Bullet. | ||
* @return {Node} | ||
*/ | ||
@@ -598,2 +595,3 @@ function tokenizeList(eat, $0, $1, $2) { | ||
var index = 0; | ||
var isLoose = false; | ||
var now; | ||
@@ -605,3 +603,3 @@ var bullet; | ||
var exitBlockquote; | ||
var list; | ||
var node; | ||
var indent; | ||
@@ -676,3 +674,3 @@ var size; | ||
list = add(self.renderList([], firstBullet)); | ||
node = add(self.renderList([], firstBullet)); | ||
@@ -683,4 +681,8 @@ while (++index < length) { | ||
item = eat(item)(list, self.renderListItem(item, now)); | ||
item = eat(item)(node, self.renderListItem(item, now)); | ||
if (item.loose) { | ||
isLoose = true; | ||
} | ||
if (index !== length - 1) { | ||
@@ -691,6 +693,10 @@ eat(NEW_LINE); | ||
list.position.end = eat.now(); | ||
node.loose = isLoose; | ||
node.position.end = eat.now(); | ||
enterTop(); | ||
exitBlockquote(); | ||
return node; | ||
} | ||
@@ -703,2 +709,3 @@ | ||
* @param {string} $0 - Whole HTML. | ||
* @return {Node} | ||
*/ | ||
@@ -708,3 +715,3 @@ function tokenizeHtml(eat, $0) { | ||
eat($0)(this.renderRaw(HTML, $0)); | ||
return eat($0)(this.renderRaw(HTML, $0)); | ||
} | ||
@@ -722,2 +729,3 @@ | ||
* @param {string} $3 - Title. | ||
* @return {Node?} | ||
*/ | ||
@@ -728,2 +736,3 @@ function tokenizeLinkDefinition(eat, $0, $1, $2, $3) { | ||
var add = eat($0); | ||
var node; | ||
@@ -735,6 +744,12 @@ if (!has.call(self.links, identifier)) { | ||
self.links[identifier] = add({}, self.renderLink( | ||
true, self.descape($2), null, $3, eat.now(), eat | ||
)); | ||
$2 = self.descape($2); | ||
node = self.renderLink(true, $2, null, $3, eat.now(), eat); | ||
self.links[identifier] = add({}, node); | ||
return node; | ||
} | ||
return null; | ||
} | ||
@@ -752,5 +767,6 @@ | ||
* @param {string} $1 - Content. | ||
* @return {Node} | ||
*/ | ||
function tokenizeYAMLFrontMatter(eat, $0, $1) { | ||
eat($0)(this.renderRaw(YAML, $1 ? trimRightLines($1) : EMPTY)); | ||
return eat($0)(this.renderRaw(YAML, $1 ? trimRightLines($1) : EMPTY)); | ||
} | ||
@@ -770,2 +786,3 @@ | ||
* @param {string} $3 - Whole value. | ||
* @return {Node} | ||
*/ | ||
@@ -778,3 +795,3 @@ function tokenizeFootnoteDefinition(eat, $0, $1, $2, $3) { | ||
var identifier = escapeKey(normalize($2)); | ||
var token; | ||
var node; | ||
@@ -790,5 +807,7 @@ $3 = $3.replace(EXPRESSION_INITIAL_TAB, function (value) { | ||
token = eat($0)({}, self.renderFootnoteDefinition(identifier, $3, now)); | ||
node = eat($0)({}, self.renderFootnoteDefinition(identifier, $3, now)); | ||
self.footnotes[identifier] = token; | ||
self.footnotes[identifier] = node; | ||
return node; | ||
} | ||
@@ -810,6 +829,7 @@ | ||
* @param {string} $5 - Rows. | ||
* @return {Node} | ||
*/ | ||
function tokenizeTable(eat, $0, $1, $2, $3, $4, $5) { | ||
var self = this; | ||
var table; | ||
var node; | ||
var index; | ||
@@ -819,3 +839,3 @@ var length; | ||
table = eat(EMPTY)({ | ||
node = eat(EMPTY)({ | ||
'type': TABLE, | ||
@@ -907,3 +927,3 @@ 'align': [], | ||
function renderRow(type, value) { | ||
var row = eat(EMPTY)(table, self.renderBlock(type, [])); | ||
var row = eat(EMPTY)(node, self.renderBlock(type, [])); | ||
@@ -935,3 +955,3 @@ value | ||
table.align = getAlignment($4); | ||
node.align = getAlignment($4); | ||
@@ -955,3 +975,5 @@ /* | ||
table.position.end = eat.now(); | ||
node.position.end = eat.now(); | ||
return node; | ||
} | ||
@@ -967,2 +989,3 @@ | ||
* @param {string} $0 | ||
* @return {Node?} | ||
*/ | ||
@@ -973,3 +996,3 @@ function tokenizeParagraph(eat, $0) { | ||
return; | ||
return null; | ||
} | ||
@@ -979,3 +1002,3 @@ | ||
eat($0)(this.renderBlock(PARAGRAPH, $0)); | ||
return eat($0)(this.renderBlock(PARAGRAPH, $0)); | ||
} | ||
@@ -988,5 +1011,6 @@ | ||
* @param {string} $0 | ||
* @return {Node} | ||
*/ | ||
function tokenizeText(eat, $0) { | ||
eat($0)(this.renderRaw(TEXT, $0)); | ||
return eat($0)(this.renderRaw(TEXT, $0)); | ||
} | ||
@@ -1030,2 +1054,6 @@ | ||
/* | ||
* `loose` should be added later. | ||
*/ | ||
return { | ||
@@ -1035,2 +1063,3 @@ 'type': LIST, | ||
'start': start, | ||
'loose': null, | ||
'children': children | ||
@@ -1390,5 +1419,6 @@ }; | ||
* @param {string} $1 - Escaped character. | ||
* @return {Node} | ||
*/ | ||
function tokenizeEscape(eat, $0, $1) { | ||
eat($0)(this.renderRaw(ESCAPE, $1)); | ||
return eat($0)(this.renderRaw(ESCAPE, $1)); | ||
} | ||
@@ -1404,2 +1434,3 @@ | ||
* @param {string?} $2 - Protocol or at. | ||
* @return {Node} | ||
*/ | ||
@@ -1413,2 +1444,3 @@ function tokenizeAutoLink(eat, $0, $1, $2) { | ||
var tokenize; | ||
var node; | ||
@@ -1436,5 +1468,7 @@ if ($2 === AT_SIGN) { | ||
eat($0)(self.renderLink(true, href, text, null, now, eat)); | ||
node = eat($0)(self.renderLink(true, href, text, null, now, eat)); | ||
self.inlineTokenizers.escape = tokenize; | ||
return node; | ||
} | ||
@@ -1451,2 +1485,3 @@ | ||
* @param {string} $1 - URL. | ||
* @return {Node} | ||
*/ | ||
@@ -1456,3 +1491,3 @@ function tokenizeURL(eat, $0, $1) { | ||
eat($0)(this.renderLink(true, $1, $1, null, now, eat)); | ||
return eat($0)(this.renderLink(true, $1, $1, null, now, eat)); | ||
} | ||
@@ -1467,2 +1502,3 @@ | ||
* @param {string} $0 - Content. | ||
* @return {Node} | ||
*/ | ||
@@ -1478,3 +1514,3 @@ function tokenizeTag(eat, $0) { | ||
eat($0)(self.renderRaw(HTML, $0)); | ||
return eat($0)(self.renderRaw(HTML, $0)); | ||
} | ||
@@ -1494,2 +1530,3 @@ | ||
* @param {string?} $7 - Title wrapped in parentheses. | ||
* @return {Node?} | ||
*/ | ||
@@ -1507,6 +1544,8 @@ function tokenizeLink(eat, $0, $1, $2, $3, $4, $5, $6, $7) { | ||
eat($0)(this.renderLink( | ||
return eat($0)(this.renderLink( | ||
isLink, this.descape(href), $2, title, now, eat | ||
)); | ||
} | ||
return null; | ||
} | ||
@@ -1524,2 +1563,3 @@ | ||
* @param {string} $3 - Content. | ||
* @return {Node} | ||
*/ | ||
@@ -1549,4 +1589,6 @@ function tokenizeReferenceLink(eat, $0, $1, $2, $3) { | ||
eat($0)(self.renderFootnote(identifier)); | ||
} else if (!url || !url.href) { | ||
return eat($0)(self.renderFootnote(identifier)); | ||
} | ||
if (!url || !url.href) { | ||
if (isFootnote && text.indexOf(SPACE) > -1) { | ||
@@ -1579,16 +1621,16 @@ /* | ||
eat($0)(self.renderFootnote(token.id)); | ||
} else { | ||
eat($0.charAt(0))(self.renderRaw(TEXT, $0.charAt(0))); | ||
return eat($0)(self.renderFootnote(token.id)); | ||
} | ||
} else { | ||
now = eat.now($1); | ||
now.column += $1.length; | ||
return eat($0.charAt(0))(self.renderRaw(TEXT, $0.charAt(0))); | ||
} | ||
eat($0)(self.renderLink( | ||
$0.charAt(0) !== EXCLAMATION_MARK, self.descape(url.href), | ||
$2, url.title, now, eat | ||
)); | ||
} | ||
now = eat.now($1); | ||
now.column += $1.length; | ||
return eat($0)(self.renderLink( | ||
$0.charAt(0) !== EXCLAMATION_MARK, self.descape(url.href), | ||
$2, url.title, now, eat | ||
)); | ||
} | ||
@@ -1607,2 +1649,3 @@ | ||
* @param {string?} $4 - Content. | ||
* @return {Node?} | ||
*/ | ||
@@ -1614,3 +1657,3 @@ function tokenizeStrong(eat, $0, $1, $2, $3, $4) { | ||
if (trim(value) === EMPTY) { | ||
return; | ||
return null; | ||
} | ||
@@ -1620,3 +1663,3 @@ | ||
eat($0)(this.renderInline(STRONG, value, now)); | ||
return eat($0)(this.renderInline(STRONG, value, now)); | ||
} | ||
@@ -1633,2 +1676,3 @@ | ||
* @param {string?} $4 - Content. | ||
* @return {Node?} | ||
*/ | ||
@@ -1645,3 +1689,3 @@ function tokenizeEmphasis(eat, $0, $1, $2, $3, $4) { | ||
) { | ||
return; | ||
return null; | ||
} | ||
@@ -1651,3 +1695,3 @@ | ||
eat($0)(this.renderInline(EMPHASIS, value, now)); | ||
return eat($0)(this.renderInline(EMPHASIS, value, now)); | ||
} | ||
@@ -1661,2 +1705,3 @@ | ||
* @param {string} $1 - Content. | ||
* @return {Node} | ||
*/ | ||
@@ -1668,3 +1713,3 @@ function tokenizeDeletion(eat, $0, $1) { | ||
eat($0)(this.renderInline(DELETE, $1, now)); | ||
return eat($0)(this.renderInline(DELETE, $1, now)); | ||
} | ||
@@ -1679,5 +1724,6 @@ | ||
* @param {string} $2 - Content. | ||
* @return {Node} | ||
*/ | ||
function tokenizeInlineCode(eat, $0, $1, $2) { | ||
eat($0)(this.renderRaw(INLINE_CODE, trim($2 || ''))); | ||
return eat($0)(this.renderRaw(INLINE_CODE, trim($2 || ''))); | ||
} | ||
@@ -1690,5 +1736,6 @@ | ||
* @param {string} $0 | ||
* @return {Node} | ||
*/ | ||
function tokenizeBreak(eat, $0) { | ||
eat($0)(this.renderVoid(BREAK)); | ||
return eat($0)(this.renderVoid(BREAK)); | ||
} | ||
@@ -1695,0 +1742,0 @@ |
@@ -14,3 +14,3 @@ 'use strict'; | ||
var WHITE_SPACE_FINAL = /\s+$/; | ||
var NEW_LINE_FINAL = /\n+$/; | ||
var NEW_LINES_FINAL = /\n+$/; | ||
var WHITE_SPACE_INITIAL = /^\s+/; | ||
@@ -156,3 +156,3 @@ var EXPRESSION_LINE_BREAKS = /\r\n|\r/g; | ||
function trimRightLines(value) { | ||
return String(value).replace(NEW_LINE_FINAL, ''); | ||
return String(value).replace(NEW_LINES_FINAL, ''); | ||
} | ||
@@ -159,0 +159,0 @@ |
{ | ||
"name": "mdast", | ||
"version": "0.17.1", | ||
"version": "0.18.0", | ||
"description": "Markdown processor powered by plugins", | ||
@@ -58,3 +58,3 @@ "license": "MIT", | ||
"mdast-github": "^0.2.0", | ||
"mdast-toc": "^0.2.0", | ||
"mdast-toc": "^0.3.0", | ||
"mdast-usage": "^0.2.0", | ||
@@ -61,0 +61,0 @@ "mdast-yaml-config": "^0.1.0", |
@@ -7,3 +7,3 @@ # ![mdast](https://cdn.rawgit.com/wooorm/mdast/master/logo.svg) | ||
**mdast** is not just another markdown to HTML compiler. It can generate, and reformat, markdown too. It’s powered by plugins to do all kinds of things: [change a Readme.md](https://github.com/wooorm/mdast-usage), [lint JavaScript in your markdown](https://github.com/wooorm/eslint-md), or [add a table of contents](https://github.com/wooorm/mdast-toc). | ||
**mdast** is not just another markdown to HTML compiler. It can generate, and reformat, markdown too. It’s powered by [plugins](doc/Plugins.md) to do all kinds of things: [change a Readme.md](https://github.com/wooorm/mdast-usage), [lint JavaScript in your markdown](https://github.com/wooorm/eslint-md), or [add a table of contents](https://github.com/wooorm/mdast-toc). | ||
@@ -10,0 +10,0 @@ ## Table of Contents |
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
209773
4511