Skip to content

Commit

Permalink
🗜️ build [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkedJS bot committed Aug 30, 2022
1 parent 994b2e6 commit 7e2ef30
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 132 deletions.
95 changes: 52 additions & 43 deletions lib/marked.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {

function getDefaults() {
return {
async: false,
baseUrl: null,
breaks: false,
extensions: null,
Expand Down Expand Up @@ -412,7 +413,7 @@ function outputLink(cap, link, raw, lexer) {
href: href,
title: title,
text: text,
tokens: lexer.inlineTokens(text, [])
tokens: lexer.inlineTokens(text)
};
lexer.state.inLink = false;
return token;
Expand Down Expand Up @@ -520,15 +521,13 @@ var Tokenizer = /*#__PURE__*/function () {
}
}

var token = {
return {
type: 'heading',
raw: cap[0],
depth: cap[1].length,
text: text,
tokens: []
tokens: this.lexer.inline(text)
};
this.lexer.inline(token.text, token.tokens);
return token;
}
};

Expand Down Expand Up @@ -758,10 +757,10 @@ var Tokenizer = /*#__PURE__*/function () {
};

if (this.options.sanitize) {
var text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]);
token.type = 'paragraph';
token.text = this.options.sanitizer ? this.options.sanitizer(cap[0]) : escape(cap[0]);
token.tokens = [];
this.lexer.inline(token.text, token.tokens);
token.text = text;
token.tokens = this.lexer.inline(text);
}

return token;
Expand Down Expand Up @@ -831,8 +830,7 @@ var Tokenizer = /*#__PURE__*/function () {
l = item.header.length;

for (j = 0; j < l; j++) {
item.header[j].tokens = [];
this.lexer.inline(item.header[j].text, item.header[j].tokens);
item.header[j].tokens = this.lexer.inline(item.header[j].text);
} // cell child tokens


Expand All @@ -842,8 +840,7 @@ var Tokenizer = /*#__PURE__*/function () {
row = item.rows[j];

for (k = 0; k < row.length; k++) {
row[k].tokens = [];
this.lexer.inline(row[k].text, row[k].tokens);
row[k].tokens = this.lexer.inline(row[k].text);
}
}

Expand All @@ -856,45 +853,40 @@ var Tokenizer = /*#__PURE__*/function () {
var cap = this.rules.block.lheading.exec(src);

if (cap) {
var token = {
return {
type: 'heading',
raw: cap[0],
depth: cap[2].charAt(0) === '=' ? 1 : 2,
text: cap[1],
tokens: []
tokens: this.lexer.inline(cap[1])
};
this.lexer.inline(token.text, token.tokens);
return token;
}
};

_proto.paragraph = function paragraph(src) {
var cap = this.rules.block.paragraph.exec(src);

if (cap) {
var token = {
var text = cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1];
return {
type: 'paragraph',
raw: cap[0],
text: cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1],
tokens: []
text: text,
tokens: this.lexer.inline(text)
};
this.lexer.inline(token.text, token.tokens);
return token;
}
};

_proto.text = function text(src) {
var cap = this.rules.block.text.exec(src);

if (cap) {
var token = {
return {
type: 'text',
raw: cap[0],
text: cap[0],
tokens: []
tokens: this.lexer.inline(cap[0])
};
this.lexer.inline(token.text, token.tokens);
return token;
}
};

Expand Down Expand Up @@ -1073,7 +1065,7 @@ var Tokenizer = /*#__PURE__*/function () {
type: 'em',
raw: src.slice(0, lLength + match.index + rLength + 1),
text: _text,
tokens: this.lexer.inlineTokens(_text, [])
tokens: this.lexer.inlineTokens(_text)
};
} // Create 'strong' if smallest delimiter has even char count. **a***

Expand All @@ -1083,7 +1075,7 @@ var Tokenizer = /*#__PURE__*/function () {
type: 'strong',
raw: src.slice(0, lLength + match.index + rLength + 1),
text: text,
tokens: this.lexer.inlineTokens(text, [])
tokens: this.lexer.inlineTokens(text)
};
}
}
Expand Down Expand Up @@ -1129,7 +1121,7 @@ var Tokenizer = /*#__PURE__*/function () {
type: 'del',
raw: cap[0],
text: cap[2],
tokens: this.lexer.inlineTokens(cap[2], [])
tokens: this.lexer.inlineTokens(cap[2])
};
}
};
Expand Down Expand Up @@ -2728,22 +2720,32 @@ function marked(src, opt, callback) {
return;
}

