Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

commonmark

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commonmark - npm Package Compare versions

Comparing version 0.29.1 to 0.29.2

27

changelog.txt

@@ -0,1 +1,28 @@

[0.29.2]
* Use ES modules (Iddan Aaronsohn).
* Improve and simplify reference link normalization (#168).
We now use the built in `str.toLowerCase().toUpperCase()`, which
@rlidwka has shown does an accurate unicode case fold.
This allows us to remove a huge lookup table and should
both decrease the size of the library and speed things up.
* Fix end source position for nested or indented fenrced code blocks.
Improves on earlier fix to #141, which only worked for code blocks
flush with the left margin.
* Upgrade to entities 2.0+.
* Fix generation of dist files for dingus.
* Use esm for bin/commonmark, bench, test.
* Use rollup uglify plugin to create minified dist.
* Move dev dependencies to proper place in package.json.
* Use rollup instead of browserify (Iddan Aaronsohn).
* Reformat code with prettier (Iddan Aaronsohn).
* Replace travis CI with GitHub Actions CI.
* Bump versions of software to benchmark against.
* Change jgm/commonmark.js to commonmark/commonmark.js (#126).
* Security audit fixes.
* Remove obsolete spec2js.js script
* Remove test on node 9 and under. Only support actively maintained
versions.
* Run npm lint in ci.
[0.29.1]

@@ -2,0 +29,0 @@

510

lib/blocks.js
"use strict";
var Node = require('./node');
var unescapeString = require('./common').unescapeString;
var OPENTAG = require('./common').OPENTAG;
var CLOSETAG = require('./common').CLOSETAG;
import Node from "./node.js";
import { unescapeString, OPENTAG, CLOSETAG } from "./common.js";
import InlineParser from "./inlines.js";

@@ -17,22 +16,20 @@ var CODE_INDENT = 4;

var InlineParser = require('./inlines');
var reHtmlBlockOpen = [
/./, // dummy for 0
/^<(?:script|pre|style)(?:\s|>|$)/i,
/^<!--/,
/^<[?]/,
/^<![A-Z]/,
/^<!\[CDATA\[/,
/^<[/]?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[123456]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|[/]?[>]|$)/i,
new RegExp('^(?:' + OPENTAG + '|' + CLOSETAG + ')\\s*$', 'i')
/./, // dummy for 0
/^<(?:script|pre|textarea|style)(?:\s|>|$)/i,
/^<!--/,
/^<[?]/,
/^<![A-Z]/,
/^<!\[CDATA\[/,
/^<[/]?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[123456]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|[/]?[>]|$)/i,
new RegExp("^(?:" + OPENTAG + "|" + CLOSETAG + ")\\s*$", "i")
];
var reHtmlBlockClose = [
/./, // dummy for 0
/<\/(?:script|pre|style)>/i,
/-->/,
/\?>/,
/>/,
/\]\]>/
/./, // dummy for 0
/<\/(?:script|pre|textarea|style)>/i,
/-->/,
/\?>/,
/>/,
/\]\]>/
];

@@ -62,3 +59,3 @@

var isBlank = function(s) {
return !(reNonSpace.test(s));
return !reNonSpace.test(s);
};

@@ -90,4 +87,3 @@

var t = block.type;
if (!block._lastLineChecked &&
(t === 'list' || t === 'item')) {
if (!block._lastLineChecked && (t === "list" || t === "item")) {
block._lastLineChecked = true;

@@ -107,8 +103,8 @@ block = block._lastChild;

if (this.partiallyConsumedTab) {
this.offset += 1; // skip over tab
// add space characters:
var charsToTab = 4 - (this.column % 4);
this.tip._string_content += (' '.repeat(charsToTab));
this.offset += 1; // skip over tab
// add space characters:
var charsToTab = 4 - (this.column % 4);
this.tip._string_content += " ".repeat(charsToTab);
}
this.tip._string_content += this.currentLine.slice(this.offset) + '\n';
this.tip._string_content += this.currentLine.slice(this.offset) + "\n";
};

@@ -125,4 +121,7 @@

var column_number = offset + 1; // offset 0 = column 1
var newBlock = new Node(tag, [[this.lineNumber, column_number], [0, 0]]);
newBlock._string_content = '';
var newBlock = new Node(tag, [
[this.lineNumber, column_number],
[0, 0]
]);
newBlock._string_content = "";
this.tip.appendChild(newBlock);

@@ -141,9 +140,11 @@ this.tip = newBlock;

var spacesStartOffset;
var data = { type: null,
tight: true, // lists are tight by default
bulletChar: null,
start: null,
delimiter: null,
padding: null,
markerOffset: parser.indent };
var data = {
type: null,
tight: true, // lists are tight by default
bulletChar: null,
start: null,
delimiter: null,
padding: null,
markerOffset: parser.indent
};
if (parser.indent >= 4) {

@@ -153,9 +154,9 @@ return null;

if ((match = rest.match(reBulletListMarker))) {
data.type = 'bullet';
data.type = "bullet";
data.bulletChar = match[0][0];
} else if ((match = rest.match(reOrderedListMarker)) &&
(container.type !== 'paragraph' ||
match[1] === '1')) {
data.type = 'ordered';
} else if (
(match = rest.match(reOrderedListMarker)) &&
(container.type !== "paragraph" || match[1] === "1")
) {
data.type = "ordered";
data.start = parseInt(match[1]);

@@ -173,3 +174,8 @@ data.delimiter = match[2];

// if it interrupts paragraph, make sure first line isn't blank
if (container.type === 'paragraph' && !parser.currentLine.slice(parser.nextNonspace + match[0].length).match(reNonSpace)) {
if (
container.type === "paragraph" &&
!parser.currentLine
.slice(parser.nextNonspace + match[0].length)
.match(reNonSpace)
) {
return null;

@@ -186,9 +192,6 @@ }

nextc = peek(parser.currentLine, parser.offset);
} while (parser.column - spacesStartCol < 5 &&
isSpaceOrTab(nextc));
} while (parser.column - spacesStartCol < 5 && isSpaceOrTab(nextc));
var blank_item = peek(parser.currentLine, parser.offset) === -1;
var spaces_after_marker = parser.column - spacesStartCol;
if (spaces_after_marker >= 5 ||
spaces_after_marker < 1 ||
blank_item) {
if (spaces_after_marker >= 5 || spaces_after_marker < 1 || blank_item) {
data.padding = match[0].length + 1;

@@ -210,5 +213,7 @@ parser.column = spacesStartCol;

var listsMatch = function(list_data, item_data) {
return (list_data.type === item_data.type &&
list_data.delimiter === item_data.delimiter &&
list_data.bulletChar === item_data.bulletChar);
return (
list_data.type === item_data.type &&
list_data.delimiter === item_data.delimiter &&
list_data.bulletChar === item_data.bulletChar
);
};

@@ -236,9 +241,17 @@

document: {
continue: function() { return 0; },
finalize: function() { return; },
canContain: function(t) { return (t !== 'item'); },
continue: function() {
return 0;
},
finalize: function() {
return;
},
canContain: function(t) {
return t !== "item";
},
acceptsLines: false
},
list: {
continue: function() { return 0; },
continue: function() {
return 0;
},
finalize: function(parser, block) {

@@ -256,4 +269,6 @@ var item = block._firstChild;

while (subitem) {
if (endsWithBlankLine(subitem) &&
(item._next || subitem._next)) {
if (
endsWithBlankLine(subitem) &&
(item._next || subitem._next)
) {
block._listData.tight = false;

@@ -267,3 +282,5 @@ break;

},
canContain: function(t) { return (t === 'item'); },
canContain: function(t) {
return t === "item";
},
acceptsLines: false

@@ -274,4 +291,6 @@ },

var ln = parser.currentLine;
if (!parser.indented &&
peek(ln, parser.nextNonspace) === C_GREATERTHAN) {
if (
!parser.indented &&
peek(ln, parser.nextNonspace) === C_GREATERTHAN
) {
parser.advanceNextNonspace();

@@ -287,4 +306,8 @@ parser.advanceOffset(1, false);

},
finalize: function() { return; },
canContain: function(t) { return (t !== 'item'); },
finalize: function() {
return;
},
canContain: function(t) {
return t !== "item";
},
acceptsLines: false

@@ -301,7 +324,11 @@ },

}
} else if (parser.indent >=
container._listData.markerOffset +
container._listData.padding) {
parser.advanceOffset(container._listData.markerOffset +
container._listData.padding, true);
} else if (
parser.indent >=
container._listData.markerOffset + container._listData.padding
) {
parser.advanceOffset(
container._listData.markerOffset +
container._listData.padding,
true
);
} else {

@@ -312,4 +339,8 @@ return 1;

},
finalize: function() { return; },
canContain: function(t) { return (t !== 'item'); },
finalize: function() {
return;
},
canContain: function(t) {
return t !== "item";
},
acceptsLines: false

@@ -322,4 +353,8 @@ },

},
finalize: function() { return; },
canContain: function() { return false; },
finalize: function() {
return;
},
canContain: function() {
return false;
},
acceptsLines: false

@@ -332,4 +367,8 @@ },

},
finalize: function() { return; },
canContain: function() { return false; },
finalize: function() {
return;
},
canContain: function() {
return false;
},
acceptsLines: false

@@ -341,9 +380,12 @@ },

