Skip to content

Commit

Permalink
Change signature again
Browse files Browse the repository at this point in the history
  • Loading branch information
calculuschild committed Aug 14, 2021
1 parent 3f57f4e commit c1daf6f
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 142 deletions.
51 changes: 22 additions & 29 deletions lib/marked.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,16 +665,12 @@ var Tokenizer_1 = class Tokenizer {
if (cap) {
const item = {
type: 'table',
header: {
text: splitCells$1(cap[1])
},
header: splitCells$1(cap[1]).map(c => {return {text: c};}),
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
cells: {
text: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
}
rows: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
};

if (item.header.text.length === item.align.length) {
if (item.header.length === item.align.length) {
item.raw = cap[0];

let l = item.align.length;
Expand All @@ -691,30 +687,27 @@ var Tokenizer_1 = class Tokenizer {
}
}

l = item.cells.text.length;
l = item.rows.length;
for (i = 0; i < l; i++) {
item.cells.text[i] = splitCells$1(item.cells.text[i], item.header.text.length);
item.rows[i] = splitCells$1(item.rows[i], item.header.length).map(c => {return {text : c};});
}

// parse child tokens inside headers and cells
item.header.tokens = [];
item.cells.tokens = [];
// parse child tokens inside headers and cells

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

// cell child tokens
l = item.cells.text.length;
l = item.rows.length;
for (j = 0; j < l; j++) {
row = item.cells.text[j];
item.cells.tokens[j] = [];
row = item.rows[j];
for (k = 0; k < row.length; k++) {
item.cells.tokens[j][k] = [];
this.lexer.inlineTokens(row[k], item.cells.tokens[j][k]);
row[k].tokens = [];
this.lexer.inlineTokens(row[k].text, row[k].tokens);
}
}

Expand Down Expand Up @@ -2214,25 +2207,25 @@ var Parser_1 = class Parser {

// header
cell = '';
l2 = token.header.text.length;
l2 = token.header.length;
for (j = 0; j < l2; j++) {
cell += this.renderer.tablecell(
this.parseInline(token.header.tokens[j]),
this.parseInline(token.header[j].tokens),
{ header: true, align: token.align[j] }
);
}
header += this.renderer.tablerow(cell);

body = '';
l2 = token.cells.text.length;
l2 = token.rows.length;
for (j = 0; j < l2; j++) {
row = token.cells.tokens[j];
row = token.rows[j];

cell = '';
l3 = row.length;
for (k = 0; k < l3; k++) {
cell += this.renderer.tablecell(
this.parseInline(row[k]),
this.parseInline(row[k].tokens),
{ header: false, align: token.align[k] }
);
}
Expand Down Expand Up @@ -2655,12 +2648,12 @@ marked.walkTokens = function(tokens, callback) {
callback(token);
switch (token.type) {
case 'table': {
for (const cell of token.header.tokens) {
marked.walkTokens(cell, callback);
for (const cell of token.header) {
marked.walkTokens(cell.tokens, callback);
}
for (const row of token.cells.tokens) {
for (const row of token.rows) {
for (const cell of row) {
marked.walkTokens(cell, callback);
marked.walkTokens(cell.tokens, callback);
}
}
break;
Expand Down
59 changes: 30 additions & 29 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,16 +760,16 @@
if (cap) {
var item = {
type: 'table',
header: {
text: splitCells$1(cap[1])
},
header: splitCells$1(cap[1]).map(function (c) {
return {
text: c
};
}),
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
cells: {
text: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
}
rows: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
};

if (item.header.text.length === item.align.length) {
if (item.header.length === item.align.length) {
item.raw = cap[0];
var l = item.align.length;
var i, j, k, row;
Expand All @@ -786,33 +786,34 @@
}
}

l = item.cells.text.length;
l = item.rows.length;

for (i = 0; i < l; i++) {
item.cells.text[i] = splitCells$1(item.cells.text[i], item.header.text.length);
item.rows[i] = splitCells$1(item.rows[i], item.header.length).map(function (c) {
return {
text: c
};
});
} // parse child tokens inside headers and cells
// header child tokens


item.header.tokens = [];
item.cells.tokens = []; // header child tokens

l = item.header.text.length;
l = item.header.length;

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


l = item.cells.text.length;
l = item.rows.length;

for (j = 0; j < l; j++) {
row = item.cells.text[j];
item.cells.tokens[j] = [];
row = item.rows[j];

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

Expand Down Expand Up @@ -2305,26 +2306,26 @@
header = ''; // header

cell = '';
l2 = token.header.text.length;
l2 = token.header.length;

for (j = 0; j < l2; j++) {
cell += this.renderer.tablecell(this.parseInline(token.header.tokens[j]), {
cell += this.renderer.tablecell(this.parseInline(token.header[j].tokens), {
header: true,
align: token.align[j]
});
}

header += this.renderer.tablerow(cell);
body = '';
l2 = token.cells.text.length;
l2 = token.rows.length;

for (j = 0; j < l2; j++) {
row = token.cells.tokens[j];
row = token.rows[j];
cell = '';
l3 = row.length;

for (k = 0; k < l3; k++) {
cell += this.renderer.tablecell(this.parseInline(row[k]), {
cell += this.renderer.tablecell(this.parseInline(row[k].tokens), {
header: false,
align: token.align[k]
});
Expand Down Expand Up @@ -2844,17 +2845,17 @@
switch (token.type) {
case 'table':
{
for (var _iterator2 = _createForOfIteratorHelperLoose(token.header.tokens), _step2; !(_step2 = _iterator2()).done;) {
for (var _iterator2 = _createForOfIteratorHelperLoose(token.header), _step2; !(_step2 = _iterator2()).done;) {
var cell = _step2.value;
marked.walkTokens(cell, callback);
marked.walkTokens(cell.tokens, callback);
}

for (var _iterator3 = _createForOfIteratorHelperLoose(token.cells.tokens), _step3; !(_step3 = _iterator3()).done;) {
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, callback);
marked.walkTokens(_cell.tokens, callback);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,25 @@ module.exports = class Parser {

// header
cell = '';
l2 = token.header.text.length;
l2 = token.header.length;
for (j = 0; j < l2; j++) {
cell += this.renderer.tablecell(
this.parseInline(token.header.tokens[j]),
this.parseInline(token.header[j].tokens),
{ header: true, align: token.align[j] }
);
}
header += this.renderer.tablerow(cell);

body = '';
l2 = token.cells.text.length;
l2 = token.rows.length;
for (j = 0; j < l2; j++) {
row = token.cells.tokens[j];
row = token.rows[j];

cell = '';
l3 = row.length;
for (k = 0; k < l3; k++) {
cell += this.renderer.tablecell(
this.parseInline(row[k]),
this.parseInline(row[k].tokens),
{ header: false, align: token.align[k] }
);
}
Expand Down
31 changes: 12 additions & 19 deletions src/Tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,12 @@ module.exports = class Tokenizer {
if (cap) {
const item = {
type: 'table',
header: {
text: splitCells(cap[1])
},
header: splitCells(cap[1]).map(c => { return { text: c }; }),
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
cells: {
text: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
}
rows: cap[3] ? cap[3].replace(/\n$/, '').split('\n') : []
};

if (item.header.text.length === item.align.length) {
if (item.header.length === item.align.length) {
item.raw = cap[0];

let l = item.align.length;
Expand All @@ -374,30 +370,27 @@ module.exports = class Tokenizer {
}
}

l = item.cells.text.length;
l = item.rows.length;
for (i = 0; i < l; i++) {
item.cells.text[i] = splitCells(item.cells.text[i], item.header.text.length);
item.rows[i] = splitCells(item.rows[i], item.header.length).map(c => { return { text: c }; });
}

// parse child tokens inside headers and cells
item.header.tokens = [];
item.cells.tokens = [];

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

// cell child tokens
l = item.cells.text.length;
l = item.rows.length;
for (j = 0; j < l; j++) {
row = item.cells.text[j];
item.cells.tokens[j] = [];
row = item.rows[j];
for (k = 0; k < row.length; k++) {
item.cells.tokens[j][k] = [];
this.lexer.inlineTokens(row[k], item.cells.tokens[j][k]);
row[k].tokens = [];
this.lexer.inlineTokens(row[k].text, row[k].tokens);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ marked.walkTokens = function(tokens, callback) {
callback(token);
switch (token.type) {
case 'table': {
for (const cell of token.header.tokens) {
marked.walkTokens(cell, callback);
for (const cell of token.header) {
marked.walkTokens(cell.tokens, callback);
}
for (const row of token.cells.tokens) {
for (const row of token.rows) {
for (const cell of row) {
marked.walkTokens(cell, callback);
marked.walkTokens(cell.tokens, callback);
}
}
break;
Expand Down
Loading

0 comments on commit c1daf6f

Please sign in to comment.