Socket
Socket
Sign inDemoInstall

remark-parse

Package Overview
Dependencies
25
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.0 to 2.3.0

lib/util/html.js

7

index.js

@@ -11,17 +11,10 @@ /**

/* Dependencies. */
var unherit = require('unherit');
var Parser = require('./lib/parser.js');
/* Expose */
module.exports = exports = parse;
exports.Parser = Parser;
/**
* Attacher.
*
* @param {unified} processor - Unified processor.
*/
function parse(processor) {
processor.Parser = unherit(Parser);
}

72

lib/block-elements.json
[
"address",
"article",
"header",
"aside",
"hgroup",
"base",
"basefont",
"blockquote",
"hr",
"iframe",
"body",
"li",
"map",
"button",
"object",
"canvas",
"ol",
"caption",
"output",
"center",
"col",
"p",
"colgroup",
"pre",
"dd",
"progress",
"details",
"dialog",
"dir",
"div",
"section",
"dl",
"table",
"td",
"dt",
"tbody",
"embed",
"textarea",
"fieldset",
"tfoot",
"figcaption",
"th",
"figure",
"thead",
"footer",
"tr",
"form",
"ul",
"frame",
"frameset",
"h1",

@@ -49,5 +33,37 @@ "h2",

"h6",
"video",
"script",
"style"
"head",
"header",
"hgroup",
"hr",
"html",
"iframe",
"legend",
"li",
"link",
"main",
"menu",
"menuitem",
"meta",
"nav",
"noframes",
"ol",
"optgroup",
"option",
"p",
"param",
"pre",
"section",
"source",
"title",
"summary",
"table",
"tbody",
"td",
"tfoot",
"th",
"thead",
"title",
"tr",
"track",
"ul"
]

