New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
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 0.20.1 to 0.21.0

7

history.md

@@ -6,2 +6,9 @@ ---

0.21.0 / 2015-05-24
===================
* Add support for tokenizing into multiple tokens ([a1b7125](https://github.com/wooorm/mdast/commit/a1b7125))
* Add `indent` to `node.position` ([709777b](https://github.com/wooorm/mdast/commit/709777b))
* Fix missing parentheses ([84316a8](https://github.com/wooorm/mdast/commit/84316a8))
0.20.1 / 2015-05-20

@@ -8,0 +15,0 @@ ===================

250

lib/parse.js

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

var objectCreate = utilities.create;
var arrayPush = [].push;

@@ -199,3 +200,3 @@ /*

var INDENTATION_CHARACTERS = objectCreate;
var INDENTATION_CHARACTERS = objectCreate();

@@ -632,8 +633,5 @@ INDENTATION_CHARACTERS[SPACE] = SPACE.length;

function tokenizeHeading(eat, $0, $1, $2, $3, $4) {
var offset = this.offset;
var now = eat.now();
var line = now.line;
var prefix = $1 + $2 + ($3 || '');
offset[line] = (offset[line] || 0) + prefix.length;
now.column += ($1 + $2 + ($3 || '')).length;

@@ -690,6 +688,13 @@ return eat($0)(this.renderHeading($4, $2.length, now));

var now = eat.now();
var indent = this.indent(now.line);
var value = trimRightLines($0);
var add = eat(value);
$0 = trimRightLines($0);
value = value.replace(EXPRESSION_BLOCK_QUOTE, function (prefix) {
indent(prefix.length);
return eat($0)(this.renderBlockquote($0, now));
return '';
});
return add(this.renderBlockquote(value, now));
}

@@ -718,3 +723,2 @@

var bullet;
var add;
var item;

@@ -788,3 +792,3 @@ var enterTop;

add = eat(EMPTY);
node = eat($0).reset(self.renderList([], firstBullet));

@@ -794,4 +798,2 @@ enterTop = self.exitTop();

node = add(self.renderList([], firstBullet));
while (++index < length) {

@@ -814,4 +816,2 @@ item = matches[index];

node.position.end = eat.now();
enterTop();

@@ -922,8 +922,6 @@ exitBlockquote();

var now = eat.now();
var line = now.line;
var offset = self.offset;
var indent = self.indent(now.line);
$3 = $3.replace(EXPRESSION_INITIAL_TAB, function (value) {
offset[line] = (offset[line] || 0) + value.length;
line++;
indent(value.length);

@@ -970,3 +968,3 @@ return EMPTY;

node = eat(EMPTY)({
node = eat($0).reset({
'type': TABLE,

@@ -1030,3 +1028,3 @@ 'align': [],

function renderRow(type, value) {
var row = eat(EMPTY)(self.renderParent(type, []), node);
var row = eat(value).reset(self.renderParent(type, []), node);

@@ -1036,4 +1034,2 @@ value

.replace(EXPRESSION_TABLE_CONTENT, eatCellFactory(row));
row.position.end = eat.now();
}

@@ -1078,4 +1074,2 @@

node.position.end = eat.now();
return node;

@@ -1187,4 +1181,3 @@ }

var self = this;
var offset = self.offset;
var line = position.line;
var indent = self.indent(position.line);

@@ -1199,4 +1192,3 @@ /**

function replacer($0) {
offset[line] = (offset[line] || 0) + $0.length;
line++;
indent($0.length);

@@ -1213,7 +1205,7 @@ return EMPTY;

/*
* The initial line is also matched by the below, so
* The initial line was also matched by the below, so
* we reset the `line`.
*/
line = position.line;
indent = self.indent(position.line);

@@ -1235,4 +1227,3 @@ return value.replace(EXPRESSION_INITIAL_INDENT, replacer);

var self = this;
var offset = self.offset;
var line = position.line;
var indent = self.indent(position.line);
var bullet;

@@ -1286,4 +1277,3 @@ var rest;

offset[line] = (offset[line] || 0) + bullet.length;
line++;
indent(bullet.length);

@@ -1294,6 +1284,3 @@ index = 0;

while (++index < length) {
offset[line] = (offset[line] || 0) +
lines[index].length - trimmedLines[index].length;
line++;
indent(lines[index].length - trimmedLines[index].length);
}

@@ -1325,7 +1312,6 @@

var self = this;
var offsets = self.offset;
var checked = null;
var node;
var task;
var offset;
var indent;

@@ -1338,7 +1324,7 @@ value = LIST_ITEM_MAP[self.options.pedantic].apply(self, arguments);

if (task) {
indent = task[0].length;
checked = task[1].toLowerCase() === 'x';
offset = task[0].length;
offsets[position.line] += offset;
value = value.slice(offset);
self.indent(position.line)(indent);
value = value.slice(indent);
}

@@ -1397,3 +1383,3 @@ }

* @param {number} depth - Heading depth.
* @param {Object} position - Location of inline content.
* @param {Object} position - Heading content location.
* @return {Object} - `heading` node

@@ -1413,25 +1399,14 @@ */

* @example
* renderBlockquote('_foo_', now());
* renderBlockquote('_foo_', eat);
*
* @param {string} value - Content.
* @param {Object} position - Location of blockquote.
* @param {Object} now - Position.
* @return {Object} - `blockquote` node.
*/
function renderBlockquote(value, position) {
function renderBlockquote(value, now) {
var self = this;
var line = position.line;
var offset = self.offset;
var exitBlockquote = self.enterBlockquote();
var token;
value = value.replace(EXPRESSION_BLOCK_QUOTE, function ($0) {
offset[line] = (offset[line] || 0) + $0.length;
line++;
return EMPTY;
});
token = {
var token = {
'type': BLOCKQUOTE,
'children': this.tokenizeBlock(value, position)
'children': this.tokenizeBlock(value, now)
};

@@ -2007,2 +1982,33 @@

/**
* Factory to track indentation for each line corresponding
* to the given `start` and the number of invocations.
*
* @param {number} start - Starting line.
* @return {function(offset)} - Indenter.
*/
Parser.prototype.indent = function (start) {
var self = this;
var line = start;
/**
* Intender which increments the global offset,
* starting at the bound line, and further incrementing
* each line for each invocation.
*
* @example
* indenter(2)
*
* @param {number} offset - Number to increment the
* offset.
*/
function indenter(offset) {
self.offset[line] = (self.offset[line] || 0) + offset;
line++;
}
return indenter;
};
/**
* Parse `value` into an AST.

@@ -2135,7 +2141,11 @@ *

function updatePosition(subvalue) {
var lines = subvalue.match(/\n/g);
var lastIndex = subvalue.lastIndexOf(NEW_LINE);
var character = -1;
var subvalueLength = subvalue.length;
var lastIndex = -1;
if (lines) {
line += lines.length;
while (++character < subvalueLength) {
if (subvalue.charAt(character) === NEW_LINE) {
lastIndex = character;
line++;
}
}

@@ -2150,3 +2160,3 @@

if (line in offset) {
if (lines) {
if (lastIndex !== -1) {
column += offset[line];

@@ -2160,2 +2170,34 @@ } else if (column <= offset[line]) {

/**
* Get offset. Called before the fisrt character is
* eaten to retrieve the range's offsets.
*
* @return {Function} - `done`, to be called when
* the last character is eaten.
*/
function getOffset() {
var indentation = [];
var pos = line + 1;
/**
* Done. Called when the last character is
* eaten to retrieve the range's offsets.
*
* @return {Array.<number>} - Offset.
*/
function done() {
var last = line + 1;
while (pos < last) {
indentation.push((offset[pos] || 0) + 1);
pos++;
}
return indentation;
}
return done;
}
/**
* Get the current position.

@@ -2220,6 +2262,7 @@ *

*/
function update(node) {
function update(node, indent) {
start = node.position ? node.position.start : start;
node.position = new Position(start);
node.position.indent = indent;

@@ -2246,2 +2289,3 @@ return node;

add = function (token, parent) {
var isMultiple = 'length' in token;
var prev;

@@ -2256,22 +2300,28 @@ var children;

prev = children[children.length - 1];
if (isMultiple) {
arrayPush.apply(children, token);
} else {
if (type === INLINE && token.type === TEXT) {
token.value = decode(token.value, eat);
}
if (type === INLINE && token.type === TEXT) {
token.value = decode(token.value, eat);
}
prev = children[children.length - 1];
if (
prev &&
token.type === prev.type &&
token.type in MERGEABLE_NODES
) {
token = MERGEABLE_NODES[token.type].call(self, prev, token);
}
if (
prev &&
token.type === prev.type &&
token.type in MERGEABLE_NODES
) {
token = MERGEABLE_NODES[token.type].call(
self, prev, token
);
}
if (token !== prev) {
children.push(token);
}
if (!isMultiple && token !== prev) {
children.push(token);
}
if (self.atStart && tokens.length) {
self.exitStart();
if (self.atStart && tokens.length) {
self.exitStart();
}
}

@@ -2296,3 +2346,5 @@

eat = function (subvalue) {
var indent = getOffset();
var pos = position();
var current = now();

@@ -2311,2 +2363,4 @@ /* istanbul ignore if */

indent = indent();
/**

@@ -2319,5 +2373,30 @@ * Add the given arguments, add `position` to

function apply() {
return pos(add.apply(null, arguments));
return pos(add.apply(null, arguments), indent);
}
/**
* Functions just like apply, but resets the
* content: the line and column are reversed,
* and the eaten value is re-added.
*
* This is useful for nodes with a single
* type of content, such as lists and tables.
*
* See `apply` above for what parameters are
* expected.
*
* @return {Node}
*/
function reset() {
var node = apply.apply(null, arguments);
line = current.line;
column = current.column;
value = subvalue + value;
return node;
}
apply.reset = reset;
return apply;

@@ -2541,2 +2620,9 @@ };

/*
* Expose `tokenizeFactory` so dependencies could create
* their own tokenizers.
*/
Parser.prototype.tokenizeFactory = tokenizeFactory;
/*
* Expose `parse` on `module.exports`.

@@ -2543,0 +2629,0 @@ */

{
"name": "mdast",
"version": "0.20.1",
"version": "0.21.0",
"description": "Markdown processor powered by plugins",

@@ -5,0 +5,0 @@ "license": "MIT",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc