Skip to content

Commit 8bd5e9b

Browse files
author
Jiang Shang
committed
bugfix
1 parent f4470b6 commit 8bd5e9b

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

dist/Parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ var Parser = (function () {
508508
break;
509509

510510
// multi heading
511-
case /^\s*((=|-){2,})\s*$/.test(line) && (this.getBlock() && !/^\s*$/.test(lines[this.getBlock()[2]])):
511+
case /^\s*((=|-){2,})\s*$/.test(line) && (this.getBlock() && this.getBlock()[0] === 'normal' && !/^\s*$/.test(lines[this.getBlock()[2]])):
512512
// check if last line isn't empty
513513
var multiHeadingMatches = line.match(/^\s*((=|-){2,})\s*$/);
514514
if (this.isBlock('normal')) {

hyperdown.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@
208208

209209
html += result;
210210
});
211-
211+
if (this.hooks.afterParse) {
212+
html = this.call('afterParse', html);
213+
}
212214
return html;
213215
}
214216

@@ -493,7 +495,7 @@
493495
case /^ {4}/.test(line):
494496
emptyCount = 0;
495497

496-
if (this.isBlock('pre')) {
498+
if (this.isBlock('pre') || this.isBlock('list')) {
497499
this.setBlock(key);
498500
} else if (this.isBlock('normal')) {
499501
this.startBlock('pre', key);
@@ -554,7 +556,7 @@
554556
break;
555557

556558
// multi heading
557-
case /^\s*((=|-){2,})\s*$/.test(line) && (this.getBlock() && !/^\s*$/.test(lines[this.getBlock()[2]])):
559+
case /^\s*((=|-){2,})\s*$/.test(line) && (this.getBlock() && this.getBlock()[0] === 'normal' && !/^\s*$/.test(lines[this.getBlock()[2]])):
558560
// check if last line isn't empty
559561
var multiHeadingMatches = line.match(/^\s*((=|-){2,})\s*$/);
560562
if (this.isBlock('normal')) {
@@ -798,7 +800,7 @@
798800

799801
// count levels
800802
lines.forEach(function (line, key) {
801-
var matches = line.match(/^(\s*)((?:[0-9a-z]\.?)|\-|\+|\*)(\s+)(.*)$/);
803+
var matches = line.match(/^(\s*)((?:[0-9a-z]+\.?)|\-|\+|\*)(\s+)(.*)$/);
802804
if (matches) {
803805
var space = matches[1].length;
804806
var type = /[\+\-\*]/.test(matches[2]) ? 'ul' : 'ol';
@@ -836,6 +838,9 @@
836838
var pattern = new RegExp("^\s{" + secondMinSpace + "}");
837839
leftLines.push(line.replace(pattern, ''));
838840
} else {
841+
if (leftLines.length) {
842+
html += "<li>" + _this6.parse(leftLines.join("\n")) + "</li>";
843+
}
839844
if (lastType !== type) {
840845
if (lastType.length) {
841846
html += '</' + lastType + '>';
@@ -844,10 +849,6 @@
844849
html += '<' + type + '>';
845850
}
846851

847-
if (leftLines.length) {
848-
html += "<li>" + _this6.parse(leftLines.join("\n")) + "</li>";
849-
}
850-
851852
leftLines = [text];
852853
lastType = type;
853854
}

src/Parser.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ export default class Parser {
123123

124124
html += result
125125
})
126-
126+
if (this.hooks.afterParse) {
127+
html = this.call('afterParse', html)
128+
}
127129
return html
128130
}
129131

@@ -395,7 +397,7 @@ export default class Parser {
395397
case /^ {4}/.test(line):
396398
emptyCount = 0
397399

398-
if (this.isBlock('pre')) {
400+
if (this.isBlock('pre') || this.isBlock('list')) {
399401
this.setBlock(key)
400402
} else if (this.isBlock('normal')) {
401403
this.startBlock('pre', key)
@@ -455,7 +457,7 @@ export default class Parser {
455457
break
456458

457459
// multi heading
458-
case /^\s*((=|-){2,})\s*$/.test(line) && (this.getBlock() && !/^\s*$/.test(lines[this.getBlock()[2]])): // check if last line isn't empty
460+
case /^\s*((=|-){2,})\s*$/.test(line) && (this.getBlock() && this.getBlock()[0] === 'normal' && !/^\s*$/.test(lines[this.getBlock()[2]])): // check if last line isn't empty
459461
let multiHeadingMatches = line.match(/^\s*((=|-){2,})\s*$/)
460462
if (this.isBlock('normal')) {
461463
this.backBlock(1, 'mh', multiHeadingMatches[1][0] == '=' ? 1 : 2)
@@ -672,7 +674,7 @@ export default class Parser {
672674

673675
// count levels
674676
lines.forEach( (line, key) => {
675-
let matches = line.match(/^(\s*)((?:[0-9a-z]\.?)|\-|\+|\*)(\s+)(.*)$/)
677+
let matches = line.match(/^(\s*)((?:[0-9a-z]+\.?)|\-|\+|\*)(\s+)(.*)$/)
676678
if (matches) {
677679
let space = matches[1].length
678680
let type = /[\+\-\*]/.test(matches[2]) ? 'ul' : 'ol'
@@ -705,6 +707,9 @@ export default class Parser {
705707
let pattern = new RegExp("^\s{" + secondMinSpace + "}")
706708
leftLines.push(line.replace(pattern, ''))
707709
} else {
710+
if (leftLines.length) {
711+
html += "<li>" + this.parse(leftLines.join("\n")) + "</li>"
712+
}
708713
if (lastType !== type) {
709714
if (lastType.length) {
710715
html += `</${lastType}>`
@@ -713,10 +718,6 @@ export default class Parser {
713718
html += `<${type}>`
714719
}
715720

716-
if (leftLines.length) {
717-
html += "<li>" + this.parse(leftLines.join("\n")) + "</li>"
718-
}
719-
720721
leftLines = [text]
721722
lastType = type
722723
}

test/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,8 @@ describe('HyperDown.js', function() {
9797
it('specialhtml', function() {
9898
assert.equal('<p>&lt;li&gt;asdf</p>', parser.makeHtml('<li>asdf'));
9999
});
100+
it('specialHR', function() {
101+
assert.equal('<pre><code>a</code></pre><hr>', parser.makeHtml('```\na\n```\n---'));
102+
});
100103
});
101104
});

0 commit comments

Comments
 (0)