@@ -11,14 +11,7 @@ /**

/* Dependencies. */
var entities = require('parse-entities');
/* Expose. */
module.exports = factory;
/**
* Factory to create an entity decoder.
*
* @param {Object} ctx - Context to attach to.
* @return {Function} - See `decode`.
*/
/* Factory to create an entity decoder. */
function factory(ctx) {

@@ -29,8 +22,3 @@ decoder.raw = decodeRaw;

/**
* Normalize `position` to add an `indent`.
*
* @param {Position} position - Reference
* @return {Position} - Augmented with `indent`.
*/
/* Normalize `position` to add an `indent`. */
function normalize(position) {

@@ -55,10 +43,5 @@ var offsets = ctx.offset;

/**
* Handle a warning.
*
* @this {VFile} - Virtual file.
* @param {string} reason - Reason for warning.
* @param {Position} position - Place of warning.
* @param {number} code - Code for warning.
*/
/* Handle a warning.
* See https://github.com/wooorm/parse-entities
* for the warnings. */
function handleWarning(reason, position, code) {

@@ -72,9 +55,3 @@ if (code === 3) {

/**
* Decode `value` (at `position`) into text-nodes.
*
* @param {string} value - Value to parse.
* @param {Position} position - Position to start parsing at.
* @param {Function} handler - Node handler.
*/
/* Decode `value` (at `position`) into text-nodes. */
function decoder(value, position, handler) {

@@ -91,10 +68,3 @@ entities(value, {

/**
* Decode `value` (at `position`) into a string.
*
* @param {string} value - Value to parse.
* @param {Position} position - Position to start
* parsing at.
* @return {string} - Plain-text.
*/
/* Decode `value` (at `position`) into a string. */
function decodeRaw(value, position) {

@@ -101,0 +71,0 @@ return entities(value, {

@@ -11,12 +11,4 @@ /**

/* Expose. */
module.exports = locate;
/**
* Find a possible token.
*
* @param {string} value - Value to search.
* @param {number} fromIndex - Index to start searching at.
* @return {number} - Location.
*/
function locate(value, fromIndex) {

@@ -23,0 +15,0 @@ var index = value.indexOf('\n', fromIndex);

@@ -11,14 +11,6 @@ /**

/* Expose. */
module.exports = locate;
/**
* Find a possible token.
*
* @param {string} value - Value to search.
* @param {number} fromIndex - Index to start searching at.
* @return {number} - Location.
*/
function locate(value, fromIndex) {
return value.indexOf('`', fromIndex);
}

@@ -11,14 +11,6 @@ /**

/* Expose. */
module.exports = locate;
/**
* Find a possible token.
*
* @param {string} value - Value to search.
* @param {number} fromIndex - Index to start searching at.
* @return {number} - Location.
*/
function locate(value, fromIndex) {
return value.indexOf('~~', fromIndex);
}

@@ -11,12 +11,4 @@ /**

/* Expose. */
module.exports = locate;
/**
* Find a possible token.
*
* @param {string} value - Value to search.
* @param {number} fromIndex - Index to start searching at.
* @return {number} - Location.
*/
function locate(value, fromIndex) {

@@ -23,0 +15,0 @@ var asterisk = value.indexOf('*', fromIndex);

@@ -11,14 +11,6 @@ /**

/* Expose. */
module.exports = locate;
/**
* Find a possible token.
*
* @param {string} value - Value to search.
* @param {number} fromIndex - Index to start searching at.
* @return {number} - Location.
*/
function locate(value, fromIndex) {
return value.indexOf('\\', fromIndex);
}

@@ -11,12 +11,4 @@ /**

/* Expose. */
module.exports = locate;
/**
* Find a possible token.
*
* @param {string} value - Value to search.
* @param {number} fromIndex - Index to start searching at.
* @return {number} - Location.
*/
function locate(value, fromIndex) {

@@ -23,0 +15,0 @@ var link = value.indexOf('[', fromIndex);

@@ -11,12 +11,4 @@ /**

/* Expose. */
module.exports = locate;
/**
* Find a possible token.
*
* @param {string} value - Value to search.
* @param {number} fromIndex - Index to start searching at.
* @return {number} - Location.
*/
function locate(value, fromIndex) {

@@ -23,0 +15,0 @@ var asterisk = value.indexOf('**', fromIndex);

@@ -11,14 +11,6 @@ /**

/* Expose. */
module.exports = locate;
/**
* Find a possible token.
*
* @param {string} value - Value to search.
* @param {number} fromIndex - Index to start searching at.
* @return {number} - Location.
*/
function locate(value, fromIndex) {
return value.indexOf('<', fromIndex);
}

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

/* Expose. */
module.exports = locate;

@@ -17,9 +16,2 @@

/**
* Find a possible token.
*
* @param {string} value - Value to search.
* @param {number} fromIndex - Index to start searching at.
* @return {number} - Location.
*/
function locate(value, fromIndex) {

@@ -26,0 +18,0 @@ var length = PROTOCOLS.length;

@@ -11,24 +11,11 @@ /**

/* Dependencies. */
var xtend = require('xtend');
var removePosition = require('unist-util-remove-position');
/* Expose. */
module.exports = parse;
/* Characters. */
var C_NEWLINE = '\n';
/* Constants. */
var EXPRESSION_LINE_BREAKS = /\r\n|\r/g;
/**
* Parse the bound file.
*
* @example
* new Parser(new File('_Foo_.')).parse();
*
* @this {Parser}
* @return {Object} - `root` node.
*/
/* Parse the bound file. */
function parse() {

@@ -35,0 +22,0 @@ var self = this;

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

/* Dependencies. */
var xtend = require('xtend');

@@ -20,17 +19,5 @@ var toggle = require('state-toggle');

/* Expose `attacher`. */
module.exports = Parser;
/**
* Construct a new parser.
*
* @example
* var parser = new Parser(new VFile('Foo'));
*
* @constructor
* @class {Parser}
* @param {VFile} file - File to parse.
* @param {Object?} [options] - Passed to
* `Parser#setOptions()`.
*/
/* Construct a new parser. */
function Parser(file, options) {

@@ -66,2 +53,59 @@ this.file = file;

/* Nodes that can interupt a paragraph:
*
* ```markdown
* A paragraph, followed by a thematic break.
* ___
* ```
*
* In the above example, the thematic break “interupts”
* the paragraph. */
proto.interruptParagraph = [
['thematicBreak'],
['atxHeading'],
['fencedCode'],
['blockquote'],
['html'],
['setextHeading', {commonmark: false}],
['definition', {commonmark: false}],
['footnote', {commonmark: false}]
];
/* Nodes that can interupt a list:
*
* ```markdown
* - One
* ___
* ```
*
* In the above example, the thematic break “interupts”
* the list. */
proto.interruptList = [
['fencedCode', {pedantic: false}],
['thematicBreak', {pedantic: false}],
['definition', {commonmark: false}],
['footnote', {commonmark: false}]
];
/* Nodes that can interupt a blockquote:
*
* ```markdown
* > A paragraph.
* ___
* ```
*
* In the above example, the thematic break “interupts”
* the blockquote. */
proto.interruptBlockquote = [
['indentedCode', {commonmark: true}],
['fencedCode', {commonmark: true}],
['atxHeading', {commonmark: true}],
['setextHeading', {commonmark: true}],
['thematicBreak', {commonmark: true}],
['html', {commonmark: true}],
['list', {commonmark: true}],
['definition', {commonmark: false}],
['footnote', {commonmark: false}]
];
/* Handlers. */

@@ -109,5 +153,3 @@ proto.blockTokenizers = {

/**
* Get all keys in `value`.
*/
/* Get all keys in `value`. */
function keys(value) {

@@ -114,0 +156,0 @@ var result = [];

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

/* Dependencies. */
var xtend = require('xtend');

@@ -17,18 +16,5 @@ var escapes = require('markdown-escapes');

/* Expose `attacher`. */
module.exports = setOptions;
/**
* Set options. Does not overwrite previously set
* options.
*
* @example
* var parser = new Parser();
* parser.setOptions({gfm: true});
*
* @this {Parser}
* @throws {Error} - When an option is invalid.
* @param {Object?} [options] - Parse settings.
* @return {Parser} - `self`.
*/
/* Set options. */
function setOptions(options) {

@@ -35,0 +21,0 @@ var self = this;

@@ -11,7 +11,5 @@ /**

/* Dependencies. */
var decode = require('parse-entities');
var locate = require('../locate/tag');
/* Expose. */
module.exports = autoLink;

@@ -21,3 +19,2 @@ autoLink.locator = locate;

/* Constants. */
var C_LT = '<';

@@ -30,11 +27,3 @@ var C_GT = '>';

/**
* Tokenise a link.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `link` node.
*/
/* Tokenise a link. */
function autoLink(eat, value, silent) {

@@ -41,0 +30,0 @@ var self;

@@ -11,9 +11,7 @@ /**

/* Dependencies. */
var trim = require('trim');
var interrupt = require('../util/interrupt');
/* Expose. */
module.exports = blockquote;
/* Characters */
var C_NEWLINE = '\n';

@@ -24,15 +22,8 @@ var C_TAB = '\t';

/**
* Tokenise a blockquote.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `blockquote` node.
*/
/* Tokenise a blockquote. */
function blockquote(eat, value, silent) {
var self = this;
var commonmark = self.options.commonmark;
var offsets = self.offset;
var tokenizers = self.blockTokenizers;
var interruptors = self.interruptBlockquote;
var now = eat.now();

@@ -45,3 +36,2 @@ var currentLine = now.line;

var add;
var tokenizers;
var index = 0;

@@ -75,3 +65,2 @@ var character;

tokenizers = self.blockTokenizers;
index = 0;

@@ -119,23 +108,5 @@

if (
(
commonmark &&
(
tokenizers.indentedCode.call(self, eat, rest, true) ||
tokenizers.fencedCode.call(self, eat, rest, true) ||
tokenizers.atxHeading.call(self, eat, rest, true) ||
tokenizers.setextHeading.call(self, eat, rest, true) ||
tokenizers.thematicBreak.call(self, eat, rest, true) ||
tokenizers.html.call(self, eat, rest, true) ||
tokenizers.list.call(self, eat, rest, true)
)
) ||
(
!commonmark &&
(
tokenizers.definition.call(self, eat, rest, true) ||
tokenizers.footnote.call(self, eat, rest, true)
)
)
) {
/* Check if the following code contains a possible
* block. */
if (interrupt(interruptors, tokenizers, self, [eat, rest, true])) {
break;

@@ -142,0 +113,0 @@ }

@@ -11,21 +11,10 @@ /**

/* Dependencies. */
var locate = require('../locate/break');
/* Expose. */
module.exports = hardBreak;
hardBreak.locator = locate;
/* Constants. */
var MIN_BREAK_LENGTH = 2;
/**
* Tokenise a break.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `break` node.
*/
/* Tokenise a break. */
function hardBreak(eat, value, silent) {

@@ -32,0 +21,0 @@ var self = this;

@@ -11,9 +11,6 @@ /**

/* Dependencies. */
var trim = require('trim-trailing-lines');
/* Expose. */
module.exports = fencedCode;
/* Characters */
var C_NEWLINE = '\n';

@@ -25,15 +22,6 @@ var C_TAB = '\t';

/* Constants */
var MIN_FENCE_COUNT = 3;
var CODE_INDENT_COUNT = 4;
/**
* Tokenise fenced code.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `code` node.
*/
/* Tokenise fenced code. */
function fencedCode(eat, value, silent) {

@@ -40,0 +28,0 @@ var self = this;

@@ -11,10 +11,7 @@ /**

/* Dependencies. */
var repeat = require('repeat-string');
var trim = require('trim-trailing-lines');
/* Expose. */
module.exports = indentedCode;
/* Characters */
var C_NEWLINE = '\n';

@@ -24,15 +21,6 @@ var C_TAB = '\t';

/* Constants */
var CODE_INDENT_COUNT = 4;
var CODE_INDENT = repeat(C_SPACE, CODE_INDENT_COUNT);
/**
* Tokenise indented code.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `code` node.
*/
/* Tokenise indented code. */
function indentedCode(eat, value, silent) {

@@ -39,0 +27,0 @@ var index = -1;

@@ -11,22 +11,11 @@ /**

/* Dependencies. */
var whitespace = require('is-whitespace-character');
var locate = require('../locate/code-inline');
/* Expose. */
module.exports = inlineCode;
inlineCode.locator = locate;
/* Constants. */
var C_TICK = '`';
/**
* Tokenise inline code.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `inlineCode` node.
*/
/* Tokenise inline code. */
function inlineCode(eat, value, silent) {

@@ -33,0 +22,0 @@ var length = value.length;

@@ -11,7 +11,5 @@ /**

/* Dependencies. */
var whitespace = require('is-whitespace-character');
var normalize = require('../util/normalize');
/* Expose. */
module.exports = definition;

@@ -21,3 +19,2 @@ definition.notInList = true;

/* Characters */
var C_DOUBLE_QUOTE = '"';

@@ -37,10 +34,3 @@ var C_SINGLE_QUOTE = '\'';

/**
* Tokenise a definition.
*
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `definition` node.
*/
/* Tokenise a definition. */
function definition(eat, value, silent) {

@@ -286,11 +276,3 @@ var self = this;

/**
* Check whether `character` can be inside an enclosed
* URI.
*
* @property {string} delimiter - Closing delimiter.
* @param {string} character - Character to test.
* @return {boolean} - Whether `character` can be inside
* an enclosed URI.
*/
/* Check if `character` can be inside an enclosed URI. */
function isEnclosedURLCharacter(character) {

@@ -304,10 +286,3 @@ return character !== C_GT &&

/**
* Check whether `character` can be inside an unclosed
* URI.
*
* @param {string} character - Character to test.
* @return {boolean} - Whether `character` can be inside
* an unclosed URI.
*/
/* Check if `character` can be inside an unclosed URI. */
function isUnclosedURLCharacter(character) {

@@ -314,0 +289,0 @@ return character !== C_BRACKET_OPEN &&

@@ -11,23 +11,12 @@ /**

/* Dependencies. */
var whitespace = require('is-whitespace-character');
var locate = require('../locate/delete');
/* Expose. */
module.exports = strikethrough;
strikethrough.locator = locate;
/* Constants. */
var C_TILDE = '~';
var DOUBLE = '~~';
/**
* Tokenise strikethrough.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `delete` node.
*/
/* Tokenise strikethrough. */
function strikethrough(eat, value, silent) {

@@ -34,0 +23,0 @@ var self = this;

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

/* Dependencies. */
var trim = require('trim');

@@ -18,19 +17,9 @@ var word = require('is-word-character');

/* Expose. */
module.exports = emphasis;
emphasis.locator = locate;
/* Constants. */
var C_ASTERISK = '*';
var C_UNDERSCORE = '_';
/**
* Tokenise emphasis.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `emphasis` node.
*/
/* Tokenise emphasis. */
function emphasis(eat, value, silent) {

@@ -37,0 +26,0 @@ var self = this;

@@ -11,18 +11,8 @@ /**

/* Dependencies. */
var locate = require('../locate/escape');
/* Expose. */
module.exports = escape;
escape.locator = locate;
/**
* Tokenise an escape.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `text` or `break` node.
*/
/* Tokenise an escape. */
function escape(eat, value, silent) {

@@ -29,0 +19,0 @@ var self = this;

@@ -11,7 +11,5 @@ /**

/* Dependencies. */
var whitespace = require('is-whitespace-character');
var normalize = require('../util/normalize');
/* Expose. */
module.exports = footnoteDefinition;

@@ -21,3 +19,2 @@ footnoteDefinition.notInList = true;

/* Characters */
var C_BACKSLASH = '\\';

@@ -32,13 +29,5 @@ var C_NEWLINE = '\n';

/* Constants. */
var EXPRESSION_INITIAL_TAB = /^( {4}|\t)?/gm;
/**
* Tokenise a footnote definition.
*
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `footnoteDefinition` node.
*/
/* Tokenise a footnote definition. */
function footnoteDefinition(eat, value, silent) {

@@ -45,0 +34,0 @@ var self = this;

@@ -11,6 +11,4 @@ /**

/* Expose. */
module.exports = atxHeading;
/* Characters */
var C_NEWLINE = '\n';

@@ -21,14 +19,5 @@ var C_TAB = '\t';

/* Constants. */
var MAX_ATX_COUNT = 6;
/**
* Tokenise an ATX-style heading.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `heading` node.
*/
/* Tokenise an ATX-style heading. */
function atxHeading(eat, value, silent) {

@@ -35,0 +24,0 @@ var self = this;

@@ -11,6 +11,4 @@ /**

/* Expose. */
module.exports = setextHeading;
/* Characters */
var C_NEWLINE = '\n';

@@ -22,6 +20,5 @@ var C_TAB = '\t';

/* Constants. */
var MAX_HEADING_INDENT = 3;
/* A map of characters which can be used to mark setext
/* Map of characters which can be used to mark setext
* headers, mapping to their corresponding depth. */

@@ -33,11 +30,3 @@ var SETEXT_MARKERS = {};

/**
* Tokenise an setext-style heading.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `heading` node.
*/
/* Tokenise an setext-style heading. */
function setextHeading(eat, value, silent) {

@@ -44,0 +33,0 @@ var self = this;

@@ -11,39 +11,35 @@ /**

/* Dependencies. */
var cdata = require('../util/match-cdata');
var comment = require('../util/match-comment');
var declaration = require('../util/match-declaration');
var instruction = require('../util/match-instruction');
var closing = require('../util/match-tag-closing');
var opening = require('../util/match-tag-opening');
var openCloseTag = require('../util/html').openCloseTag;
/* Expose. */
module.exports = blockHTML;
/* Characters. */
var C_TAB = '\t';
var C_SPACE = ' ';
var C_NEWLINE = '\n';
var C_LT = '<';
/* Constants. */
var MIN_CLOSING_HTML_NEWLINE_COUNT = 2;
/**
* Tokenise block HTML.
*
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `html` node.
*/
/* Tokenise block HTML. */
function blockHTML(eat, value, silent) {
var self = this;
var blocks = self.options.blocks;
var length = value.length;
var index = 0;
var length = value.length;
var subvalue = '';
var next;
var line;
var offset;
var character;
var queue;
var count;
var sequence;
var subvalue;
var sequences = [
[/^<(script|pre|style)(?=(\s|>|$))/i, /<\/(script|pre|style)>/i, true],
[/^<!--/, /-->/, true],
[/^<\?/, /\?>/, true],
[/^<![A-Za-z]/, />/, true],
[/^<!\[CDATA\[/, /\]\]>/, true],
[new RegExp('^</?(' + blocks.join('|') + ')(?=(\\s|/?>|$))', 'i'), /^$/, true],
[new RegExp(openCloseTag.source + '\\s*$'), /^$/, false]
];
/* Eat initial spacing. */

@@ -57,18 +53,23 @@ while (index < length) {

subvalue += character;
index++;
}
offset = index;
value = value.slice(offset);
if (value.charAt(index) !== C_LT) {
return;
}
/* Try to eat an HTML thing. */
queue = comment(value, self.options) ||
cdata(value) ||
instruction(value) ||
declaration(value) ||
closing(value, blocks) ||
opening(value, blocks);
next = value.indexOf(C_NEWLINE, index + 1);
next = next === -1 ? length : next;
line = value.slice(index, next);
offset = -1;
count = sequences.length;
if (!queue) {
while (++offset < count) {
if (sequences[offset][0].test(line)) {
sequence = sequences[offset];
break;
}
}
if (!sequence) {
return;

@@ -78,28 +79,28 @@ }

if (silent) {
return true;
return sequence[2];
}
subvalue += queue;
index = subvalue.length - offset;
queue = '';
index = next;
while (index < length) {
character = value.charAt(index);
if (!sequence[1].test(line)) {
while (index < length) {
next = value.indexOf(C_NEWLINE, index + 1);
next = next === -1 ? length : next;
line = value.slice(index + 1, next);
if (character === C_NEWLINE) {
queue += character;
} else if (queue.length < MIN_CLOSING_HTML_NEWLINE_COUNT) {
subvalue += queue + character;
queue = '';
} else {
break;
if (sequence[1].test(line)) {
if (line) {
index = next;
}
break;
}
index = next;
}
index++;
}
return eat(subvalue)({
type: 'html',
value: subvalue
});
subvalue = value.slice(0, index);
return eat(subvalue)({type: 'html', value: subvalue});
}

@@ -11,37 +11,36 @@ /**

/* Dependencies. */
var alphabetical = require('is-alphabetical');
var locate = require('../locate/tag');
var cdata = require('../util/match-cdata');
var comment = require('../util/match-comment');
var declaration = require('../util/match-declaration');
var instruction = require('../util/match-instruction');
var closing = require('../util/match-tag-closing');
var opening = require('../util/match-tag-opening');
var tag = require('../util/html').tag;
/* Expose. */
module.exports = inlineHTML;
inlineHTML.locator = locate;
/* Constants. */
var EXPRESSION_HTML_LINK_OPEN = /^<a /i;
var EXPRESSION_HTML_LINK_CLOSE = /^<\/a>/i;
/**
* Tokenise inline HTML.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `html` node.
*/
/* Tokenise inline HTML. */
function inlineHTML(eat, value, silent) {
var self = this;
var subvalue = comment(value, self.options) ||
cdata(value) ||
instruction(value) ||
declaration(value) ||
closing(value) ||
opening(value);
var length = value.length;
var character;
var subvalue;
if (value.charAt(0) !== '<' || length < 3) {
return;
}
character = value.charAt(1);
if (
!alphabetical(character) &&
character !== '?' &&
character !== '!' &&
character !== '/'
) {
return;
}
subvalue = value.match(tag);
if (!subvalue) {

@@ -51,3 +50,3 @@ return;

/* istanbul ignore if - never used (yet) */
/* istanbul ignore if - not used yet. */
if (silent) {

@@ -57,2 +56,4 @@ return true;

subvalue = subvalue[0];
if (!self.inLink && EXPRESSION_HTML_LINK_OPEN.test(subvalue)) {

@@ -64,6 +65,3 @@ self.inLink = true;

return eat(subvalue)({
type: 'html',
value: subvalue
});
return eat(subvalue)({type: 'html', value: subvalue});
}

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

/* Dependencies. */
var has = require('has');

@@ -17,7 +16,5 @@ var whitespace = require('is-whitespace-character');

/* Expose. */
module.exports = link;
link.locator = locate;
/* Constants. */
var C_BACKSLASH = '\\';

@@ -34,3 +31,3 @@ var C_BRACKET_OPEN = '[';

/* A map of characters, which can be used to mark link
/* Map of characters, which can be used to mark link
* and image titles. */

@@ -42,3 +39,3 @@ var LINK_MARKERS = {};

/* A map of characters, which can be used to mark link
/* Map of characters, which can be used to mark link
* and image titles in commonmark-mode. */

@@ -51,11 +48,3 @@ var COMMONMARK_LINK_MARKERS = {};

/**
* Tokenise a link.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `link` node.
*/
/* Tokenise a link. */
function link(eat, value, silent) {

@@ -62,0 +51,0 @@ var self = this;

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

/* Dependencies. */
var trim = require('trim');

@@ -20,7 +19,6 @@ var repeat = require('repeat-string');

var removeIndent = require('../util/remove-indentation');
var interrupt = require('../util/interrupt');
/* Expose. */
module.exports = list;
/* Characters. */
var C_ASTERISK = '*';

@@ -37,6 +35,5 @@ var C_UNDERSCORE = '_';

/* Constants. */
var TAB_SIZE = 4;
var EXPRESSION_LOOSE_LIST_ITEM = /\n\n(?!\s*$)/;
var EXPRESSION_TASK_ITEM = /^\[([ \t]|x|X)\][ \t]/;
var EXPRESSION_TASK_ITEM = /^\[([ \t]|x|X)][ \t]/;
var EXPRESSION_BULLET = /^([ \t]*)([*+-]|\d+[.)])( {1,4}(?! )| |\t|$|(?=\n))([^\n]*)/;

@@ -46,3 +43,3 @@ var EXPRESSION_PEDANTIC_BULLET = /^([ \t]*)([*+-]|\d+[.)])([ \t]+)/;

/* A map of characters which can be used to mark
/* Map of characters which can be used to mark
* list-items. */

@@ -55,3 +52,3 @@ var LIST_UNORDERED_MARKERS = {};

/* A map of characters which can be used to mark
/* Map of characters which can be used to mark
* list-items after a digit. */

@@ -62,3 +59,3 @@ var LIST_ORDERED_MARKERS = {};

/* A map of characters which can be used to mark
/* Map of characters which can be used to mark
* list-items after a digit. */

@@ -70,11 +67,3 @@ var LIST_ORDERED_COMMONMARK_MARKERS = {};

/**
* Tokenise a list.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `list` node.
*/
/* Tokenise a list. */
function list(eat, value, silent) {

@@ -85,2 +74,3 @@ var self = this;

var tokenizers = self.blockTokenizers;
var interuptors = self.interruptList;
var markers;

@@ -277,3 +267,3 @@ var index = 0;

if (currentMarker) {
if (commonmark && marker !== currentMarker) {
if (!pedantic && marker !== currentMarker) {
break;

@@ -340,21 +330,6 @@ }

if (
!pedantic &&
(
tokenizers.fencedCode.call(self, eat, line, true) ||
tokenizers.thematicBreak.call(self, eat, line, true)
)
) {
if (interrupt(interuptors, tokenizers, self, [eat, line, true])) {
break;
}
if (!commonmark) {
if (
tokenizers.definition.call(self, eat, line, true) ||
tokenizers.footnote.call(self, eat, line, true)
) {
break;
}
}
item.value = item.value.concat(emptyLines, line);

@@ -449,13 +424,3 @@ allLines = allLines.concat(emptyLines, line);

/**
* Create a list-item using overly simple mechanics.
*
* @example
* renderPedanticListItem('- _foo_', now());
*
* @param {Object} ctx - Parser.
* @param {string} value - List-item.
* @param {Object} position - List-item location.
* @return {string} - Cleaned `value`.
*/
/* Create a list-item using overly simple mechanics. */
function pedanticListItem(ctx, value, position) {

@@ -465,16 +430,2 @@ var offsets = ctx.offset;

/**
* A simple replacer which removed all matches,
* and adds their length to `offset`.
*
* @param {string} $0 - Indentation to subtract.
* @return {string} - An empty string.
*/
function replacer($0) {
offsets[line] = (offsets[line] || 0) + $0.length;
line++;
return '';
}
/* Remove the list-item’s bullet. */

@@ -488,15 +439,14 @@ value = value.replace(EXPRESSION_PEDANTIC_BULLET, replacer);

return value.replace(EXPRESSION_INITIAL_INDENT, replacer);
/* A simple replacer which removed all matches,
* and adds their length to `offset`. */
function replacer($0) {
offsets[line] = (offsets[line] || 0) + $0.length;
line++;
return '';
}
}
/**
* Create a list-item using sane mechanics.
*
* @example
* renderNormalListItem('- _foo_', now());
*
* @param {Object} ctx - Parser.
* @param {string} value - List-item.
* @param {Object} position - List-item location.
* @return {string} - Cleaned `value`.
*/
/* Create a list-item using sane mechanics. */
function normalListItem(ctx, value, position) {

@@ -514,18 +464,4 @@ var offsets = ctx.offset;

/* Remove the list-item’s bullet. */
value = value.replace(EXPRESSION_BULLET, function ($0, $1, $2, $3, $4) {
bullet = $1 + $2 + $3;
rest = $4;
value = value.replace(EXPRESSION_BULLET, replacer);
/* Make sure that the first nine numbered list items
* can indent with an extra space. That is, when
* the bullet did not receive an extra final space. */
if (Number($2) < 10 && bullet.length % 2 === 1) {
$2 = C_SPACE + $2;
}
max = $1 + repeat(C_SPACE, $2.length) + $3;
return max + rest;
});
lines = value.split(C_NEWLINE);

@@ -556,2 +492,18 @@

return trimmedLines.join(C_NEWLINE);
function replacer($0, $1, $2, $3, $4) {
bullet = $1 + $2 + $3;
rest = $4;
/* Make sure that the first nine numbered list items
* can indent with an extra space. That is, when
* the bullet did not receive an extra final space. */
if (Number($2) < 10 && bullet.length % 2 === 1) {
$2 = C_SPACE + $2;
}
max = $1 + repeat(C_SPACE, $2.length) + $3;
return max + rest;
}
}

@@ -11,17 +11,7 @@ /**

/* Dependencies. */
var whitespace = require('is-whitespace-character');
/* Expose. */
module.exports = newline;
/**
* Tokenise newline.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {boolean?} - boolean in silent mode, nothing otherwise.
*/
/* Tokenise newline. */
function newline(eat, value, silent) {

@@ -28,0 +18,0 @@ var character = value.charAt(0);

@@ -11,11 +11,9 @@ /**

/* Dependencies. */
var trim = require('trim');
var decimal = require('is-decimal');
var trimTrailingLines = require('trim-trailing-lines');
var interrupt = require('../util/interrupt');
/* Expose. */
module.exports = paragraph;
/* Characters. */
var C_NEWLINE = '\n';

@@ -25,14 +23,5 @@ var C_TAB = '\t';

/* Constants. */
var TAB_SIZE = 4;
/**
* Tokenise paragraph.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {boolean?} - boolean in silent mode, nothing otherwise.
*/
/* Tokenise paragraph. */
function paragraph(eat, value, silent) {

@@ -44,2 +33,3 @@ var self = this;

var tokenizers = self.blockTokenizers;
var interruptors = self.interruptParagraph;
var index = value.indexOf(C_NEWLINE);

@@ -92,13 +82,7 @@ var length = value.length;

subvalue = value.slice(index + 1);
/* Check if the following code contains a possible
* block. */
subvalue = value.slice(index + 1);
if (
tokenizers.thematicBreak.call(self, eat, subvalue, true) ||
tokenizers.atxHeading.call(self, eat, subvalue, true) ||
tokenizers.fencedCode.call(self, eat, subvalue, true) ||
tokenizers.blockquote.call(self, eat, subvalue, true) ||
tokenizers.html.call(self, eat, subvalue, true)
) {
if (interrupt(interruptors, tokenizers, self, [eat, subvalue, true])) {
break;

@@ -121,13 +105,2 @@ }

if (
!commonmark &&
(
tokenizers.setextHeading.call(self, eat, subvalue, true) ||
tokenizers.definition.call(self, eat, subvalue, true) ||
tokenizers.footnote.call(self, eat, subvalue, true)
)
) {
break;
}
position = index;

@@ -134,0 +107,0 @@ index = value.indexOf(C_NEWLINE, index + 1);

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

/* Dependencies. */
var whitespace = require('is-whitespace-character');

@@ -17,7 +16,5 @@ var locate = require('../locate/link');

/* Expose. */
module.exports = reference;
reference.locator = locate;
/* Constants. */
var T_LINK = 'link';

@@ -34,12 +31,3 @@ var T_IMAGE = 'image';

/**
* Tokenise a reference.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `footnoteReference`,
* `linkReference`, or `imageReference` node.
*/
/* Tokenise a reference. */
function reference(eat, value, silent) {

@@ -46,0 +34,0 @@ var self = this;

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

/* Dependencies. */
var trim = require('trim');

@@ -17,19 +16,9 @@ var whitespace = require('is-whitespace-character');

/* Expose. */
module.exports = strong;
strong.locator = locate;
/* Constants. */
var C_ASTERISK = '*';
var C_UNDERSCORE = '_';
/**
* Tokenise strong.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `strong` node.
*/
/* Tokenise strong. */
function strong(eat, value, silent) {

@@ -36,0 +25,0 @@ var self = this;

@@ -11,10 +11,7 @@ /**

/* Dependencies. */
var whitespace = require('is-whitespace-character');
/* Expose. */
module.exports = table;
table.notInList = true;
/* Characters. */
var C_BACKSLASH = '\\';

@@ -29,7 +26,5 @@ var C_TICK = '`';

/* Constants. */
var MIN_TABLE_COLUMNS = 2;
var MIN_TABLE_ROWS = 2;
/* Available table alignments. */
var TABLE_ALIGN_LEFT = 'left';

@@ -40,11 +35,3 @@ var TABLE_ALIGN_CENTER = 'center';

/**
* Tokenise a table.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `table` node.
*/
/* Tokenise a table. */
function table(eat, value, silent) {

@@ -51,0 +38,0 @@ var self = this;

@@ -11,14 +11,5 @@ /**

/* Expose. */
module.exports = text;
/**
* Tokenise text.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `text` node.
*/
/* Tokenise text. */
function text(eat, value, silent) {

@@ -25,0 +16,0 @@ var self = this;

@@ -11,6 +11,4 @@ /**

/* Expose. */
module.exports = thematicBreak;
/* Characters */
var C_NEWLINE = '\n';

@@ -23,13 +21,5 @@ var C_TAB = '\t';

/* Constants. */
var THEMATIC_BREAK_MARKER_COUNT = 3;
/**
* Tokenise a thematic break.
*
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `thematicBreak` node.
*/
/* Tokenise a thematic break. */
function thematicBreak(eat, value, silent) {

@@ -36,0 +26,0 @@ var index = -1;

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

/* Dependencies. */
var decode = require('parse-entities');

@@ -17,3 +16,2 @@ var whitespace = require('is-whitespace-character');

/* Expose. */
module.exports = url;

@@ -23,3 +21,2 @@ url.locator = locate;

/* Constants. */
var C_BRACKET_OPEN = '[';

@@ -32,3 +29,2 @@ var C_BRACKET_CLOSE = ']';

/* Protocols. */
var HTTP_PROTOCOL = 'http://';

@@ -46,11 +42,3 @@ var HTTPS_PROTOCOL = 'https://';

/**
* Tokenise a link.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `link` node.
*/
/* Tokenise a URL. */
function url(eat, value, silent) {

@@ -57,0 +45,0 @@ var self = this;

@@ -11,7 +11,5 @@ /**

/* Expose. */
module.exports = yaml;
yaml.onlyAtStart = true;
/* Constants */
var FENCE = '---';

@@ -21,11 +19,3 @@ var C_DASH = '-';

/**
* Tokenise YAML.
*
* @property {Function} locator.
* @param {function(string)} eat - Eater.
* @param {string} value - Rest of content.
* @param {boolean?} [silent] - Whether this is a dry run.
* @return {Node?|boolean} - `yaml` node.
*/
/* Tokenise YAML. */
function yaml(eat, value, silent) {

@@ -32,0 +22,0 @@ var self = this;

@@ -11,14 +11,10 @@ /**

/* Expose. */
module.exports = factory;
/* Define nodes of a type which can be merged. */
var MERGEABLE_NODES = {};
var MERGEABLE_NODES = {
text: mergeText,
blockquote: mergeBlockquote
};
/**
* Check whether a node is mergeable with adjacent nodes.
*
* @param {Object} node - Node to check.
* @return {boolean} - Whether `node` is mergable.
*/
/* Check whether a node is mergeable with adjacent nodes. */
function mergeable(node) {

@@ -41,24 +37,12 @@ var start;

/**
* Merge two text nodes: `node` into `prev`.
*
* @param {Object} prev - Preceding sibling.
* @param {Object} node - Following sibling.
* @return {Object} - `prev`.
*/
MERGEABLE_NODES.text = function (prev, node) {
/* Merge two text nodes: `node` into `prev`. */
function mergeText(prev, node) {
prev.value += node.value;
return prev;
};
}
/**
* Merge two blockquotes: `node` into `prev`, unless in
* CommonMark mode.
*
* @param {Object} prev - Preceding sibling.
* @param {Object} node - Following sibling.
* @return {Object} - `prev`, or `node` in CommonMark mode.
*/
MERGEABLE_NODES.blockquote = function (prev, node) {
/* Merge two blockquotes: `node` into `prev`, unless in
* CommonMark mode. */
function mergeBlockquote(prev, node) {
if (this.options.commonmark) {

@@ -71,31 +55,10 @@ return node;

return prev;
};
}
/**
* Construct a tokenizer. This creates both
* `tokenizeInline` and `tokenizeBlock`.
*
* @example
* Parser.prototype.tokenizeInline = tokenizeFactory('inline');
*
* @param {string} type - Name of parser, used to find
* its expressions (`%sMethods`) and tokenizers
* (`%Tokenizers`).
* @return {Function} - Tokenizer.
*/
/* Construct a tokenizer. This creates both
* `tokenizeInline` and `tokenizeBlock`. */
function factory(type) {
return tokenize;
/**
* Tokenizer for a bound `type`
*
* @example
* parser = new Parser();
* parser.tokenizeInline('_foo_');
*
* @param {string} value - Content.
* @param {Object} location - Offset at which `value`
* starts.
* @return {Array.<Object>} - Nodes.
*/
/* Tokenizer for a bound `type`. */
function tokenize(value, location) {

@@ -102,0 +65,0 @@ var self = this;

@@ -14,31 +14,9 @@ /**

/**
* Factory to de-escape a value, based on a list at `key`
* in `ctx`.
*
* @example
* var ctx = {escape: ['a']}
* var unescape = unescapeFactory(ctx, 'escape');
*
* @param {Object} ctx - List of escapable characters.
* @param {string} key - Key in `map` at which the list
* exists.
* @return {function(string): string} - Function which
* takes a value and returns its unescaped version.
*/
/* Factory to de-escape a value, based on a list at `key`
* in `ctx`. */
function factory(ctx, key) {
return unescape;
/**
* De-escape a string using the expression at `key`
* in `ctx`.
*
* @example
* var ctx = {escape: ['a']}
* var unescape = unescapeFactory(ctx, 'escape');
* unescape('\a \b'); // 'a \b'
*
* @param {string} value - Escaped string.
* @return {string} - Unescaped string.
*/
/* De-escape a string using the expression at `key`
* in `ctx`. */
function unescape(value) {

@@ -45,0 +23,0 @@ var prev = 0;

@@ -14,3 +14,3 @@ /**

/* A map of characters, and their column length,
/* Map of characters, and their column length,
* which can be used as indentation. */

@@ -17,0 +17,0 @@ var characters = {' ': 1, '\t': 4};

{
"name": "remark-parse",
"version": "2.2.0",
"version": "2.3.0",
"description": "Markdown parser for remark",

@@ -46,3 +46,4 @@ "license": "MIT",

"xtend": "^4.0.1"
}
},
"xo": false
}

@@ -286,3 +286,3 @@ # remark-parse [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat]

definitions;
* `notInLink` (`boolean`)
* `notInList` (`boolean`)
— Whether nodes cannot be in lists.

@@ -289,0 +289,0 @@ * `notInLink` (`boolean`)

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc