-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarked-ie6.js
More file actions
74 lines (74 loc) · 3.18 KB
/
Copy pathmarked-ie6.js
File metadata and controls
74 lines (74 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
(function(global) {
var defaults = {
gfm: true,
breaks: false,
sanitize: false
};
function trim(str) {
return str.replace(/^\s+|\s+$/g, "");
}
function escapeHTML(str) {
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
}
function marked(src, opt) {
if (!src) return "";
var options = {}, k;
for (k in defaults) options[k] = defaults[k];
if (opt) for (k in opt) options[k] = opt[k];
if (options.sanitize) src = escapeHTML(src);
var text = "\n" + src.replace(/\r\n|\r/g, "\n") + "\n";
var codeBlocks = [];
text = text.replace(/\n```[\s\S]*?\n([\s\S]*?)\n```\n/g, function(match, code) {
codeBlocks.push(escapeHTML(code));
return "\n@@CB" + (codeBlocks.length - 1) + "@@\n";
});
text = text.replace(/\n(#+)(.*)/g, function(m, hashes, content) {
var level = hashes.length;
return "\n<h" + level + ">" + trim(content) + "</h" + level + ">";
});
text = text.replace(/\n(?:---|\*\*\*|___)\s*\n/g, "\n<hr />\n");
text = text.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '<img src="$2" alt="$1" />');
text = text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, "<strong>$2</strong>");
text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, "<em>$2</em>");
text = text.replace(/`([^`]+)`/g, "<code>$1</code>");
text = text.replace(/~~([^~]+)~~/g, "<del>$1</del>");
text = text.replace(/\n(>.*?(?:\n[^\n]*)*\n)/g, function(m, bq) {
return "\n<blockquote>" + bq.replace(/\n>\s?/g, "\n") + "</blockquote>\n";
});
text = text.replace(/\n((?:[\*\-\+]\s+.*(?:\n|$))+)/g, function(m, list) {
var items = list.replace(/\n[\*\-\+]\s+(.*)/g, "\n<li>$1</li>");
return "\n<ul>" + items + "</ul>\n";
});
text = text.replace(/\n((?:\d+\.\s+.*(?:\n|$))+)/g, function(m, list) {
var items = list.replace(/\n\d+\.\s+(.*)/g, "\n<li>$1</li>");
return "\n<ol>" + items + "</ol>\n";
});
var paragraphs = text.split(/\n{2,}/);
for (var i = 0; i < paragraphs.length; i++) {
var p = trim(paragraphs[i]);
if (p !== "") {
if (!/^<(?:ul|ol|li|h|p|bl|pre|hr|img|div|table|tbody|thead|tr|th|td)/i.test(p)) {
if (options.breaks) p = p.replace(/\n/g, "<br>\n");
paragraphs[i] = "<p>" + p + "</p>";
} else {
paragraphs[i] = p;
}
} else {
paragraphs[i] = "";
}
}
text = paragraphs.join("\n");
text = text.replace(/@@CB(\d+)@@/g, function(m, i) {
return "<pre><code>" + codeBlocks[i] + "</code></pre>";
});
return trim(text.replace(/\n</g, "<"));
}
marked.parse = marked;
marked.setOptions = function(opt) {
for (var k in opt) defaults[k] = opt[k];
return marked;
};
marked.defaults = defaults;
global.marked = marked;
})(typeof window !== "undefined" ? window : this);