Skip to content

Commit 691d787

Browse files
author
Jiang Shang
committed
safari bugfix
1 parent 6888cb8 commit 691d787

File tree

2 files changed

+36
-53
lines changed

2 files changed

+36
-53
lines changed

hyperdown.js

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@
392392
}, {
393393
key: 'parseBlock',
394394
value: function parseBlock(text, lines) {
395+
var _this4 = this;
396+
395397
this.blocks = [];
396398
this.current = 'normal';
397399
this.pos = -1;
@@ -504,34 +506,28 @@
504506
case /^((?:(?:(?:[ :]*\-[ :]*)+(?:\||\+))|(?:(?:\||\+)(?:[ :]*\-[ :]*)+)|(?:(?:[ :]*\-[ :]*)+(?:\||\+)(?:[ :]*\-[ :]*)+))+)$/g.test(line):
505507
var tableMatches = /^((?:(?:(?:[ :]*\-[ :]*)+(?:\||\+))|(?:(?:\||\+)(?:[ :]*\-[ :]*)+)|(?:(?:[ :]*\-[ :]*)+(?:\||\+)(?:[ :]*\-[ :]*)+))+)$/g.exec(line);
506508
if (this.isBlock('normal')) {
507-
var block = this.getBlock();
508-
var head = false;
509-
510-
if (block.length === 0 || block[0] !== 'normal' || /^\s*$/.test(lines[block[2]])) {
511-
this.startBlock('table', key);
512-
} else {
513-
head = true;
514-
this.backBlock(1, 'table');
515-
}
516-
517-
if (tableMatches[1][0] == '|') {
518-
tableMatches[1] = tableMatches[1].substr(1);
509+
(function () {
510+
var block = _this4.getBlock();
511+
var head = false;
519512

520-
if (tableMatches[1][tableMatches[1].length - 1] == '|') {
521-
tableMatches[1] = tableMatches[1].slice(0, -1);
513+
if (block.length === 0 || block[0] !== 'normal' || /^\s*$/.test(lines[block[2]])) {
514+
_this4.startBlock('table', key);
515+
} else {
516+
head = true;
517+
_this4.backBlock(1, 'table');
522518
}
523-
}
524519

525-
var rows = tableMatches[1].split(/(\+|\|)/);
526-
var aligns = [];
527-
var _iteratorNormalCompletion = true;
528-
var _didIteratorError = false;
529-
var _iteratorError = undefined;
520+
if (tableMatches[1][0] == '|') {
521+
tableMatches[1] = tableMatches[1].substr(1);
530522

531-
try {
532-
for (var _iterator = rows[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
533-
var row = _step.value;
523+
if (tableMatches[1][tableMatches[1].length - 1] == '|') {
524+
tableMatches[1] = tableMatches[1].slice(0, -1);
525+
}
526+
}
534527

528+
var rows = tableMatches[1].split(/(\+|\|)/);
529+
var aligns = [];
530+
rows.forEach(function (row) {
535531
var align = 'none';
536532

537533
if (tableMatches = row.match(/^\s*(:?)\-+(:?)\s*$/)) {
@@ -545,23 +541,10 @@
545541
}
546542

547543
aligns.push(align);
548-
}
549-
} catch (err) {
550-
_didIteratorError = true;
551-
_iteratorError = err;
552-
} finally {
553-
try {
554-
if (!_iteratorNormalCompletion && _iterator['return']) {
555-
_iterator['return']();
556-
}
557-
} finally {
558-
if (_didIteratorError) {
559-
throw _iteratorError;
560-
}
561-
}
562-
}
544+
});
563545

564-
this.setBlock(key, [head, aligns]);
546+
_this4.setBlock(key, [head, aligns]);
547+
})();
565548
}
566549
break;
567550

@@ -734,10 +717,10 @@
734717
}, {
735718
key: 'parsePre',
736719
value: function parsePre(lines) {
737-
var _this4 = this;
720+
var _this5 = this;
738721

739722
lines.forEach(function (line, ind) {
740-
lines[ind] = _this4.htmlspecialchars(line.substr(4));
723+
lines[ind] = _this5.htmlspecialchars(line.substr(4));
741724
});
742725
var str = lines.join('\n');
743726

@@ -809,7 +792,7 @@
809792
}, {
810793
key: 'parseList',
811794
value: function parseList(lines) {
812-
var _this5 = this;
795+
var _this6 = this;
813796

814797
var html = '';
815798
var minSpace = 99999;
@@ -864,7 +847,7 @@
864847
}
865848

866849
if (leftLines.length) {
867-
html += "<li>" + _this5.parse(leftLines.join("\n")) + "</li>";
850+
html += "<li>" + _this6.parse(leftLines.join("\n")) + "</li>";
868851
}
869852

870853
leftLines = [text];
@@ -891,7 +874,7 @@
891874
}, {
892875
key: 'parseTable',
893876
value: function parseTable(lines, value) {
894-
var _this6 = this;
877+
var _this7 = this;
895878

896879
var _value = _slicedToArray(value, 2);
897880

@@ -970,7 +953,7 @@
970953
html += ' align="' + aligns[key] + '"';
971954
}
972955

973-
html += '>' + _this6.parseInline(text) + ('</' + tag + '>');
956+
html += '>' + _this7.parseInline(text) + ('</' + tag + '>');
974957
});
975958

976959
html += '</tr>';
@@ -983,9 +966,9 @@
983966
};
984967

985968
for (var key in lines) {
986-
var _ret = _loop(key);
969+
var _ret2 = _loop(key);
987970

988-
if (_ret === 'continue') continue;
971+
if (_ret2 === 'continue') continue;
989972
}
990973

991974
if (body !== null) {
@@ -1016,10 +999,10 @@
1016999
}, {
10171000
key: 'parseNormal',
10181001
value: function parseNormal(lines) {
1019-
var _this7 = this;
1002+
var _this8 = this;
10201003

10211004
lines = lines.map(function (line) {
1022-
return _this7.parseInline(line);
1005+
return _this8.parseInline(line);
10231006
});
10241007

10251008
var str = lines.join("\n").trim();
@@ -1077,10 +1060,10 @@
10771060
}, {
10781061
key: 'parseHtml',
10791062
value: function parseHtml(lines, type) {
1080-
var _this8 = this;
1063+
var _this9 = this;
10811064

10821065
lines.forEach(function (line) {
1083-
line = _this8.parseInline(line, _this8.specialWhiteList[type] ? _this8.specialWhiteList[type] : '');
1066+
line = _this9.parseInline(line, _this9.specialWhiteList[type] ? _this9.specialWhiteList[type] : '');
10841067
});
10851068

10861069
return lines.join("\n");

src/Parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export default class Parser {
428428

429429
let rows = tableMatches[1].split(/(\+|\|)/)
430430
let aligns = []
431-
for(let row of rows) {
431+
rows.forEach( row => {
432432
let align = 'none'
433433

434434
if (tableMatches = row.match(/^\s*(:?)\-+(:?)\s*$/)) {
@@ -442,7 +442,7 @@ export default class Parser {
442442
}
443443

444444
aligns.push(align)
445-
}
445+
})
446446

447447
this.setBlock(key, [head, aligns])
448448
}

0 commit comments

Comments
 (0)