var indent = parser.indent;
if (container._isFenced) { // fenced
var match = (indent <= 3 &&
if (container._isFenced) {
// fenced
var match =
indent <= 3 &&
ln.charAt(parser.nextNonspace) === container._fenceChar &&
ln.slice(parser.nextNonspace).match(reClosingCodeFence));
ln.slice(parser.nextNonspace).match(reClosingCodeFence);
if (match && match[0].length >= container._fenceLength) {
// closing fence - we're at end of line, so we can return
parser.lastLineLength = match[0].length;
parser.lastLineLength =
parser.offset + indent + match[0].length;
parser.finalize(container, parser.lineNumber);

@@ -359,3 +401,4 @@ return 2;

}
} else { // indented
} else {
// indented
if (indent >= CODE_INDENT) {

@@ -372,6 +415,7 @@ parser.advanceOffset(CODE_INDENT, true);

finalize: function(parser, block) {
if (block._isFenced) { // fenced
if (block._isFenced) {
// fenced
// first line becomes info string
var content = block._string_content;
var newlinePos = content.indexOf('\n');
var newlinePos = content.indexOf("\n");
var firstLine = content.slice(0, newlinePos);

@@ -381,8 +425,14 @@ var rest = content.slice(newlinePos + 1);

block._literal = rest;
} else { // indented
block._literal = block._string_content.replace(/(\n *)+$/, '\n');
} else {
// indented
block._literal = block._string_content.replace(
/(\n *)+$/,
"\n"
);
}
block._string_content = null; // allow GC
},
canContain: function() { return false; },
canContain: function() {
return false;
},
acceptsLines: true

@@ -392,11 +442,15 @@ },

continue: function(parser, container) {
return ((parser.blank &&
(container._htmlBlockType === 6 ||
container._htmlBlockType === 7)) ? 1 : 0);
return parser.blank &&
(container._htmlBlockType === 6 ||
container._htmlBlockType === 7)
? 1
: 0;
},
finalize: function(parser, block) {
block._literal = block._string_content.replace(/(\n *)+$/, '');
block._literal = block._string_content.replace(/(\n *)+$/, "");
block._string_content = null; // allow GC
},
canContain: function() { return false; },
canContain: function() {
return false;
},
acceptsLines: true

@@ -406,3 +460,3 @@ },

continue: function(parser) {
return (parser.blank ? 1 : 0);
return parser.blank ? 1 : 0;
},

@@ -414,6 +468,9 @@ finalize: function(parser, block) {

// try parsing the beginning as link reference definitions:
while (peek(block._string_content, 0) === C_OPEN_BRACKET &&
(pos =
parser.inlineParser.parseReference(block._string_content,
parser.refmap))) {
while (
peek(block._string_content, 0) === C_OPEN_BRACKET &&
(pos = parser.inlineParser.parseReference(
block._string_content,
parser.refmap
))
) {
block._string_content = block._string_content.slice(pos);

@@ -426,3 +483,5 @@ hasReferenceDefs = true;

},
canContain: function() { return false; },
canContain: function() {
return false;
},
acceptsLines: true

@@ -439,4 +498,6 @@ }

function(parser) {
if (!parser.indented &&
peek(parser.currentLine, parser.nextNonspace) === C_GREATERTHAN) {
if (
!parser.indented &&
peek(parser.currentLine, parser.nextNonspace) === C_GREATERTHAN
) {
parser.advanceNextNonspace();

@@ -449,3 +510,3 @@ parser.advanceOffset(1, false);

parser.closeUnmatchedBlocks();
parser.addChild('block_quote', parser.nextNonspace);
parser.addChild("block_quote", parser.nextNonspace);
return 1;

@@ -460,12 +521,18 @@ } else {

var match;
if (!parser.indented &&
(match = parser.currentLine.slice(parser.nextNonspace).match(reATXHeadingMarker))) {
if (
!parser.indented &&
(match = parser.currentLine
.slice(parser.nextNonspace)
.match(reATXHeadingMarker))
) {
parser.advanceNextNonspace();
parser.advanceOffset(match[0].length, false);
parser.closeUnmatchedBlocks();
var container = parser.addChild('heading', parser.nextNonspace);
var container = parser.addChild("heading", parser.nextNonspace);
container.level = match[0].trim().length; // number of #s
// remove trailing ###s:
container._string_content =
parser.currentLine.slice(parser.offset).replace(/^[ \t]*#+[ \t]*$/, '').replace(/[ \t]+#+[ \t]*$/, '');
container._string_content = parser.currentLine
.slice(parser.offset)
.replace(/^[ \t]*#+[ \t]*$/, "")
.replace(/[ \t]+#+[ \t]*$/, "");
parser.advanceOffset(parser.currentLine.length - parser.offset);

@@ -481,7 +548,11 @@ return 2;

var match;
if (!parser.indented &&
(match = parser.currentLine.slice(parser.nextNonspace).match(reCodeFence))) {
if (
!parser.indented &&
(match = parser.currentLine
.slice(parser.nextNonspace)
.match(reCodeFence))
) {
var fenceLength = match[0].length;
parser.closeUnmatchedBlocks();
var container = parser.addChild('code_block', parser.nextNonspace);
var container = parser.addChild("code_block", parser.nextNonspace);
container._isFenced = true;

@@ -501,4 +572,6 @@ container._fenceLength = fenceLength;

function(parser, container) {
if (!parser.indented &&
peek(parser.currentLine, parser.nextNonspace) === C_LESSTHAN) {
if (
!parser.indented &&
peek(parser.currentLine, parser.nextNonspace) === C_LESSTHAN
) {
var s = parser.currentLine.slice(parser.nextNonspace);

@@ -508,10 +581,10 @@ var blockType;

for (blockType = 1; blockType <= 7; blockType++) {
if (reHtmlBlockOpen[blockType].test(s) &&
(blockType < 7 ||
container.type !== 'paragraph')) {
if (
reHtmlBlockOpen[blockType].test(s) &&
(blockType < 7 || container.type !== "paragraph")
) {
parser.closeUnmatchedBlocks();
// We don't adjust parser.offset;
// spaces are part of the HTML block:
var b = parser.addChild('html_block',
parser.offset);
var b = parser.addChild("html_block", parser.offset);
b._htmlBlockType = blockType;

@@ -524,3 +597,2 @@ return 2;

return 0;
},

@@ -531,26 +603,37 @@

var match;
if (!parser.indented &&
container.type === 'paragraph' &&
((match = parser.currentLine.slice(parser.nextNonspace).match(reSetextHeadingLine)))) {
if (
!parser.indented &&
container.type === "paragraph" &&
(match = parser.currentLine
.slice(parser.nextNonspace)
.match(reSetextHeadingLine))
) {
parser.closeUnmatchedBlocks();
// resolve reference link definitiosn
var pos;
while (peek(container._string_content, 0) === C_OPEN_BRACKET &&
(pos =
parser.inlineParser.parseReference(
container._string_content, parser.refmap))) {
container._string_content =
container._string_content.slice(pos);
while (
peek(container._string_content, 0) === C_OPEN_BRACKET &&
(pos = parser.inlineParser.parseReference(
container._string_content,
parser.refmap
))
) {
container._string_content = container._string_content.slice(
pos
);
}
if (container._string_content.length > 0) {
var heading = new Node('heading', container.sourcepos);
heading.level = match[0][0] === '=' ? 1 : 2;
heading._string_content = container._string_content;
container.insertAfter(heading);
container.unlink();
parser.tip = heading;
parser.advanceOffset(parser.currentLine.length - parser.offset, false);
return 2;
var heading = new Node("heading", container.sourcepos);
heading.level = match[0][0] === "=" ? 1 : 2;
heading._string_content = container._string_content;
container.insertAfter(heading);
container.unlink();
parser.tip = heading;
parser.advanceOffset(
parser.currentLine.length - parser.offset,
false
);
return 2;
} else {
return 0;
return 0;
}

@@ -564,7 +647,12 @@ } else {

function(parser) {
if (!parser.indented &&
reThematicBreak.test(parser.currentLine.slice(parser.nextNonspace))) {
if (
!parser.indented &&
reThematicBreak.test(parser.currentLine.slice(parser.nextNonspace))
) {
parser.closeUnmatchedBlocks();
parser.addChild('thematic_break', parser.nextNonspace);
parser.advanceOffset(parser.currentLine.length - parser.offset, false);
parser.addChild("thematic_break", parser.nextNonspace);
parser.advanceOffset(
parser.currentLine.length - parser.offset,
false
);
return 2;

@@ -580,10 +668,14 @@ } else {

if ((!parser.indented || container.type === 'list')
&& (data = parseListMarker(parser, container))) {
if (
(!parser.indented || container.type === "list") &&
(data = parseListMarker(parser, container))
) {
parser.closeUnmatchedBlocks();
// add the list if needed
if (parser.tip.type !== 'list' ||
!(listsMatch(container._listData, data))) {
container = parser.addChild('list', parser.nextNonspace);
if (
parser.tip.type !== "list" ||
!listsMatch(container._listData, data)
) {
container = parser.addChild("list", parser.nextNonspace);
container._listData = data;

@@ -593,3 +685,3 @@ }

// add the list item
container = parser.addChild('item', parser.nextNonspace);
container = parser.addChild("item", parser.nextNonspace);
container._listData = data;

@@ -604,9 +696,11 @@ return 1;

function(parser) {
if (parser.indented &&
parser.tip.type !== 'paragraph' &&
!parser.blank) {
if (
parser.indented &&
parser.tip.type !== "paragraph" &&
!parser.blank
) {
// indented code
parser.advanceOffset(CODE_INDENT, true);
parser.closeUnmatchedBlocks();
parser.addChild('code_block', parser.offset);
parser.addChild("code_block", parser.offset);
return 2;

@@ -616,4 +710,3 @@ } else {

}
}
}
];

@@ -626,3 +719,3 @@

while (count > 0 && (c = currentLine[this.offset])) {
if (c === '\t') {
if (c === "\t") {
charsToTab = 4 - (this.column % 4);

@@ -662,9 +755,9 @@ if (columns) {

while ((c = currentLine.charAt(i)) !== '') {
if (c === ' ') {
while ((c = currentLine.charAt(i)) !== "") {
if (c === " ") {
i++;
cols++;
} else if (c === '\t') {
} else if (c === "\t") {
i++;
cols += (4 - (cols % 4));
cols += 4 - (cols % 4);
} else {

@@ -674,3 +767,3 @@ break;

}
this.blank = (c === '\n' || c === '\r' || c === '');
this.blank = c === "\n" || c === "\r" || c === "";
this.nextNonspace = i;

@@ -698,4 +791,4 @@ this.nextNonspaceColumn = cols;

// replace NUL characters for security
if (ln.indexOf('\u0000') !== -1) {
ln = ln.replace(/\0/g, '\uFFFD');
if (ln.indexOf("\u0000") !== -1) {
ln = ln.replace(/\0/g, "\uFFFD");
}

@@ -715,11 +808,11 @@

switch (this.blocks[container.type].continue(this, container)) {
case 0: // we've matched, keep going
break;
case 1: // we've failed to match a block
all_matched = false;
break;
case 2: // we've hit end of line for fenced code close and can return
return;
default:
throw 'continue returned illegal value, must be 0, 1, or 2';
case 0: // we've matched, keep going
break;
case 1: // we've failed to match a block
all_matched = false;
break;
case 2: // we've hit end of line for fenced code close and can return
return;
default:
throw "continue returned illegal value, must be 0, 1, or 2";
}

@@ -732,7 +825,7 @@ if (!all_matched) {

this.allClosed = (container === this.oldtip);
this.allClosed = container === this.oldtip;
this.lastMatchedContainer = container;
var matchedLeaf = container.type !== 'paragraph' &&
blocks[container.type].acceptsLines;
var matchedLeaf =
container.type !== "paragraph" && blocks[container.type].acceptsLines;
var starts = this.blockStarts;

@@ -743,8 +836,9 @@ var startsLen = starts.length;

while (!matchedLeaf) {
this.findNextNonspace();
// this is a little performance optimization:
if (!this.indented &&
!reMaybeSpecial.test(ln.slice(this.nextNonspace))) {
if (
!this.indented &&
!reMaybeSpecial.test(ln.slice(this.nextNonspace))
) {
this.advanceNextNonspace();

@@ -769,3 +863,4 @@ break;

if (i === startsLen) { // nothing matched
if (i === startsLen) {
// nothing matched
this.advanceNextNonspace();

@@ -779,10 +874,9 @@ break;

// First check for a lazy paragraph continuation:
if (!this.allClosed && !this.blank &&
this.tip.type === 'paragraph') {
// First check for a lazy paragraph continuation:
if (!this.allClosed && !this.blank && this.tip.type === "paragraph") {
// lazy paragraph continuation
this.addLine();
} else {
// not a lazy continuation
} else { // not a lazy continuation
// finalize any blocks not matched

@@ -800,8 +894,11 @@ this.closeUnmatchedBlocks();

// on an empty list item, or if we just closed a fenced block.
var lastLineBlank = this.blank &&
!(t === 'block_quote' ||
(t === 'code_block' && container._isFenced) ||
(t === 'item' &&
!container._firstChild &&
container.sourcepos[0][0] === this.lineNumber));
var lastLineBlank =
this.blank &&
!(
t === "block_quote" ||
(t === "code_block" && container._isFenced) ||
(t === "item" &&
!container._firstChild &&
container.sourcepos[0][0] === this.lineNumber)
);

@@ -818,13 +915,16 @@ // propagate lastLineBlank up through parents:

// if HtmlBlock, check for end condition
if (t === 'html_block' &&
if (
t === "html_block" &&
container._htmlBlockType >= 1 &&
container._htmlBlockType <= 5 &&
reHtmlBlockClose[container._htmlBlockType].test(this.currentLine.slice(this.offset))) {
reHtmlBlockClose[container._htmlBlockType].test(
this.currentLine.slice(this.offset)
)
) {
this.lastLineLength = ln.length;
this.finalize(container, this.lineNumber);
}
} else if (this.offset < ln.length && !this.blank) {
// create paragraph container for line
container = this.addChild('paragraph', this.offset);
container = this.addChild("paragraph", this.offset);
this.advanceNextNonspace();

@@ -862,3 +962,3 @@ this.addLine();

t = node.type;
if (!event.entering && (t === 'paragraph' || t === 'heading')) {
if (!event.entering && (t === "paragraph" || t === "heading")) {
this.inlineParser.parse(node);

@@ -870,3 +970,6 @@ }

var Document = function() {
var doc = new Node('document', [[1, 1], [0, 0]]);
var doc = new Node("document", [
[1, 1],
[0, 0]
]);
return doc;

@@ -886,3 +989,5 @@ };

this.currentLine = "";
if (this.options.time) { console.time("preparing input"); }
if (this.options.time) {
console.time("preparing input");
}
var lines = input.split(reLineEnding);

@@ -894,4 +999,8 @@ var len = lines.length;

}
if (this.options.time) { console.timeEnd("preparing input"); }
if (this.options.time) { console.time("block parsing"); }
if (this.options.time) {
console.timeEnd("preparing input");
}
if (this.options.time) {
console.time("block parsing");
}
for (var i = 0; i < len; i++) {

@@ -903,12 +1012,17 @@ this.incorporateLine(lines[i]);

}
if (this.options.time) { console.timeEnd("block parsing"); }
if (this.options.time) { console.time("inline parsing"); }
if (this.options.time) {
console.timeEnd("block parsing");
}
if (this.options.time) {
console.time("inline parsing");
}
this.processInlines(this.doc);
if (this.options.time) { console.timeEnd("inline parsing"); }
if (this.options.time) {
console.timeEnd("inline parsing");
}
return this.doc;
};
// The Parser object.
function Parser(options){
function Parser(options) {
return {

@@ -949,2 +1063,2 @@ doc: new Document(),

module.exports = Parser;
export default Parser;
"use strict";
var encode = require('mdurl/encode');
import encode from "mdurl/encode.js";
import * as entities from "entities";
var C_BACKSLASH = 92;
var decodeHTML = require('entities').decodeHTML;
var ENTITY = "&(?:#x[a-f0-9]{1,6}|#[0-9]{1,7}|[a-z][a-z0-9]{1,31});";
var TAGNAME = '[A-Za-z][A-Za-z0-9-]*';
var ATTRIBUTENAME = '[a-zA-Z_:][a-zA-Z0-9:._-]*';
var TAGNAME = "[A-Za-z][A-Za-z0-9-]*";
var ATTRIBUTENAME = "[a-zA-Z_:][a-zA-Z0-9:._-]*";
var UNQUOTEDVALUE = "[^\"'=<>`\\x00-\\x20]+";
var SINGLEQUOTEDVALUE = "'[^']*'";
var DOUBLEQUOTEDVALUE = '"[^"]*"';
var ATTRIBUTEVALUE = "(?:" + UNQUOTEDVALUE + "|" + SINGLEQUOTEDVALUE + "|" + DOUBLEQUOTEDVALUE + ")";
var ATTRIBUTEVALUE =
"(?:" +
UNQUOTEDVALUE +
"|" +
SINGLEQUOTEDVALUE +
"|" +
DOUBLEQUOTEDVALUE +
")";
var ATTRIBUTEVALUESPEC = "(?:" + "\\s*=" + "\\s*" + ATTRIBUTEVALUE + ")";

@@ -25,15 +31,27 @@ var ATTRIBUTE = "(?:" + "\\s+" + ATTRIBUTENAME + ATTRIBUTEVALUESPEC + "?)";

var CDATA = "<!\\[CDATA\\[[\\s\\S]*?\\]\\]>";
var HTMLTAG = "(?:" + OPENTAG + "|" + CLOSETAG + "|" + HTMLCOMMENT + "|" +
PROCESSINGINSTRUCTION + "|" + DECLARATION + "|" + CDATA + ")";
var reHtmlTag = new RegExp('^' + HTMLTAG, 'i');
var HTMLTAG =
"(?:" +
OPENTAG +
"|" +
CLOSETAG +
"|" +
HTMLCOMMENT +
"|" +
PROCESSINGINSTRUCTION +
"|" +
DECLARATION +
"|" +
CDATA +
")";
var reHtmlTag = new RegExp("^" + HTMLTAG, "i");
var reBackslashOrAmp = /[\\&]/;
var ESCAPABLE = '[!"#$%&\'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]';
var ESCAPABLE = "[!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]";
var reEntityOrEscapedChar = new RegExp('\\\\' + ESCAPABLE + '|' + ENTITY, 'gi');
var reEntityOrEscapedChar = new RegExp("\\\\" + ESCAPABLE + "|" + ENTITY, "gi");
var XMLSPECIAL = '[&<>"]';
var reXmlSpecial = new RegExp(XMLSPECIAL, 'g');
var reXmlSpecial = new RegExp(XMLSPECIAL, "g");

@@ -44,3 +62,3 @@ var unescapeChar = function(s) {

} else {
return decodeHTML(s);
return entities.decodeHTML(s);
}

@@ -61,4 +79,3 @@ };

return encode(uri);
}
catch(err) {
} catch (err) {
return uri;

@@ -70,12 +87,12 @@ }

switch (s) {
case '&':
return '&amp;';
case '<':
return '&lt;';
case '>':
return '&gt;';
case '"':
return '&quot;';
default:
return s;
case "&":
return "&amp;";
case "<":
return "&lt;";
case ">":
return "&gt;";
case '"':
return "&quot;";
default:
return s;
}

@@ -92,10 +109,11 @@ };

module.exports = { unescapeString: unescapeString,
normalizeURI: normalizeURI,
escapeXml: escapeXml,
reHtmlTag: reHtmlTag,
OPENTAG: OPENTAG,
CLOSETAG: CLOSETAG,
ENTITY: ENTITY,
ESCAPABLE: ESCAPABLE
};
export {
unescapeString,
normalizeURI,
escapeXml,
reHtmlTag,
OPENTAG,
CLOSETAG,
ENTITY,
ESCAPABLE
};

@@ -5,4 +5,11 @@ "use strict";

/*! http://mths.be/fromcodepoint v0.2.1 by @mathias */
var _fromCodePoint;
export default function fromCodePoint(_) {
return _fromCodePoint(_);
}
if (String.fromCodePoint) {
module.exports = function (_) {
_fromCodePoint = function(_) {
try {

@@ -12,3 +19,3 @@ return String.fromCodePoint(_);

if (e instanceof RangeError) {
return String.fromCharCode(0xFFFD);
return String.fromCharCode(0xfffd);
}

@@ -18,45 +25,44 @@ throw e;

};
} else {
var stringFromCharCode = String.fromCharCode;
var floor = Math.floor;
var fromCodePoint = function() {
var MAX_SIZE = 0x4000;
var codeUnits = [];
var highSurrogate;
var lowSurrogate;
var index = -1;
var length = arguments.length;
if (!length) {
return '';
}
var result = '';
while (++index < length) {
var codePoint = Number(arguments[index]);
if (
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
codePoint < 0 || // not a valid Unicode code point
codePoint > 0x10FFFF || // not a valid Unicode code point
floor(codePoint) !== codePoint // not an integer
) {
return String.fromCharCode(0xFFFD);
}
if (codePoint <= 0xFFFF) { // BMP code point
codeUnits.push(codePoint);
} else { // Astral code point; split in surrogate halves
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
codePoint -= 0x10000;
highSurrogate = (codePoint >> 10) + 0xD800;
lowSurrogate = (codePoint % 0x400) + 0xDC00;
codeUnits.push(highSurrogate, lowSurrogate);
}
if (index + 1 === length || codeUnits.length > MAX_SIZE) {
result += stringFromCharCode.apply(null, codeUnits);
codeUnits.length = 0;
}
}
return result;
};
module.exports = fromCodePoint;
var stringFromCharCode = String.fromCharCode;
var floor = Math.floor;
_fromCodePoint = function() {
var MAX_SIZE = 0x4000;
var codeUnits = [];
var highSurrogate;
var lowSurrogate;
var index = -1;
var length = arguments.length;
if (!length) {
return "";
}
var result = "";
while (++index < length) {
var codePoint = Number(arguments[index]);
if (
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
codePoint < 0 || // not a valid Unicode code point
codePoint > 0x10ffff || // not a valid Unicode code point
floor(codePoint) !== codePoint // not an integer
) {
return String.fromCharCode(0xfffd);
}
if (codePoint <= 0xffff) {
// BMP code point
codeUnits.push(codePoint);
} else {
// Astral code point; split in surrogate halves
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
codePoint -= 0x10000;
highSurrogate = (codePoint >> 10) + 0xd800;
lowSurrogate = (codePoint % 0x400) + 0xdc00;
codeUnits.push(highSurrogate, lowSurrogate);
}
if (index + 1 === length || codeUnits.length > MAX_SIZE) {
result += stringFromCharCode.apply(null, codeUnits);
codeUnits.length = 0;
}
}
return result;
};
}

@@ -14,6 +14,6 @@ "use strict";

module.exports.Node = require('./node');
module.exports.Parser = require('./blocks');
module.exports.Renderer = require('./render/renderer');
module.exports.HtmlRenderer = require('./render/html');
module.exports.XmlRenderer = require('./render/xml');
export { default as Node } from "./node.js";
export { default as Parser } from "./blocks.js";
export { default as Renderer } from "./render/renderer.js";
export { default as HtmlRenderer } from "./render/html.js";
export { default as XmlRenderer } from "./render/xml.js";
"use strict";
var Node = require('./node');
var common = require('./common');
var normalizeReference = require('./normalize-reference');
import Node from "./node.js";
import * as common from "./common.js";
import fromCodePoint from "./from-code-point.js";
import * as entities from "entities";
import "string.prototype.repeat"; // Polyfill for String.prototype.repeat
var normalizeURI = common.normalizeURI;
var unescapeString = common.unescapeString;
var fromCodePoint = require('./from-code-point.js');
var decodeHTML = require('entities').decodeHTML;
require('string.prototype.repeat'); // Polyfill for String.prototype.repeat

@@ -34,3 +33,3 @@ // Constants for character codes:

var ESCAPABLE = common.ESCAPABLE;
var ESCAPED_CHAR = '\\\\' + ESCAPABLE;
var ESCAPED_CHAR = "\\\\" + ESCAPABLE;

@@ -40,16 +39,25 @@ var ENTITY = common.ENTITY;

var rePunctuation = new RegExp(/[!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E42\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC9\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDF3C-\uDF3E]|\uD809[\uDC70-\uDC74]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]/);
var rePunctuation = new RegExp(
/[!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E42\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC9\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDF3C-\uDF3E]|\uD809[\uDC70-\uDC74]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]/
);
var reLinkTitle = new RegExp(
'^(?:"(' + ESCAPED_CHAR + '|[^"\\x00])*"' +
'|' +
'\'(' + ESCAPED_CHAR + '|[^\'\\x00])*\'' +
'|' +
'\\((' + ESCAPED_CHAR + '|[^()\\x00])*\\))');
'^(?:"(' +
ESCAPED_CHAR +
'|[^"\\x00])*"' +
"|" +
"'(" +
ESCAPED_CHAR +
"|[^'\\x00])*'" +
"|" +
"\\((" +
ESCAPED_CHAR +
"|[^()\\x00])*\\))"
);
var reLinkDestinationBraces = /^(?:<(?:[^<>\n\\\x00]|\\.)*>)/;
var reEscapable = new RegExp('^' + ESCAPABLE);
var reEscapable = new RegExp("^" + ESCAPABLE);
var reEntityHere = new RegExp('^' + ENTITY, 'i');
var reEntityHere = new RegExp("^" + ENTITY, "i");

@@ -86,3 +94,3 @@ var reTicks = /`+/;

var text = function(s) {
var node = new Node('text');
var node = new Node("text");
node._literal = s;

@@ -92,2 +100,14 @@ return node;

// normalize a reference in reference link (remove []s, trim,
// collapse internal space, unicode case fold.
// See commonmark/commonmark.js#168.
var normalizeReference = function(string) {
return string
.slice(1, string.length - 1)
.trim()
.replace(/[ \t\r\n]+/, " ")
.toLowerCase()
.toUpperCase();
};
// INLINE PARSER

@@ -144,10 +164,12 @@

if (matched === ticks) {
node = new Node('code');
contents = this.subject.slice(afterOpenTicks,
this.pos - ticks.length)
.replace(/\n/gm, ' ');
if (contents.length > 0 &&
node = new Node("code");
contents = this.subject
.slice(afterOpenTicks, this.pos - ticks.length)
.replace(/\n/gm, " ");
if (
contents.length > 0 &&
contents.match(/[^ ]/) !== null &&
contents[0] == ' ' &&
contents[contents.length - 1] == ' ') {
contents[0] == " " &&
contents[contents.length - 1] == " "
) {
node._literal = contents.slice(1, contents.length - 1);

@@ -177,3 +199,3 @@ } else {

this.pos += 1;
node = new Node('linebreak');
node = new Node("linebreak");
block.appendChild(node);

@@ -184,3 +206,3 @@ } else if (reEscapable.test(subj.charAt(this.pos))) {

} else {
block.appendChild(text('\\'));
block.appendChild(text("\\"));
}

@@ -197,5 +219,5 @@ return true;

dest = m.slice(1, m.length - 1);
node = new Node('link');
node._destination = normalizeURI('mailto:' + dest);
node._title = '';
node = new Node("link");
node._destination = normalizeURI("mailto:" + dest);
node._title = "";
node.appendChild(text(dest));

@@ -206,5 +228,5 @@ block.appendChild(node);

dest = m.slice(1, m.length - 1);
node = new Node('link');
node = new Node("link");
node._destination = normalizeURI(dest);
node._title = '';
node._title = "";
node.appendChild(text(dest));

@@ -224,3 +246,3 @@ block.appendChild(node);

} else {
var node = new Node('html_inline');
var node = new Node("html_inline");
node._literal = m;

@@ -241,3 +263,6 @@ block.appendChild(node);

var left_flanking, right_flanking, can_open, can_close;
var after_is_whitespace, after_is_punctuation, before_is_whitespace, before_is_punctuation;
var after_is_whitespace,
after_is_punctuation,
before_is_whitespace,
before_is_punctuation;

@@ -258,7 +283,7 @@ if (cc === C_SINGLEQUOTE || cc === C_DOUBLEQUOTE) {

char_before = startpos === 0 ? '\n' : this.subject.charAt(startpos - 1);
char_before = startpos === 0 ? "\n" : this.subject.charAt(startpos - 1);
cc_after = this.peek();
if (cc_after === -1) {
char_after = '\n';
char_after = "\n";
} else {

@@ -273,11 +298,13 @@ char_after = fromCodePoint(cc_after);

left_flanking = !after_is_whitespace &&
(!after_is_punctuation || before_is_whitespace || before_is_punctuation);
right_flanking = !before_is_whitespace &&
(!before_is_punctuation || after_is_whitespace || after_is_punctuation);
left_flanking =
!after_is_whitespace &&
(!after_is_punctuation ||
before_is_whitespace ||
before_is_punctuation);
right_flanking =
!before_is_whitespace &&
(!before_is_punctuation || after_is_whitespace || after_is_punctuation);
if (cc === C_UNDERSCORE) {
can_open = left_flanking &&
(!right_flanking || before_is_punctuation);
can_close = right_flanking &&
(!left_flanking || after_is_punctuation);
can_open = left_flanking && (!right_flanking || before_is_punctuation);
can_close = right_flanking && (!left_flanking || after_is_punctuation);
} else if (cc === C_SINGLEQUOTE || cc === C_DOUBLEQUOTE) {

@@ -291,5 +318,3 @@ can_open = left_flanking && !right_flanking;

this.pos = startpos;
return { numdelims: numdelims,
can_open: can_open,
can_close: can_close };
return { numdelims: numdelims, can_open: can_open, can_close: can_close };
};

@@ -319,19 +344,22 @@

// Add entry to stack for this opener
if ((res.can_open || res.can_close) &&
(this.options.smart || cc !== C_SINGLEQUOTE || cc !== C_DOUBLEQUOTE)){
this.delimiters = { cc: cc,
numdelims: numdelims,
origdelims: numdelims,
node: node,
previous: this.delimiters,
next: null,
can_open: res.can_open,
can_close: res.can_close };
if (this.delimiters.previous !== null) {
this.delimiters.previous.next = this.delimiters;
}
if (
(res.can_open || res.can_close) &&
(this.options.smart || (cc !== C_SINGLEQUOTE && cc !== C_DOUBLEQUOTE))
) {
this.delimiters = {
cc: cc,
numdelims: numdelims,
origdelims: numdelims,
node: node,
previous: this.delimiters,
next: null,
can_open: res.can_open,
can_close: res.can_close
};
if (this.delimiters.previous !== null) {
this.delimiters.previous.next = this.delimiters;
}
}
return true;
};

@@ -365,6 +393,6 @@

var opener_found;
var openers_bottom = [[],[],[]];
var openers_bottom = [[], [], []];
var odd_match = false;
for (var i=0; i < 3; i++) {
for (var i = 0; i < 3; i++) {
openers_bottom[i][C_UNDERSCORE] = stack_bottom;

@@ -389,7 +417,11 @@ openers_bottom[i][C_ASTERISK] = stack_bottom;

opener_found = false;
while (opener !== null && opener !== stack_bottom &&
opener !== openers_bottom[closer.origdelims % 3][closercc]) {
odd_match = (closer.can_open || opener.can_close) &&
closer.origdelims % 3 !== 0 &&
(opener.origdelims + closer.origdelims) % 3 === 0;
while (
opener !== null &&
opener !== stack_bottom &&
opener !== openers_bottom[closer.origdelims % 3][closercc]
) {
odd_match =
(closer.can_open || opener.can_close) &&
closer.origdelims % 3 !== 0 &&
(opener.origdelims + closer.origdelims) % 3 === 0;
if (opener.cc === closer.cc && opener.can_open && !odd_match) {

@@ -409,3 +441,3 @@ opener_found = true;

use_delims =
(closer.numdelims >= 2 && opener.numdelims >= 2) ? 2 : 1;
closer.numdelims >= 2 && opener.numdelims >= 2 ? 2 : 1;

@@ -418,11 +450,13 @@ opener_inl = opener.node;

closer.numdelims -= use_delims;
opener_inl._literal =
opener_inl._literal.slice(0,
opener_inl._literal.length - use_delims);
closer_inl._literal =
closer_inl._literal.slice(0,
closer_inl._literal.length - use_delims);
opener_inl._literal = opener_inl._literal.slice(
0,
opener_inl._literal.length - use_delims
);
closer_inl._literal = closer_inl._literal.slice(
0,
closer_inl._literal.length - use_delims
);
// build contents for new emph element
var emph = new Node(use_delims === 1 ? 'emph' : 'strong');
var emph = new Node(use_delims === 1 ? "emph" : "strong");

@@ -454,5 +488,3 @@ tmp = opener_inl._next;

}
}
} else if (closercc === C_SINGLEQUOTE) {

@@ -464,3 +496,2 @@ closer.node._literal = "\u2019";

closer = closer.next;
} else if (closercc === C_DOUBLEQUOTE) {

@@ -472,7 +503,7 @@ closer.node._literal = "\u201D";

closer = closer.next;
}
if (!opener_found) {
// Set lower bound for future searches for openers:
openers_bottom[old_closer.origdelims % 3][closercc] = old_closer.previous;
openers_bottom[old_closer.origdelims % 3][closercc] =
old_closer.previous;
if (!old_closer.can_open) {

@@ -485,3 +516,2 @@ // We can remove a closer that can't be an opener,

}
}

@@ -520,4 +550,6 @@

while ((c = this.peek()) !== -1) {
if (c === C_BACKSLASH
&& reEscapable.test(this.subject.charAt(this.pos + 1))) {
if (
c === C_BACKSLASH &&
reEscapable.test(this.subject.charAt(this.pos + 1))
) {
this.pos += 1;

@@ -544,10 +576,11 @@ if (this.peek() !== -1) {

if (this.pos === savepos && c !== C_CLOSE_PAREN) {
return null;
return null;
}
if (openparens !== 0) {
return null;
return null;
}
res = this.subject.substr(savepos, this.pos - savepos);
return normalizeURI(unescapeString(res));
} else { // chop off surrounding <..>:
} else {
// chop off surrounding <..>:
return normalizeURI(unescapeString(res.substr(1, res.length - 2)));

@@ -572,3 +605,3 @@ }

var node = text('[');
var node = text("[");
block.appendChild(node);

@@ -589,3 +622,3 @@

var node = text('![');
var node = text("![");
block.appendChild(node);

@@ -596,3 +629,3 @@

} else {
block.appendChild(text('!'));
block.appendChild(text("!"));
}

@@ -623,3 +656,3 @@ return true;

// no matched opener, just return a literal
block.appendChild(text(']'));
block.appendChild(text("]"));
return true;

@@ -630,3 +663,3 @@ }

// no matched opener, just return a literal
block.appendChild(text(']'));
block.appendChild(text("]"));
// take opener off brackets stack

@@ -647,10 +680,13 @@ this.removeBracket();

this.pos++;
if (this.spnl() &&
((dest = this.parseLinkDestination()) !== null) &&
if (
this.spnl() &&
(dest = this.parseLinkDestination()) !== null &&
this.spnl() &&
// make sure there's a space before the title:
(reWhitespaceChar.test(this.subject.charAt(this.pos - 1)) &&
(title = this.parseLinkTitle()) || true) &&
((reWhitespaceChar.test(this.subject.charAt(this.pos - 1)) &&
(title = this.parseLinkTitle())) ||
true) &&
this.spnl() &&
this.peek() === C_CLOSE_PAREN) {
this.peek() === C_CLOSE_PAREN
) {
this.pos += 1;

@@ -664,3 +700,2 @@ matched = true;

if (!matched) {
// Next, see if there's a link label

@@ -693,5 +728,5 @@ var beforelabel = this.pos;

if (matched) {
var node = new Node(is_image ? 'image' : 'link');
var node = new Node(is_image ? "image" : "link");
node._destination = dest;
node._title = title || '';
node._title = title || "";

@@ -715,21 +750,20 @@ var tmp, next;

if (!is_image) {
opener = this.brackets;
while (opener !== null) {
if (!opener.image) {
opener.active = false; // deactivate this opener
opener = this.brackets;
while (opener !== null) {
if (!opener.image) {
opener.active = false; // deactivate this opener
}
opener = opener.previous;
}
opener = opener.previous;
}
}
return true;
} else {
// no match
} else { // no match
this.removeBracket(); // remove this opener from stack
this.removeBracket(); // remove this opener from stack
this.pos = startpos;
block.appendChild(text(']'));
block.appendChild(text("]"));
return true;
}
};

@@ -741,8 +775,10 @@

}
this.brackets = { node: node,
previous: this.brackets,
previousDelimiter: this.delimiters,
index: index,
image: image,
active: true };
this.brackets = {
node: node,
previous: this.brackets,
previousDelimiter: this.delimiters,
index: index,
image: image,
active: true
};
};

@@ -758,3 +794,3 @@

if ((m = this.match(reEntityHere))) {
block.appendChild(text(decodeHTML(m)));
block.appendChild(text(entities.decodeHTML(m)));
return true;

@@ -772,20 +808,31 @@ } else {

if (this.options.smart) {
block.appendChild(text(
m.replace(reEllipses, "\u2026")
.replace(reDash, function(chars) {
var enCount = 0;
var emCount = 0;
if (chars.length % 3 === 0) { // If divisible by 3, use all em dashes
emCount = chars.length / 3;
} else if (chars.length % 2 === 0) { // If divisible by 2, use all en dashes
enCount = chars.length / 2;
} else if (chars.length % 3 === 2) { // If 2 extra dashes, use en dash for last 2; em dashes for rest
enCount = 1;
emCount = (chars.length - 2) / 3;
} else { // Use en dashes for last 4 hyphens; em dashes for rest
enCount = 2;
emCount = (chars.length - 4) / 3;
}
return "\u2014".repeat(emCount) + "\u2013".repeat(enCount);
})));
block.appendChild(
text(
m
.replace(reEllipses, "\u2026")
.replace(reDash, function(chars) {
var enCount = 0;
var emCount = 0;
if (chars.length % 3 === 0) {
// If divisible by 3, use all em dashes
emCount = chars.length / 3;
} else if (chars.length % 2 === 0) {
// If divisible by 2, use all en dashes
enCount = chars.length / 2;
} else if (chars.length % 3 === 2) {
// If 2 extra dashes, use en dash for last 2; em dashes for rest
enCount = 1;
emCount = (chars.length - 2) / 3;
} else {
// Use en dashes for last 4 hyphens; em dashes for rest
enCount = 2;
emCount = (chars.length - 4) / 3;
}
return (
"\u2014".repeat(emCount) +
"\u2013".repeat(enCount)
);
})
)
);
} else {

@@ -806,8 +853,12 @@ block.appendChild(text(m));

var lastc = block._lastChild;
if (lastc && lastc.type === 'text' && lastc._literal[lastc._literal.length - 1] === ' ') {
var hardbreak = lastc._literal[lastc._literal.length - 2] === ' ';
lastc._literal = lastc._literal.replace(reFinalSpace, '');
block.appendChild(new Node(hardbreak ? 'linebreak' : 'softbreak'));
if (
lastc &&
lastc.type === "text" &&
lastc._literal[lastc._literal.length - 1] === " "
) {
var hardbreak = lastc._literal[lastc._literal.length - 2] === " ";
lastc._literal = lastc._literal.replace(reFinalSpace, "");
block.appendChild(new Node(hardbreak ? "linebreak" : "softbreak"));
} else {
block.appendChild(new Node('softbreak'));
block.appendChild(new Node("softbreak"));
}

@@ -859,3 +910,3 @@ this.match(reInitialSpace); // gobble leading spaces in next line

if (title === null) {
title = '';
title = "";
// rewind before spaces

@@ -868,3 +919,3 @@ this.pos = beforetitle;

if (this.match(reSpaceAtEndOfLine) === null) {
if (title === '') {
if (title === "") {
atLineEnd = false;

@@ -875,3 +926,3 @@ } else {

// discard the title
title = '';
title = "";
// rewind before spaces

@@ -890,3 +941,3 @@ this.pos = beforetitle;

var normlabel = normalizeReference(rawlabel);
if (normlabel === '') {
if (normlabel === "") {
// label must contain non-whitespace characters

@@ -912,38 +963,38 @@ this.pos = startpos;

}
switch(c) {
case C_NEWLINE:
res = this.parseNewline(block);
break;
case C_BACKSLASH:
res = this.parseBackslash(block);
break;
case C_BACKTICK:
res = this.parseBackticks(block);
break;
case C_ASTERISK:
case C_UNDERSCORE:
res = this.handleDelim(c, block);
break;
case C_SINGLEQUOTE:
case C_DOUBLEQUOTE:
res = this.options.smart && this.handleDelim(c, block);
break;
case C_OPEN_BRACKET:
res = this.parseOpenBracket(block);
break;
case C_BANG:
res = this.parseBang(block);
break;
case C_CLOSE_BRACKET:
res = this.parseCloseBracket(block);
break;
case C_LESSTHAN:
res = this.parseAutolink(block) || this.parseHtmlTag(block);
break;
case C_AMPERSAND:
res = this.parseEntity(block);
break;
default:
res = this.parseString(block);
break;
switch (c) {
case C_NEWLINE:
res = this.parseNewline(block);
break;
case C_BACKSLASH:
res = this.parseBackslash(block);
break;
case C_BACKTICK:
res = this.parseBackticks(block);
break;
case C_ASTERISK:
case C_UNDERSCORE:
res = this.handleDelim(c, block);
break;
case C_SINGLEQUOTE:
case C_DOUBLEQUOTE:
res = this.options.smart && this.handleDelim(c, block);
break;
case C_OPEN_BRACKET:
res = this.parseOpenBracket(block);
break;
case C_BANG:
res = this.parseBang(block);
break;
case C_CLOSE_BRACKET:
res = this.parseCloseBracket(block);
break;
case C_LESSTHAN:
res = this.parseAutolink(block) || this.parseHtmlTag(block);
break;
case C_AMPERSAND:
res = this.parseEntity(block);
break;
default:
res = this.parseString(block);
break;
}

@@ -965,4 +1016,3 @@ if (!res) {

this.brackets = null;
while (this.parseInline(block)) {
}
while (this.parseInline(block)) {}
block._string_content = null; // allow raw string to be garbage collected

@@ -973,6 +1023,6 @@ this.processEmphasis(null);

// The InlineParser object.
function InlineParser(options){
function InlineParser(options) {
return {
subject: '',
delimiters: null, // used by handleDelim method
subject: "",
delimiters: null, // used by handleDelim method
brackets: null,

@@ -1010,2 +1060,2 @@ pos: 0,

module.exports = InlineParser;
export default InlineParser;

@@ -5,17 +5,17 @@ "use strict";

switch (node._type) {
case 'document':
case 'block_quote':
case 'list':
case 'item':
case 'paragraph':
case 'heading':
case 'emph':
case 'strong':
case 'link':
case 'image':
case 'custom_inline':
case 'custom_block':
return true;
default:
return false;
case "document":
case "block_quote":
case "list":
case "item":
case "paragraph":
case "heading":
case "emph":
case "strong":
case "link":
case "image":
case "custom_inline":
case "custom_block":
return true;
default:
return false;
}

@@ -26,6 +26,6 @@ }

this.current = node;
this.entering = (entering === true);
this.entering = entering === true;
};
var next = function(){
var next = function() {
var cur = this.current;

@@ -48,10 +48,7 @@ var entering = this.entering;

}
} else if (cur === this.root) {
this.current = null;
} else if (cur._next === null) {
this.current = cur._parent;
this.entering = false;
} else {

@@ -62,11 +59,13 @@ this.current = cur._next;

return {entering: entering, node: cur};
return { entering: entering, node: cur };
};
var NodeWalker = function(root) {
return { current: root,
root: root,
entering: true,
next: next,
resumeAt: resumeAt };
return {
current: root,
root: root,
entering: true,
next: next,
resumeAt: resumeAt
};
};

@@ -102,87 +101,147 @@

Object.defineProperty(proto, 'isContainer', {
get: function () { return isContainer(this); }
Object.defineProperty(proto, "isContainer", {
get: function() {
return isContainer(this);
}
});
Object.defineProperty(proto, 'type', {
get: function() { return this._type; }
Object.defineProperty(proto, "type", {
get: function() {
return this._type;
}
});
Object.defineProperty(proto, 'firstChild', {
get: function() { return this._firstChild; }
Object.defineProperty(proto, "firstChild", {
get: function() {
return this._firstChild;
}
});
Object.defineProperty(proto, 'lastChild', {
get: function() { return this._lastChild; }
Object.defineProperty(proto, "lastChild", {
get: function() {
return this._lastChild;
}
});
Object.defineProperty(proto, 'next', {
get: function() { return this._next; }
Object.defineProperty(proto, "next", {
get: function() {
return this._next;
}
});
Object.defineProperty(proto, 'prev', {
get: function() { return this._prev; }
Object.defineProperty(proto, "prev", {
get: function() {
return this._prev;
}
});
Object.defineProperty(proto, 'parent', {
get: function() { return this._parent; }
Object.defineProperty(proto, "parent", {
get: function() {
return this._parent;
}
});
Object.defineProperty(proto, 'sourcepos', {
get: function() { return this._sourcepos; }
Object.defineProperty(proto, "sourcepos", {
get: function() {
return this._sourcepos;
}
});
Object.defineProperty(proto, 'literal', {
get: function() { return this._literal; },
set: function(s) { this._literal = s; }
Object.defineProperty(proto, "literal", {
get: function() {
return this._literal;
},
set: function(s) {
this._literal = s;
}
});
Object.defineProperty(proto, 'destination', {
get: function() { return this._destination; },
set: function(s) { this._destination = s; }
Object.defineProperty(proto, "destination", {
get: function() {
return this._destination;
},
set: function(s) {
this._destination = s;
}
});
Object.defineProperty(proto, 'title', {
get: function() { return this._title; },
set: function(s) { this._title = s; }
Object.defineProperty(proto, "title", {
get: function() {
return this._title;
},
set: function(s) {
this._title = s;
}
});
Object.defineProperty(proto, 'info', {
get: function() { return this._info; },
set: function(s) { this._info = s; }
Object.defineProperty(proto, "info", {
get: function() {
return this._info;
},
set: function(s) {
this._info = s;
}
});
Object.defineProperty(proto, 'level', {
get: function() { return this._level; },
set: function(s) { this._level = s; }
Object.defineProperty(proto, "level", {
get: function() {
return this._level;
},
set: function(s) {
this._level = s;
}
});
Object.defineProperty(proto, 'listType', {
get: function() { return this._listData.type; },
set: function(t) { this._listData.type = t; }
Object.defineProperty(proto, "listType", {
get: function() {
return this._listData.type;
},
set: function(t) {
this._listData.type = t;
}
});
Object.defineProperty(proto, 'listTight', {
get: function() { return this._listData.tight; },
set: function(t) { this._listData.tight = t; }
Object.defineProperty(proto, "listTight", {
get: function() {
return this._listData.tight;
},
set: function(t) {
this._listData.tight = t;
}
});
Object.defineProperty(proto, 'listStart', {
get: function() { return this._listData.start; },
set: function(n) { this._listData.start = n; }
Object.defineProperty(proto, "listStart", {
get: function() {
return this._listData.start;
},
set: function(n) {
this._listData.start = n;
}
});
Object.defineProperty(proto, 'listDelimiter', {
get: function() { return this._listData.delimiter; },
set: function(delim) { this._listData.delimiter = delim; }
Object.defineProperty(proto, "listDelimiter", {
get: function() {
return this._listData.delimiter;
},
set: function(delim) {
this._listData.delimiter = delim;
}
});
Object.defineProperty(proto, 'onEnter', {
get: function() { return this._onEnter; },
set: function(s) { this._onEnter = s; }
Object.defineProperty(proto, "onEnter", {
get: function() {
return this._onEnter;
},
set: function(s) {
this._onEnter = s;
}
});
Object.defineProperty(proto, 'onExit', {
get: function() { return this._onExit; },
set: function(s) { this._onExit = s; }
Object.defineProperty(proto, "onExit", {
get: function() {
return this._onExit;
},
set: function(s) {
this._onExit = s;
}
});

@@ -265,5 +324,4 @@

module.exports = Node;
export default Node;
/* Example of use of walker:

@@ -270,0 +328,0 @@

"use strict";
var Renderer = require('./renderer');
import { escapeXml } from "../common.js";
import Renderer from "./renderer.js";

@@ -9,4 +10,3 @@ var reUnsafeProtocol = /^javascript:|vbscript:|file:|data:/i;

var potentiallyUnsafe = function(url) {
return reUnsafeProtocol.test(url) &&
!reSafeDataProtocol.test(url);
return reUnsafeProtocol.test(url) && !reSafeDataProtocol.test(url);
};

@@ -16,31 +16,31 @@

function tag(name, attrs, selfclosing) {
if (this.disableTags > 0) {
return;
}
this.buffer += ('<' + name);
if (attrs && attrs.length > 0) {
var i = 0;
var attrib;
while ((attrib = attrs[i]) !== undefined) {
this.buffer += (' ' + attrib[0] + '="' + attrib[1] + '"');
i++;
if (this.disableTags > 0) {
return;
}
}
if (selfclosing) {
this.buffer += ' /';
}
this.buffer += '>';
this.lastOut = '>';
this.buffer += "<" + name;
if (attrs && attrs.length > 0) {
var i = 0;
var attrib;
while ((attrib = attrs[i]) !== undefined) {
this.buffer += " " + attrib[0] + '="' + attrib[1] + '"';
i++;
}
}
if (selfclosing) {
this.buffer += " /";
}
this.buffer += ">";
this.lastOut = ">";
}
function HtmlRenderer(options) {
options = options || {};
// by default, soft breaks are rendered as newlines in HTML
options.softbreak = options.softbreak || '\n';
// set to "<br />" to make them hard breaks
// set to " " if you want to ignore line wrapping in source
options = options || {};
// by default, soft breaks are rendered as newlines in HTML
options.softbreak = options.softbreak || "\n";
// set to "<br />" to make them hard breaks
// set to " " if you want to ignore line wrapping in source
this.disableTags = 0;
this.lastOut = "\n";
this.options = options;
this.disableTags = 0;
this.lastOut = "\n";
this.options = options;
}

@@ -51,193 +51,191 @@

function text(node) {
this.out(node.literal);
this.out(node.literal);
}
function softbreak() {
this.lit(this.options.softbreak);
this.lit(this.options.softbreak);
}
function linebreak() {
this.tag('br', [], true);
this.cr();
this.tag("br", [], true);
this.cr();
}
function link(node, entering) {
var attrs = this.attrs(node);
if (entering) {
if (!(this.options.safe && potentiallyUnsafe(node.destination))) {
attrs.push(['href', this.esc(node.destination)]);
var attrs = this.attrs(node);
if (entering) {
if (!(this.options.safe && potentiallyUnsafe(node.destination))) {
attrs.push(["href", this.esc(node.destination)]);
}
if (node.title) {
attrs.push(["title", this.esc(node.title)]);
}
this.tag("a", attrs);
} else {
this.tag("/a");
}
if (node.title) {
attrs.push(['title', this.esc(node.title)]);
}
this.tag('a', attrs);
} else {
this.tag('/a');
}
}
function image(node, entering) {
if (entering) {
if (this.disableTags === 0) {
if (this.options.safe && potentiallyUnsafe(node.destination)) {
this.lit('<img src="" alt="');
} else {
this.lit('<img src="' + this.esc(node.destination) +
'" alt="');
}
if (entering) {
if (this.disableTags === 0) {
if (this.options.safe && potentiallyUnsafe(node.destination)) {
this.lit('<img src="" alt="');
} else {
this.lit('<img src="' + this.esc(node.destination) + '" alt="');
}
}
this.disableTags += 1;
} else {
this.disableTags -= 1;
if (this.disableTags === 0) {
if (node.title) {
this.lit('" title="' + this.esc(node.title));
}
this.lit('" />');
}
}
this.disableTags += 1;
} else {
this.disableTags -= 1;
if (this.disableTags === 0) {
if (node.title) {
this.lit('" title="' + this.esc(node.title));
}
this.lit('" />');
}
}
}
function emph(node, entering) {
this.tag(entering ? 'em' : '/em');
this.tag(entering ? "em" : "/em");
}
function strong(node, entering) {
this.tag(entering ? 'strong' : '/strong');
this.tag(entering ? "strong" : "/strong");
}
function paragraph(node, entering) {
var grandparent = node.parent.parent
, attrs = this.attrs(node);
if (grandparent !== null &&
grandparent.type === 'list') {
if (grandparent.listTight) {
return;
var grandparent = node.parent.parent,
attrs = this.attrs(node);
if (grandparent !== null && grandparent.type === "list") {
if (grandparent.listTight) {
return;
}
}
}
if (entering) {
this.cr();
this.tag('p', attrs);
} else {
this.tag('/p');
this.cr();
}
if (entering) {
this.cr();
this.tag("p", attrs);
} else {
this.tag("/p");
this.cr();
}
}
function heading(node, entering) {
var tagname = 'h' + node.level
, attrs = this.attrs(node);
if (entering) {
this.cr();
this.tag(tagname, attrs);
} else {
this.tag('/' + tagname);
this.cr();
}
var tagname = "h" + node.level,
attrs = this.attrs(node);
if (entering) {
this.cr();
this.tag(tagname, attrs);
} else {
this.tag("/" + tagname);
this.cr();
}
}
function code(node) {
this.tag('code');
this.out(node.literal);
this.tag('/code');
this.tag("code");
this.out(node.literal);
this.tag("/code");
}
function code_block(node) {
var info_words = node.info ? node.info.split(/\s+/) : []
, attrs = this.attrs(node);
if (info_words.length > 0 && info_words[0].length > 0) {
attrs.push(['class', 'language-' + this.esc(info_words[0])]);
}
this.cr();
this.tag('pre');
this.tag('code', attrs);
this.out(node.literal);
this.tag('/code');
this.tag('/pre');
this.cr();
var info_words = node.info ? node.info.split(/\s+/) : [],
attrs = this.attrs(node);
if (info_words.length > 0 && info_words[0].length > 0) {
attrs.push(["class", "language-" + this.esc(info_words[0])]);
}
this.cr();
this.tag("pre");
this.tag("code", attrs);
this.out(node.literal);
this.tag("/code");
this.tag("/pre");
this.cr();
}
function thematic_break(node) {
var attrs = this.attrs(node);
this.cr();
this.tag('hr', attrs, true);
this.cr();
var attrs = this.attrs(node);
this.cr();
this.tag("hr", attrs, true);
this.cr();
}
function block_quote(node, entering) {
var attrs = this.attrs(node);
if (entering) {
this.cr();
this.tag('blockquote', attrs);
this.cr();
} else {
this.cr();
this.tag('/blockquote');
this.cr();
}
var attrs = this.attrs(node);
if (entering) {
this.cr();
this.tag("blockquote", attrs);
this.cr();
} else {
this.cr();
this.tag("/blockquote");
this.cr();
}
}
function list(node, entering) {
var tagname = node.listType === 'bullet' ? 'ul' : 'ol'
, attrs = this.attrs(node);
var tagname = node.listType === "bullet" ? "ul" : "ol",
attrs = this.attrs(node);
if (entering) {
var start = node.listStart;
if (start !== null && start !== 1) {
attrs.push(['start', start.toString()]);
if (entering) {
var start = node.listStart;
if (start !== null && start !== 1) {
attrs.push(["start", start.toString()]);
}
this.cr();
this.tag(tagname, attrs);
this.cr();
} else {
this.cr();
this.tag("/" + tagname);
this.cr();
}
this.cr();
this.tag(tagname, attrs);
this.cr();
} else {
this.cr();
this.tag('/' + tagname);
this.cr();
}
}
function item(node, entering) {
var attrs = this.attrs(node);
if (entering) {
this.tag('li', attrs);
} else {
this.tag('/li');
this.cr();
}
var attrs = this.attrs(node);
if (entering) {
this.tag("li", attrs);
} else {
this.tag("/li");
this.cr();
}
}
function html_inline(node) {
if (this.options.safe) {
this.lit('<!-- raw HTML omitted -->');
} else {
this.lit(node.literal);
}
if (this.options.safe) {
this.lit("<!-- raw HTML omitted -->");
} else {
this.lit(node.literal);
}
}
function html_block(node) {
this.cr();
if (this.options.safe) {
this.lit('<!-- raw HTML omitted -->');
} else {
this.lit(node.literal);
}
this.cr();
this.cr();
if (this.options.safe) {
this.lit("<!-- raw HTML omitted -->");
} else {
this.lit(node.literal);
}
this.cr();
}
function custom_inline(node, entering) {
if (entering && node.onEnter) {
this.lit(node.onEnter);
} else if (!entering && node.onExit) {
this.lit(node.onExit);
}
if (entering && node.onEnter) {
this.lit(node.onEnter);
} else if (!entering && node.onExit) {
this.lit(node.onExit);
}
}
function custom_block(node, entering) {
this.cr();
if (entering && node.onEnter) {
this.lit(node.onEnter);
} else if (!entering && node.onExit) {
this.lit(node.onExit);
}
this.cr();
this.cr();
if (entering && node.onEnter) {
this.lit(node.onEnter);
} else if (!entering && node.onExit) {
this.lit(node.onExit);
}
this.cr();
}

@@ -248,16 +246,23 @@

function out(s) {
this.lit(this.esc(s));
this.lit(this.esc(s));
}
function attrs (node) {
var att = [];
if (this.options.sourcepos) {
var pos = node.sourcepos;
if (pos) {
att.push(['data-sourcepos', String(pos[0][0]) + ':' +
String(pos[0][1]) + '-' + String(pos[1][0]) + ':' +
String(pos[1][1])]);
function attrs(node) {
var att = [];
if (this.options.sourcepos) {
var pos = node.sourcepos;
if (pos) {
att.push([
"data-sourcepos",
String(pos[0][0]) +
":" +
String(pos[0][1]) +
"-" +
String(pos[1][0]) +
":" +
String(pos[1][1])
]);
}
}
}
return att;
return att;
}

@@ -288,3 +293,3 @@

HtmlRenderer.prototype.esc = require('../common').escapeXml;
HtmlRenderer.prototype.esc = escapeXml;

@@ -295,2 +300,2 @@ HtmlRenderer.prototype.out = out;

module.exports = HtmlRenderer;
export default HtmlRenderer;

@@ -11,16 +11,16 @@ "use strict";

function render(ast) {
var walker = ast.walker()
, event
, type;
var walker = ast.walker(),
event,
type;
this.buffer = '';
this.lastOut = '\n';
this.buffer = "";
this.lastOut = "\n";
while((event = walker.next())) {
type = event.node.type;
if (this[type]) {
this[type](event.node, event.entering);
while ((event = walker.next())) {
type = event.node.type;
if (this[type]) {
this[type](event.node, event.entering);
}
}
}
return this.buffer;
return this.buffer;
}

@@ -34,4 +34,4 @@

function lit(str) {
this.buffer += str;
this.lastOut = str;
this.buffer += str;
this.lastOut = str;
}

@@ -43,5 +43,5 @@

function cr() {
if (this.lastOut !== '\n') {
this.lit('\n');
}
if (this.lastOut !== "\n") {
this.lit("\n");
}
}

@@ -57,3 +57,3 @@

function out(str) {
this.lit(str);
this.lit(str);
}

@@ -64,3 +64,3 @@

*
* Abstract function that should be implemented by concrete
* Abstract function that should be implemented by concrete
* renderer implementations.

@@ -71,3 +71,3 @@ *

function esc(str) {
return str;
return str;
}

@@ -78,5 +78,5 @@

Renderer.prototype.lit = lit;
Renderer.prototype.cr = cr;
Renderer.prototype.esc = esc;
Renderer.prototype.cr = cr;
Renderer.prototype.esc = esc;
module.exports = Renderer;
export default Renderer;
"use strict";
var Renderer = require('./renderer');
import Renderer from "./renderer.js";
import { escapeXml } from "../common.js";

@@ -8,147 +9,160 @@ var reXMLTag = /\<[^>]*\>/;

function toTagName(s) {
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
return s.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
}
function XmlRenderer(options) {
options = options || {};
options = options || {};
this.disableTags = 0;
this.lastOut = "\n";
this.disableTags = 0;
this.lastOut = "\n";
this.indentLevel = 0;
this.indent = ' ';
this.indentLevel = 0;
this.indent = " ";
this.options = options;
this.options = options;
}
function render(ast) {
this.buffer = "";
this.buffer = '';
var attrs;
var tagname;
var walker = ast.walker();
var event, node, entering;
var container;
var selfClosing;
var nodetype;
var attrs;
var tagname;
var walker = ast.walker();
var event, node, entering;
var container;
var selfClosing;
var nodetype;
var options = this.options;
var options = this.options;
if (options.time) {
console.time("rendering");
}
if (options.time) { console.time("rendering"); }
this.buffer += '<?xml version="1.0" encoding="UTF-8"?>\n';
this.buffer += '<!DOCTYPE document SYSTEM "CommonMark.dtd">\n';
this.buffer += '<?xml version="1.0" encoding="UTF-8"?>\n';
this.buffer += '<!DOCTYPE document SYSTEM "CommonMark.dtd">\n';
while ((event = walker.next())) {
entering = event.entering;
node = event.node;
nodetype = node.type;
while ((event = walker.next())) {
entering = event.entering;
node = event.node;
nodetype = node.type;
container = node.isContainer;
container = node.isContainer;
selfClosing =
nodetype === "thematic_break" ||
nodetype === "linebreak" ||
nodetype === "softbreak";
selfClosing = nodetype === 'thematic_break'
|| nodetype === 'linebreak'
|| nodetype === 'softbreak';
tagname = toTagName(nodetype);
tagname = toTagName(nodetype);
if (entering) {
attrs = [];
if (entering) {
attrs = [];
switch (nodetype) {
case 'document':
attrs.push(['xmlns', 'http://commonmark.org/xml/1.0']);
break;
case 'list':
if (node.listType !== null) {
attrs.push(['type', node.listType.toLowerCase()]);
switch (nodetype) {
case "document":
attrs.push(["xmlns", "http://commonmark.org/xml/1.0"]);
break;
case "list":
if (node.listType !== null) {
attrs.push(["type", node.listType.toLowerCase()]);
}
if (node.listStart !== null) {
attrs.push(["start", String(node.listStart)]);
}
if (node.listTight !== null) {
attrs.push([
"tight",
node.listTight ? "true" : "false"
]);
}
var delim = node.listDelimiter;
if (delim !== null) {
var delimword = "";
if (delim === ".") {
delimword = "period";
} else {
delimword = "paren";
}
attrs.push(["delimiter", delimword]);
}
break;
case "code_block":
if (node.info) {
attrs.push(["info", node.info]);
}
break;
case "heading":
attrs.push(["level", String(node.level)]);
break;
case "link":
case "image":
attrs.push(["destination", node.destination]);
attrs.push(["title", node.title]);
break;
case "custom_inline":
case "custom_block":
attrs.push(["on_enter", node.onEnter]);
attrs.push(["on_exit", node.onExit]);
break;
default:
break;
}
if (node.listStart !== null) {
attrs.push(['start', String(node.listStart)]);
if (options.sourcepos) {
var pos = node.sourcepos;
if (pos) {
attrs.push([
"sourcepos",
String(pos[0][0]) +
":" +
String(pos[0][1]) +
"-" +
String(pos[1][0]) +
":" +
String(pos[1][1])
]);
}
}
if (node.listTight !== null) {
attrs.push(['tight', (node.listTight ? 'true' : 'false')]);
this.cr();
this.out(this.tag(tagname, attrs, selfClosing));
if (container) {
this.indentLevel += 1;
} else if (!container && !selfClosing) {
var lit = node.literal;
if (lit) {
this.out(this.esc(lit));
}
this.out(this.tag("/" + tagname));
}
var delim = node.listDelimiter;
if (delim !== null) {
var delimword = '';
if (delim === '.') {
delimword = 'period';
} else {
delimword = 'paren';
}
attrs.push(['delimiter', delimword]);
}
break;
case 'code_block':
if (node.info) {
attrs.push(['info', node.info]);
}
break;
case 'heading':
attrs.push(['level', String(node.level)]);
break;
case 'link':
case 'image':
attrs.push(['destination', node.destination]);
attrs.push(['title', node.title]);
break;
case 'custom_inline':
case 'custom_block':
attrs.push(['on_enter', node.onEnter]);
attrs.push(['on_exit', node.onExit]);
break;
default:
break;
} else {
this.indentLevel -= 1;
this.cr();
this.out(this.tag("/" + tagname));
}
if (options.sourcepos) {
var pos = node.sourcepos;
if (pos) {
attrs.push(['sourcepos', String(pos[0][0]) + ':' +
String(pos[0][1]) + '-' + String(pos[1][0]) + ':' +
String(pos[1][1])]);
}
}
this.cr();
this.out(this.tag(tagname, attrs, selfClosing));
if (container) {
this.indentLevel += 1;
} else if (!container && !selfClosing) {
var lit = node.literal;
if (lit) {
this.out(this.esc(lit));
}
this.out(this.tag('/' + tagname));
}
} else {
this.indentLevel -= 1;
this.cr();
this.out(this.tag('/' + tagname));
}
}
if (options.time) { console.timeEnd("rendering"); }
this.buffer += '\n';
return this.buffer;
if (options.time) {
console.timeEnd("rendering");
}
this.buffer += "\n";
return this.buffer;
}
function out(s) {
if(this.disableTags > 0) {
this.buffer += s.replace(reXMLTag, '');
}else{
this.buffer += s;
}
this.lastOut = s;
if (this.disableTags > 0) {
this.buffer += s.replace(reXMLTag, "");
} else {
this.buffer += s;
}
this.lastOut = s;
}
function cr() {
if(this.lastOut !== '\n') {
this.buffer += '\n';
this.lastOut = '\n';
for(var i = this.indentLevel; i > 0; i--) {
this.buffer += this.indent;
if (this.lastOut !== "\n") {
this.buffer += "\n";
this.lastOut = "\n";
for (var i = this.indentLevel; i > 0; i--) {
this.buffer += this.indent;
}
}
}
}

@@ -158,16 +172,16 @@

function tag(name, attrs, selfclosing) {
var result = '<' + name;
if(attrs && attrs.length > 0) {
var i = 0;
var attrib;
while ((attrib = attrs[i]) !== undefined) {
result += ' ' + attrib[0] + '="' + this.esc(attrib[1]) + '"';
i++;
var result = "<" + name;
if (attrs && attrs.length > 0) {
var i = 0;
var attrib;
while ((attrib = attrs[i]) !== undefined) {
result += " " + attrib[0] + '="' + this.esc(attrib[1]) + '"';
i++;
}
}
}
if(selfclosing) {
result += ' /';
}
result += '>';
return result;
if (selfclosing) {
result += " /";
}
result += ">";
return result;
}

@@ -182,4 +196,4 @@

XmlRenderer.prototype.tag = tag;
XmlRenderer.prototype.esc = require('../common').escapeXml;
XmlRenderer.prototype.esc = escapeXml;
module.exports = XmlRenderer;
export default XmlRenderer;
{
"name": "commonmark",
"description": "a strongly specified, highly compatible variant of Markdown",
"version": "0.29.1",
"version": "0.29.2",
"homepage": "https://commonmark.org",

@@ -12,9 +12,17 @@ "keywords": [

],
"repository": "jgm/commonmark.js",
"repository": "commonmark/commonmark.js",
"author": "John MacFarlane",
"bugs": {
"url": "https://github.com/jgm/commonmark.js/issues"
"url": "https://github.com/commonmark/commonmark.js/issues"
},
"license": "BSD-2-Clause",
"main": "./lib/index.js",
"type": "commonjs",
"main": "./dist/commonmark.js",
"module": "./lib/index.js",
"exports": {
".": {
"require": "./dist/commonmark.js",
"default": "./lib/index.js"
}
},
"bin": {

@@ -24,9 +32,11 @@ "commonmark": "./bin/commonmark"

"scripts": {
"test": "node ./test/test.js"
"build": "rollup -c",
"lint": "eslint .",
"test": "node -r esm ./test/test"
},
"dependencies": {
"entities": "~1.1.1",
"entities": "~2.0",
"mdurl": "~1.0.1",
"string.prototype.repeat": "^0.2.0",
"minimist": "~1.2.0"
"minimist": ">=1.2.2"
},

@@ -40,15 +50,22 @@ "directories": {

"devDependencies": {
"@rollup/plugin-commonjs": "^11.0.1",
"@rollup/plugin-json": "^4.0.1",
"@rollup/plugin-node-resolve": "^7.0.0",
"acorn": ">=5.7.4",
"benchmark": "^2.1.4",
"bower": "^1.8.8",
"browserify": "^16.2.2",
"cached-path-relative": "^1.0.2",
"eslint": "^4.19.1",
"http-server": "^0.11.1",
"lodash": "^4.17.13",
"markdown-it": "^8.4.1",
"marked": "^0.7.0",
"eslint": "^7.4.0",
"esm": "^3.2.25",
"http-server": "^0.12.3",
"lodash": "^4.17.19",
"markdown-it": "^10.0",
"marked": "^0.8.0",
"mem": ">=4.0.0",
"rollup": "^1.29.0",
"rollup-plugin-uglify": "^6.0.4",
"showdown": "^1.9.1",
"uglify-js": "^3.4.0"
"uglify-js": "^3.4.0",
"serialize-javascript": ">=3.1.0"
}
}
commonmark.js
=============
[![Build Status](https://img.shields.io/travis/commonmark/commonmark.js/master.svg?style=flat)](https://travis-ci.org/commonmark/commonmark.js)
[![Build Status](https://github.com/commonmark/commonmark.js/workflows/CI%20tests/badge.svg)](https://github.com/commonmark/commonmark.js/actions)
[![NPM version](https://img.shields.io/npm/v/commonmark.svg?style=flat)](https://www.npmjs.org/package/commonmark)

@@ -36,3 +36,3 @@

For client-side use, fetch the latest from
<https://raw.githubusercontent.com/jgm/commonmark.js/master/dist/commonmark.js>,
<https://raw.githubusercontent.com/commonmark/commonmark.js/master/dist/commonmark.js>,
or `bower install commonmark`.

@@ -39,0 +39,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 too big to display

Sorry, the diff of this file is not supported yet

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