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 Dec 23, 2022
1 parent e692634 commit a01488a
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 45 deletions.
48 changes: 33 additions & 15 deletions lib/marked.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,9 @@ var Tokenizer = /*#__PURE__*/function () {
}
raw = cap[0];
src = src.substring(raw.length);
line = cap[2].split('\n', 1)[0];
line = cap[2].split('\n', 1)[0].replace(/^\t+/, function (t) {
return ' '.repeat(3 * t.length);
});
nextLine = src.split('\n', 1)[0];
if (this.options.pedantic) {
indent = 2;
Expand All @@ -559,56 +561,72 @@ var Tokenizer = /*#__PURE__*/function () {
endEarly = true;
}
if (!endEarly) {
var nextBulletRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))");
var nextBulletRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))");
var hrRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)");
var fencesBeginRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}(?:```|~~~)");
var headingBeginRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}#");

// Check if following lines should be included in List Item
while (src) {
rawLine = src.split('\n', 1)[0];
line = rawLine;
nextLine = rawLine;

// Re-align to follow commonmark nesting rules
if (this.options.pedantic) {
line = line.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
}

// End list item if found code fences
if (fencesBeginRegex.test(line)) {
if (fencesBeginRegex.test(nextLine)) {
break;
}

// End list item if found start of new heading
if (headingBeginRegex.test(line)) {
if (headingBeginRegex.test(nextLine)) {
break;
}

// End list item if found start of new bullet
if (nextBulletRegex.test(line)) {
if (nextBulletRegex.test(nextLine)) {
break;
}

// Horizontal rule found
if (hrRegex.test(src)) {
break;
}
if (line.search(/[^ ]/) >= indent || !line.trim()) {
if (nextLine.search(/[^ ]/) >= indent || !nextLine.trim()) {
// Dedent if possible
itemContents += '\n' + line.slice(indent);
} else if (!blankLine) {
// Until blank line, item doesn't need indentation
itemContents += '\n' + line;
itemContents += '\n' + nextLine.slice(indent);
} else {
// Otherwise, improper indentation ends this item
break;
// not enough indentation
if (blankLine) {
break;
}

// paragraph continuation unless last line was a different block level element
if (line.search(/[^ ]/) >= 4) {
// indented code block
break;
}
if (fencesBeginRegex.test(line)) {
break;
}
if (headingBeginRegex.test(line)) {
break;
}
if (hrRegex.test(line)) {
break;
}
itemContents += '\n' + nextLine;
}
if (!blankLine && !line.trim()) {
if (!blankLine && !nextLine.trim()) {
// Check if current line is blank
blankLine = true;
}
raw += rawLine + '\n';
src = src.substring(rawLine.length + 1);
line = nextLine.slice(indent);
}
}
if (!list.loose) {
Expand Down
46 changes: 32 additions & 14 deletions lib/marked.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ class Tokenizer {
raw = cap[0];
src = src.substring(raw.length);

line = cap[2].split('\n', 1)[0];
line = cap[2].split('\n', 1)[0].replace(/^\t+/, (t) => ' '.repeat(3 * t.length));
nextLine = src.split('\n', 1)[0];

if (this.options.pedantic) {
Expand All @@ -535,33 +535,33 @@ class Tokenizer {
}

if (!endEarly) {
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))`);
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`);
const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);

// Check if following lines should be included in List Item
while (src) {
rawLine = src.split('\n', 1)[0];
line = rawLine;
nextLine = rawLine;

// Re-align to follow commonmark nesting rules
if (this.options.pedantic) {
line = line.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
}

// End list item if found code fences
if (fencesBeginRegex.test(line)) {
if (fencesBeginRegex.test(nextLine)) {
break;
}

// End list item if found start of new heading
if (headingBeginRegex.test(line)) {
if (headingBeginRegex.test(nextLine)) {
break;
}

// End list item if found start of new bullet
if (nextBulletRegex.test(line)) {
if (nextBulletRegex.test(nextLine)) {
break;
}

Expand All @@ -570,20 +570,38 @@ class Tokenizer {
break;
}

if (line.search(/[^ ]/) >= indent || !line.trim()) { // Dedent if possible
itemContents += '\n' + line.slice(indent);
} else if (!blankLine) { // Until blank line, item doesn't need indentation
itemContents += '\n' + line;
} else { // Otherwise, improper indentation ends this item
break;
if (nextLine.search(/[^ ]/) >= indent || !nextLine.trim()) { // Dedent if possible
itemContents += '\n' + nextLine.slice(indent);
} else {
// not enough indentation
if (blankLine) {
break;
}

// paragraph continuation unless last line was a different block level element
if (line.search(/[^ ]/) >= 4) { // indented code block
break;
}
if (fencesBeginRegex.test(line)) {
break;
}
if (headingBeginRegex.test(line)) {
break;
}
if (hrRegex.test(line)) {
break;
}

itemContents += '\n' + nextLine;
}

if (!blankLine && !line.trim()) { // Check if current line is blank
if (!blankLine && !nextLine.trim()) { // Check if current line is blank
blankLine = true;
}

raw += rawLine + '\n';
src = src.substring(rawLine.length + 1);
line = nextLine.slice(indent);
}
}

Expand Down
48 changes: 33 additions & 15 deletions lib/marked.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,9 @@
}
raw = cap[0];
src = src.substring(raw.length);
line = cap[2].split('\n', 1)[0];
line = cap[2].split('\n', 1)[0].replace(/^\t+/, function (t) {
return ' '.repeat(3 * t.length);
});
nextLine = src.split('\n', 1)[0];
if (this.options.pedantic) {
indent = 2;
Expand All @@ -563,56 +565,72 @@
endEarly = true;
}
if (!endEarly) {
var nextBulletRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))");
var nextBulletRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))");
var hrRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)");
var fencesBeginRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}(?:```|~~~)");
var headingBeginRegex = new RegExp("^ {0," + Math.min(3, indent - 1) + "}#");

