Skip to content

Commit

Permalink
Fix table render problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjstyle committed Aug 27, 2016
1 parent 290848b commit e134681
Showing 1 changed file with 14 additions and 29 deletions.
43 changes: 14 additions & 29 deletions public/javascripts/lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
table: noop,
paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
text: /^[^\n]+/,
pre : /^ *<pre(?:\s+[^>]*)*\s*> *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/
text: /^[^\n]+/
};

block.bullet = /(?:[*+-]|\d+\.)/;
Expand Down Expand Up @@ -195,16 +194,6 @@
continue;
}

// pre
if (cap = this.rules.pre.exec(src)) {
src = src.substring(cap[0].length);
this.tokens.push({
type: 'pre',
text: cap[2]
});
continue;
}

// heading
if (cap = this.rules.heading.exec(src)) {
src = src.substring(cap[0].length);
Expand Down Expand Up @@ -373,7 +362,7 @@
: 'html',
pre: !this.options.sanitizer
&& (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
text: (cap[1]=='script' && this.options.script==false ? escape(cap[0]) : cap[0])
text: cap[0]
});
continue;
}
Expand All @@ -396,7 +385,7 @@
type: 'table',
header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
cells: cap[3].replace(/\n$/, '').split('\n')
};

for (i = 0; i < item.align.length; i++) {
Expand All @@ -412,6 +401,9 @@
}

for (i = 0; i < item.cells.length; i++) {
if (!item.cells[i].match(/\|$/)) {
item.cells[i] = item.cells[i] + "\|";
}
item.cells[i] = item.cells[i]
.replace(/^ *\| *| *\| *$/g, '')
.split(/ *\| */);
Expand Down Expand Up @@ -622,7 +614,7 @@
? this.options.sanitizer
? this.options.sanitizer(cap[0])
: escape(cap[0])
: this.renderer.html(cap[0]);
: cap[0]
continue;
}

Expand Down Expand Up @@ -770,7 +762,6 @@

function Renderer(options) {
this.options = options || {};

}

Renderer.prototype.code = function(code, lang, escaped) {
Expand Down Expand Up @@ -805,14 +796,13 @@
};

Renderer.prototype.heading = function(text, level, raw) {
var idText = this.options.headerPrefix
// refer from https://github.com/tadoli/marked/commit/7d3c20313d8be2da898c9924dd12effc78e726b1
+ raw.toLowerCase().replace(/[^\w|ㄱ-ㅎ|ㅏ-ㅣ|가-힣]+/g, '-');
return '<h'
+ level
+ ' id="' + idText + '">'
+ ' id="'
+ this.options.headerPrefix
+ raw.toLowerCase().replace(/[^\w]+/g, '-')
+ '">'
+ text
+ '<a href="#' + idText + '" class="head-anchor">#</a>'
+ '</h'
+ level
+ '>\n';
Expand Down Expand Up @@ -1004,11 +994,6 @@
this.token.lang,
this.token.escaped);
}
case 'pre': {
return '<pre>'
+ escape(this.token.text)
+ '</pre>\n'
}
case 'table': {
var header = ''
, body = ''
Expand Down Expand Up @@ -1108,11 +1093,12 @@
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '\'');
.replace(/'/g, '&#39;');
}

function unescape(html) {
return html.replace(/&([#\w]+);/g, function(_, n) {
// explicitly match decimal, hex, and named HTML entities
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
n = n.toLowerCase();
if (n === 'colon') return ':';
if (n.charAt(0) === '#') {
Expand Down Expand Up @@ -1260,7 +1246,6 @@
tables: true,
breaks: false,
pedantic: false,
script : false,
sanitize: false,
sanitizer: null,
mangle: true,
Expand Down

0 comments on commit e134681

Please sign in to comment.