Skip to content

Commit 41990a5

Browse files
author
MarkedJS bot
committed
🗜️ build [skip ci]
1 parent a9696e2 commit 41990a5

File tree

4 files changed

+101
-41
lines changed

4 files changed

+101
-41
lines changed

lib/marked.cjs

+35-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* marked - a markdown parser
3-
* Copyright (c) 2011-2021, Christopher Jeffrey. (MIT Licensed)
3+
* Copyright (c) 2011-2022, Christopher Jeffrey. (MIT Licensed)
44
* https://github.com/markedjs/marked
55
*/
66

@@ -26,6 +26,9 @@ function _defineProperties(target, props) {
2626
function _createClass(Constructor, protoProps, staticProps) {
2727
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
2828
if (staticProps) _defineProperties(Constructor, staticProps);
29+
Object.defineProperty(Constructor, "prototype", {
30+
writable: false
31+
});
2932
return Constructor;
3033
}
3134

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

435-
if (cap) {
436-
if (cap[0].length > 1) {
437-
return {
438-
type: 'space',
439-
raw: cap[0]
440-
};
441-
}
442-
438+
if (cap && cap[0].length > 0) {
443439
return {
444-
raw: '\n'
440+
type: 'space',
441+
raw: cap[0]
445442
};
446443
}
447444
};
@@ -667,10 +664,30 @@ var Tokenizer = /*#__PURE__*/function () {
667664
for (i = 0; i < l; i++) {
668665
this.lexer.state.top = false;
669666
list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
670-
671-
if (!list.loose && list.items[i].tokens.some(function (t) {
667+
var spacers = list.items[i].tokens.filter(function (t) {
672668
return t.type === 'space';
673-
})) {
669+
});
670+
var hasMultipleLineBreaks = spacers.every(function (t) {
671+
var chars = t.raw.split('');
672+
var lineBreaks = 0;
673+
674+
for (var _iterator = _createForOfIteratorHelperLoose(chars), _step; !(_step = _iterator()).done;) {
675+
var _char = _step.value;
676+
677+
if (_char === '\n') {
678+
lineBreaks += 1;
679+
}
680+
681+
if (lineBreaks > 1) {
682+
return true;
683+
}
684+
}
685+
686+
return false;
687+
});
688+
689+
if (!list.loose && spacers.length && hasMultipleLineBreaks) {
690+
// Having a single line break doesn't mean a list is loose. A single line break is terminating the last list item
674691
list.loose = true;
675692
list.items[i].loose = true;
676693
}
@@ -1495,7 +1512,11 @@ var Lexer = /*#__PURE__*/function () {
14951512
if (token = this.tokenizer.space(src)) {
14961513
src = src.substring(token.raw.length);
14971514

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

lib/marked.esm.js

+29-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* marked - a markdown parser
3-
* Copyright (c) 2011-2021, Christopher Jeffrey. (MIT Licensed)
3+
* Copyright (c) 2011-2022, Christopher Jeffrey. (MIT Licensed)
44
* https://github.com/markedjs/marked
55
*/
66

@@ -355,14 +355,11 @@ class Tokenizer {
355355

356356
space(src) {
357357
const cap = this.rules.block.newline.exec(src);
358-
if (cap) {
359-
if (cap[0].length > 1) {
360-
return {
361-
type: 'space',
362-
raw: cap[0]
363-
};
364-
}
365-
return { raw: '\n' };
358+
if (cap && cap[0].length > 0) {
359+
return {
360+
type: 'space',
361+
raw: cap[0]
362+
};
366363
}
367364
}
368365

@@ -586,7 +583,24 @@ class Tokenizer {
586583
for (i = 0; i < l; i++) {
587584
this.lexer.state.top = false;
588585
list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
589-
if (!list.loose && list.items[i].tokens.some(t => t.type === 'space')) {
586+
const spacers = list.items[i].tokens.filter(t => t.type === 'space');
587+
const hasMultipleLineBreaks = spacers.every(t => {
588+
const chars = t.raw.split('');
589+
let lineBreaks = 0;
590+
for (const char of chars) {
591+
if (char === '\n') {
592+
lineBreaks += 1;
593+
}
594+
if (lineBreaks > 1) {
595+
return true;
596+
}
597+
}
598+
599+
return false;
600+
});
601+
602+
if (!list.loose && spacers.length && hasMultipleLineBreaks) {
603+
// Having a single line break doesn't mean a list is loose. A single line break is terminating the last list item
590604
list.loose = true;
591605
list.items[i].loose = true;
592606
}
@@ -1477,7 +1491,11 @@ class Lexer {
14771491
// newline
14781492
if (token = this.tokenizer.space(src)) {
14791493
src = src.substring(token.raw.length);
1480-
if (token.type) {
1494+
if (token.raw.length === 1 && tokens.length > 0) {
1495+
// if there's a single \n as a spacer, it's terminating the last line,
1496+
// so move it there so that we don't get unecessary paragraph tags
1497+
tokens[tokens.length - 1].raw += '\n';
1498+
} else {
14811499
tokens.push(token);
14821500
}
14831501
continue;

lib/marked.umd.js

+35-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* marked - a markdown parser
3-
* Copyright (c) 2011-2021, Christopher Jeffrey. (MIT Licensed)
3+
* Copyright (c) 2011-2022, Christopher Jeffrey. (MIT Licensed)
44
* https://github.com/markedjs/marked
55
*/
66

@@ -28,6 +28,9 @@
2828
function _createClass(Constructor, protoProps, staticProps) {
2929
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
3030
if (staticProps) _defineProperties(Constructor, staticProps);
31+
Object.defineProperty(Constructor, "prototype", {
32+
writable: false
33+
});
3134
return Constructor;
3235
}
3336

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

437-
if (cap) {
438-
if (cap[0].length > 1) {
439-
return {
440-
type: 'space',
441-
raw: cap[0]
442-
};
443-
}
444-
440+
if (cap && cap[0].length > 0) {
445441
return {
446-
raw: '\n'
442+
type: 'space',
443+
raw: cap[0]
447444
};
448445
}
449446
};
@@ -669,10 +666,30 @@
669666
for (i = 0; i < l; i++) {
670667
this.lexer.state.top = false;
671668
list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
672-
673-
if (!list.loose && list.items[i].tokens.some(function (t) {
669+
var spacers = list.items[i].tokens.filter(function (t) {
674670
return t.type === 'space';
675-
})) {
671+
});
672+
var hasMultipleLineBreaks = spacers.every(function (t) {
673+
var chars = t.raw.split('');
674+
var lineBreaks = 0;
675+
676+
for (var _iterator = _createForOfIteratorHelperLoose(chars), _step; !(_step = _iterator()).done;) {
677+
var _char = _step.value;
678+
679+
if (_char === '\n') {
680+
lineBreaks += 1;
681+
}
682+
683+
if (lineBreaks > 1) {
684+
return true;
685+
}
686+
}
687+
688+
return false;
689+
});
690+
691+
if (!list.loose && spacers.length && hasMultipleLineBreaks) {
692+
// Having a single line break doesn't mean a list is loose. A single line break is terminating the last list item
676693
list.loose = true;
677694
list.items[i].loose = true;
678695
}
@@ -1497,7 +1514,11 @@
14971514
if (token = this.tokenizer.space(src)) {
14981515
src = src.substring(token.raw.length);
14991516

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

marked.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)