// Check if following lines should be included in List Item
while (src) {
rawLine = src.split('\n', 1)[0];
line = rawLine;
nextLine = rawLine;

// Re-align to follow commonmark nesting rules
if (this.options.pedantic) {
line = line.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
}

// End list item if found code fences
if (fencesBeginRegex.test(line)) {
if (fencesBeginRegex.test(nextLine)) {
break;
}

// End list item if found start of new heading
if (headingBeginRegex.test(line)) {
if (headingBeginRegex.test(nextLine)) {
break;
}

// End list item if found start of new bullet
if (nextBulletRegex.test(line)) {
if (nextBulletRegex.test(nextLine)) {
break;
}

// Horizontal rule found
if (hrRegex.test(src)) {
break;
}
if (line.search(/[^ ]/) >= indent || !line.trim()) {
if (nextLine.search(/[^ ]/) >= indent || !nextLine.trim()) {
// Dedent if possible
itemContents += '\n' + line.slice(indent);
} else if (!blankLine) {
// Until blank line, item doesn't need indentation
itemContents += '\n' + line;
itemContents += '\n' + nextLine.slice(indent);
} else {
// Otherwise, improper indentation ends this item
break;
// not enough indentation
if (blankLine) {
break;
}

// paragraph continuation unless last line was a different block level element
if (line.search(/[^ ]/) >= 4) {
// indented code block
break;
}
if (fencesBeginRegex.test(line)) {
break;
}
if (headingBeginRegex.test(line)) {
break;
}
if (hrRegex.test(line)) {
break;
}
itemContents += '\n' + nextLine;
}
if (!blankLine && !line.trim()) {
if (!blankLine && !nextLine.trim()) {
// Check if current line is blank
blankLine = true;
}
raw += rawLine + '\n';
src = src.substring(rawLine.length + 1);
line = nextLine.slice(indent);
}
}
if (!list.loose) {
Expand Down
2 changes: 1 addition & 1 deletion marked.min.js

Large diffs are not rendered by default.

0 comments on commit a01488a

Please sign in to comment.