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 Jan 6, 2022
1 parent a9696e2 commit 41990a5
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 41 deletions.
49 changes: 35 additions & 14 deletions lib/marked.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* marked - a markdown parser
* Copyright (c) 2011-2021, Christopher Jeffrey. (MIT Licensed)
* Copyright (c) 2011-2022, Christopher Jeffrey. (MIT Licensed)
* https://github.com/markedjs/marked
*/

Expand All @@ -26,6 +26,9 @@ function _defineProperties(target, props) {
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}

Expand Down Expand Up @@ -432,16 +435,10 @@ var Tokenizer = /*#__PURE__*/function () {
_proto.space = function space(src) {
var cap = this.rules.block.newline.exec(src);

if (cap) {
if (cap[0].length > 1) {
return {
type: 'space',
raw: cap[0]
};
}

if (cap && cap[0].length > 0) {
return {
raw: '\n'
type: 'space',
raw: cap[0]
};
}
};
Expand Down Expand Up @@ -667,10 +664,30 @@ var Tokenizer = /*#__PURE__*/function () {
for (i = 0; i < l; i++) {
this.lexer.state.top = false;
list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);

if (!list.loose && list.items[i].tokens.some(function (t) {
var spacers = list.items[i].tokens.filter(function (t) {
return t.type === 'space';
})) {
});
var hasMultipleLineBreaks = spacers.every(function (t) {
var chars = t.raw.split('');
var lineBreaks = 0;

for (var _iterator = _createForOfIteratorHelperLoose(chars), _step; !(_step = _iterator()).done;) {
var _char = _step.value;

if (_char === '\n') {
lineBreaks += 1;
}

if (lineBreaks > 1) {
return true;
}
}

return false;
});

if (!list.loose && spacers.length && hasMultipleLineBreaks) {
// Having a single line break doesn't mean a list is loose. A single line break is terminating the last list item
list.loose = true;
list.items[i].loose = true;
}
Expand Down Expand Up @@ -1495,7 +1512,11 @@ var Lexer = /*#__PURE__*/function () {
if (token = this.tokenizer.space(src)) {
src = src.substring(token.raw.length);

if (token.type) {
if (token.raw.length === 1 && tokens.length > 0) {
// if there's a single \n as a spacer, it's terminating the last line,
// so move it there so that we don't get unecessary paragraph tags
tokens[tokens.length - 1].raw += '\n';
} else {
tokens.push(token);
}

Expand Down
40 changes: 29 additions & 11 deletions lib/marked.esm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* marked - a markdown parser
* Copyright (c) 2011-2021, Christopher Jeffrey. (MIT Licensed)
* Copyright (c) 2011-2022, Christopher Jeffrey. (MIT Licensed)
* https://github.com/markedjs/marked
*/

Expand Down Expand Up @@ -355,14 +355,11 @@ class Tokenizer {

space(src) {
const cap = this.rules.block.newline.exec(src);
if (cap) {
if (cap[0].length > 1) {
return {
type: 'space',
raw: cap[0]
};
}
return { raw: '\n' };
if (cap && cap[0].length > 0) {
return {
type: 'space',
raw: cap[0]
};
}
}

Expand Down Expand Up @@ -586,7 +583,24 @@ class Tokenizer {
for (i = 0; i < l; i++) {
this.lexer.state.top = false;
list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
if (!list.loose && list.items[i].tokens.some(t => t.type === 'space')) {
const spacers = list.items[i].tokens.filter(t => t.type === 'space');
const hasMultipleLineBreaks = spacers.every(t => {
const chars = t.raw.split('');
let lineBreaks = 0;
for (const char of chars) {
if (char === '\n') {
lineBreaks += 1;
}
if (lineBreaks > 1) {
return true;
}
}

return false;
});

if (!list.loose && spacers.length && hasMultipleLineBreaks) {
// Having a single line break doesn't mean a list is loose. A single line break is terminating the last list item
list.loose = true;
list.items[i].loose = true;
}
Expand Down Expand Up @@ -1477,7 +1491,11 @@ class Lexer {
// newline
if (token = this.tokenizer.space(src)) {
src = src.substring(token.raw.length);
if (token.type) {
if (token.raw.length === 1 && tokens.length > 0) {
// if there's a single \n as a spacer, it's terminating the last line,
// so move it there so that we don't get unecessary paragraph tags
tokens[tokens.length - 1].raw += '\n';
} else {
tokens.push(token);
}
continue;
Expand Down
49 changes: 35 additions & 14 deletions lib/marked.umd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* marked - a markdown parser
* Copyright (c) 2011-2021, Christopher Jeffrey. (MIT Licensed)
* Copyright (c) 2011-2022, Christopher Jeffrey. (MIT Licensed)
* https://github.com/markedjs/marked
*/

Expand Down Expand Up @@ -28,6 +28,9 @@
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}

Expand Down Expand Up @@ -434,16 +437,10 @@
_proto.space = function space(src) {
var cap = this.rules.block.newline.exec(src);

if (cap) {
if (cap[0].length > 1) {
return {
type: 'space',
raw: cap[0]
};
}

if (cap && cap[0].length > 0) {
return {
raw: '\n'
type: 'space',
raw: cap[0]
};
}
};
Expand Down Expand Up @@ -669,10 +666,30 @@
for (i = 0; i < l; i++) {
this.lexer.state.top = false;
list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);

if (!list.loose && list.items[i].tokens.some(function (t) {
var spacers = list.items[i].tokens.filter(function (t) {
return t.type === 'space';
})) {
});
var hasMultipleLineBreaks = spacers.every(function (t) {
var chars = t.raw.split('');
var lineBreaks = 0;

for (var _iterator = _createForOfIteratorHelperLoose(chars), _step; !(_step = _iterator()).done;) {
var _char = _step.value;

if (_char === '\n') {
lineBreaks += 1;
}

if (lineBreaks > 1) {
return true;
}
}

return false;
});

if (!list.loose && spacers.length && hasMultipleLineBreaks) {
// Having a single line break doesn't mean a list is loose. A single line break is terminating the last list item
list.loose = true;
list.items[i].loose = true;
}
Expand Down Expand Up @@ -1497,7 +1514,11 @@
if (token = this.tokenizer.space(src)) {
src = src.substring(token.raw.length);

if (token.type) {
if (token.raw.length === 1 && tokens.length > 0) {
// if there's a single \n as a spacer, it's terminating the last line,
// so move it there so that we don't get unecessary paragraph tags
tokens[tokens.length - 1].raw += '\n';
} else {
tokens.push(token);
}

Expand Down
4 changes: 2 additions & 2 deletions marked.min.js

Large diffs are not rendered by default.

0 comments on commit 41990a5

Please sign in to comment.