function onError(e) {
e.message += '\nPlease report this to https://github.com/markedjs/marked.';

if (opt.silent) {
return '<p>An error occurred:</p><pre>' + escape(e.message + '', true) + '</pre>';
}

throw e;
}

try {
var _tokens = Lexer.lex(src, opt);

if (opt.walkTokens) {
if (opt.async) {
return Promise.all(marked.walkTokens(_tokens, opt.walkTokens)).then(function () {
return Parser.parse(_tokens, opt);
})["catch"](onError);
}

marked.walkTokens(_tokens, opt.walkTokens);
}

return Parser.parse(_tokens, opt);
} catch (e) {
e.message += '\nPlease report this to https://github.com/markedjs/marked.';

if (opt.silent) {
return '<p>An error occurred:</p><pre>' + escape(e.message + '', true) + '</pre>';
}

throw e;
onError(e);
}
}
/**
Expand Down Expand Up @@ -2909,11 +2911,14 @@ marked.use = function () {
var _walkTokens = marked.defaults.walkTokens;

opts.walkTokens = function (token) {
pack.walkTokens.call(this, token);
var values = [];
values.push(pack.walkTokens.call(this, token));

if (_walkTokens) {
_walkTokens.call(this, token);
values = values.concat(_walkTokens.call(this, token));
}

return values;
};
}

Expand All @@ -2930,24 +2935,26 @@ marked.use = function () {


marked.walkTokens = function (tokens, callback) {
var values = [];

var _loop3 = function _loop3() {
var token = _step.value;
callback.call(marked, token);
values = values.concat(callback.call(marked, token));

switch (token.type) {
case 'table':
{
for (var _iterator2 = _createForOfIteratorHelperLoose(token.header), _step2; !(_step2 = _iterator2()).done;) {
var cell = _step2.value;
marked.walkTokens(cell.tokens, callback);
values = values.concat(marked.walkTokens(cell.tokens, callback));
}

for (var _iterator3 = _createForOfIteratorHelperLoose(token.rows), _step3; !(_step3 = _iterator3()).done;) {
var row = _step3.value;

for (var _iterator4 = _createForOfIteratorHelperLoose(row), _step4; !(_step4 = _iterator4()).done;) {
var _cell = _step4.value;
marked.walkTokens(_cell.tokens, callback);
values = values.concat(marked.walkTokens(_cell.tokens, callback));
}
}

Expand All @@ -2956,7 +2963,7 @@ marked.walkTokens = function (tokens, callback) {

case 'list':
{
marked.walkTokens(token.items, callback);
values = values.concat(marked.walkTokens(token.items, callback));
break;
}

Expand All @@ -2965,10 +2972,10 @@ marked.walkTokens = function (tokens, callback) {
if (marked.defaults.extensions && marked.defaults.extensions.childTokens && marked.defaults.extensions.childTokens[token.type]) {
// Walk any extensions
marked.defaults.extensions.childTokens[token.type].forEach(function (childTokens) {
marked.walkTokens(token[childTokens], callback);
values = values.concat(marked.walkTokens(token[childTokens], callback));
});
} else if (token.tokens) {
marked.walkTokens(token.tokens, callback);
values = values.concat(marked.walkTokens(token.tokens, callback));
}
}
}
Expand All @@ -2977,6 +2984,8 @@ marked.walkTokens = function (tokens, callback) {
for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
_loop3();
}

return values;
};
/**
* Parse Inline
Expand Down

0 comments on commit 7e2ef30

Please sign in to comment.