Skip to content

Commit ed18cd5

Browse files
author
Travis-CI
committed
🗜️ build [skip ci]
1 parent edf87e3 commit ed18cd5

File tree

3 files changed

+160
-145
lines changed

3 files changed

+160
-145
lines changed

lib/marked.esm.js

+65-57
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
* The code in this file is generated from files in ./src/
1010
*/
1111

12-
let defaults = getDefaults();
12+
function createCommonjsModule(fn, module) {
13+
return module = { exports: {} }, fn(module, module.exports), module.exports;
14+
}
1315

16+
var defaults = createCommonjsModule(function (module) {
1417
function getDefaults() {
1518
return {
1619
baseUrl: null,
@@ -33,47 +36,53 @@ function getDefaults() {
3336
}
3437

3538
function changeDefaults(newDefaults) {
36-
defaults = newDefaults;
39+
module.exports.defaults = newDefaults;
3740
}
3841

39-
var defaults_1 = {
40-
defaults,
42+
module.exports = {
43+
defaults: getDefaults(),
4144
getDefaults,
4245
changeDefaults
4346
};
47+
});
48+
var defaults_1 = defaults.defaults;
49+
var defaults_2 = defaults.getDefaults;
50+
var defaults_3 = defaults.changeDefaults;
4451

4552
/**
4653
* Helpers
4754
*/
55+
const escapeTest = /[&<>"']/;
56+
const escapeReplace = /[&<>"']/g;
57+
const escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
58+
const escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
59+
const escapeReplacements = {
60+
'&': '&amp;',
61+
'<': '&lt;',
62+
'>': '&gt;',
63+
'"': '&quot;',
64+
"'": '&#39;'
65+
};
66+
const getEscapeReplacement = (ch) => escapeReplacements[ch];
4867
function escape(html, encode) {
4968
if (encode) {
50-
if (escape.escapeTest.test(html)) {
51-
return html.replace(escape.escapeReplace, escape.getReplacement);
69+
if (escapeTest.test(html)) {
70+
return html.replace(escapeReplace, getEscapeReplacement);
5271
}
5372
} else {
54-
if (escape.escapeTestNoEncode.test(html)) {
55-
return html.replace(escape.escapeReplaceNoEncode, escape.getReplacement);
73+
if (escapeTestNoEncode.test(html)) {
74+
return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
5675
}
5776
}
5877

5978
return html;
6079
}
61-
escape.escapeTest = /[&<>"']/;
62-
escape.escapeReplace = /[&<>"']/g;
63-
escape.escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/;
64-
escape.escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g;
65-
escape.replacements = {
66-
'&': '&amp;',
67-
'<': '&lt;',
68-
'>': '&gt;',
69-
'"': '&quot;',
70-
"'": '&#39;'
71-
};
72-
escape.getReplacement = (ch) => escape.replacements[ch];
80+
81+
const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
7382

7483
function unescape(html) {
7584
// explicitly match decimal, hex, and named HTML entities
76-
return html.replace(unescape.unescapeTest, (_, n) => {
85+
return html.replace(unescapeTest, (_, n) => {
7786
n = n.toLowerCase();
7887
if (n === 'colon') return ':';
7988
if (n.charAt(0) === '#') {
@@ -84,15 +93,15 @@ function unescape(html) {
8493
return '';
8594
});
8695
}
87-
unescape.unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
8896

97+
const caret = /(^|[^\[])\^/g;
8998
function edit(regex, opt) {
9099
regex = regex.source || regex;
91100
opt = opt || '';
92101
const obj = {
93102
replace: (name, val) => {
94103
val = val.source || val;
95-
val = val.replace(edit.caret, '$1');
104+
val = val.replace(caret, '$1');
96105
regex = regex.replace(name, val);
97106
return obj;
98107
},
@@ -102,14 +111,15 @@ function edit(regex, opt) {
102111
};
103112
return obj;
104113
}
105-
edit.caret = /(^|[^\[])\^/g;
106114

115+
const nonWordAndColonTest = /[^\w:]/g;
116+
const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
107117
function cleanUrl(sanitize, base, href) {
108118
if (sanitize) {
109119
let prot;
110120
try {
111121
prot = decodeURIComponent(unescape(href))
112-
.replace(cleanUrl.protocol, '')
122+
.replace(nonWordAndColonTest, '')
113123
.toLowerCase();
114124
} catch (e) {
115125
return null;
@@ -118,7 +128,7 @@ function cleanUrl(sanitize, base, href) {
118128
return null;
119129
}
120130
}
121-
if (base && !cleanUrl.originIndependentUrl.test(href)) {
131+
if (base && !originIndependentUrl.test(href)) {
122132
href = resolveUrl(base, href);
123133
}
124134
try {
@@ -128,44 +138,42 @@ function cleanUrl(sanitize, base, href) {
128138
}
129139
return href;
130140
}
131-
cleanUrl.protocol = /[^\w:]/g;
132-
cleanUrl.originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
141+
142+
const baseUrls = {};
143+
const justDomain = /^[^:]+:\/*[^/]*$/;
144+
const protocol = /^([^:]+:)[\s\S]*$/;
145+
const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
133146

134147
function resolveUrl(base, href) {
135-
if (!resolveUrl.baseUrls[' ' + base]) {
148+
if (!baseUrls[' ' + base]) {
136149
// we can ignore everything in base after the last slash of its path component,
137150
// but we might need to add _that_
138151
// https://tools.ietf.org/html/rfc3986#section-3
139-
if (resolveUrl.justDomain.test(base)) {
140-
resolveUrl.baseUrls[' ' + base] = base + '/';
152+
if (justDomain.test(base)) {
153+
baseUrls[' ' + base] = base + '/';
141154
} else {
142-
resolveUrl.baseUrls[' ' + base] = rtrim(base, '/', true);
155+
baseUrls[' ' + base] = rtrim(base, '/', true);
143156
}
144157
}
145-
base = resolveUrl.baseUrls[' ' + base];
158+
base = baseUrls[' ' + base];
146159
const relativeBase = base.indexOf(':') === -1;
147160

148161
if (href.substring(0, 2) === '//') {
149162
if (relativeBase) {
150163
return href;
151164
}
152-
return base.replace(resolveUrl.protocol, '$1') + href;
165+
return base.replace(protocol, '$1') + href;
153166
} else if (href.charAt(0) === '/') {
154167
if (relativeBase) {
155168
return href;
156169
}
157-
return base.replace(resolveUrl.domain, '$1') + href;
170+
return base.replace(domain, '$1') + href;
158171
} else {
159172
return base + href;
160173
}
161174
}
162-
resolveUrl.baseUrls = {};
163-
resolveUrl.justDomain = /^[^:]+:\/*[^/]*$/;
164-
resolveUrl.protocol = /^([^:]+:)[\s\S]*$/;
165-
resolveUrl.domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
166175

167-
function noop() {}
168-
noop.exec = noop;
176+
const noopTest = { exec: function noopTest() {} };
169177

170178
function merge(obj) {
171179
let i = 1,
@@ -277,7 +285,7 @@ var helpers = {
277285
edit,
278286
cleanUrl,
279287
resolveUrl,
280-
noop,
288+
noopTest,
281289
merge,
282290
splitCells,
283291
rtrim,
@@ -286,7 +294,7 @@ var helpers = {
286294
};
287295

288296
const {
289-
noop: noop$1,
297+
noopTest: noopTest$1,
290298
edit: edit$1,
291299
merge: merge$1
292300
} = helpers;
@@ -313,8 +321,8 @@ const block = {
313321
+ '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
314322
+ ')',
315323
def: /^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
316-
nptable: noop$1,
317-
table: noop$1,
324+
nptable: noopTest$1,
325+
table: noopTest$1,
318326
lheading: /^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,
319327
// regex template, placeholders will be replaced according to different paragraph
320328
// interruption rules of commonmark and the original markdown spec:
@@ -401,7 +409,7 @@ block.pedantic = merge$1({}, block.normal, {
401409
.getRegex(),
402410
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
403411
heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
404-
fences: noop$1, // fences not supported
412+
fences: noopTest$1, // fences not supported
405413
paragraph: edit$1(block.normal._paragraph)
406414
.replace('hr', block.hr)
407415
.replace('heading', ' *#{1,6} *[^\n]')
@@ -419,7 +427,7 @@ block.pedantic = merge$1({}, block.normal, {
419427
const inline = {
420428
escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
421429
autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
422-
url: noop$1,
430+
url: noopTest$1,
423431
tag: '^comment'
424432
+ '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
425433
+ '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
@@ -433,7 +441,7 @@ const inline = {
433441
em: /^_([^\s_])_(?!_)|^\*([^\s*<\[])\*(?!\*)|^_([^\s<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s<"][\s\S]*?[^\s\*])\*(?!\*|[^\spunctuation])|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,
434442
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
435443
br: /^( {2,}|\\)\n(?!\s*$)/,
436-
del: noop$1,
444+
del: noopTest$1,
437445
text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/
438446
};
439447

@@ -526,7 +534,7 @@ var rules = {
526534
inline
527535
};
528536

529-
const { defaults: defaults$1 } = defaults_1;
537+
const { defaults: defaults$1 } = defaults;
530538
const { block: block$1 } = rules;
531539
const {
532540
rtrim: rtrim$1,
@@ -929,7 +937,7 @@ var Lexer_1 = class Lexer {
929937
};
930938
};
931939

932-
const { defaults: defaults$2 } = defaults_1;
940+
const { defaults: defaults$2 } = defaults;
933941
const {
934942
cleanUrl: cleanUrl$1,
935943
escape: escape$2
@@ -1125,7 +1133,7 @@ var Slugger_1 = class Slugger {
11251133
};
11261134
};
11271135

1128-
const { defaults: defaults$3 } = defaults_1;
1136+
const { defaults: defaults$3 } = defaults;
11291137
const { inline: inline$1 } = rules;
11301138
const {
11311139
findClosingBracket: findClosingBracket$1,
@@ -1457,7 +1465,7 @@ var TextRenderer_1 = class TextRenderer {
14571465
}
14581466
};
14591467

1460-
const { defaults: defaults$4 } = defaults_1;
1468+
const { defaults: defaults$4 } = defaults;
14611469
const {
14621470
merge: merge$2,
14631471
unescape: unescape$1
@@ -1666,10 +1674,10 @@ const {
16661674
escape: escape$4
16671675
} = helpers;
16681676
const {
1669-
getDefaults: getDefaults$1,
1670-
changeDefaults: changeDefaults$1,
1677+
getDefaults,
1678+
changeDefaults,
16711679
defaults: defaults$5
1672-
} = defaults_1;
1680+
} = defaults;
16731681

16741682
/**
16751683
* Marked
@@ -1775,11 +1783,11 @@ function marked(src, opt, callback) {
17751783
marked.options =
17761784
marked.setOptions = function(opt) {
17771785
merge$3(marked.defaults, opt);
1778-
changeDefaults$1(marked.defaults);
1786+
changeDefaults(marked.defaults);
17791787
return marked;
17801788
};
17811789

1782-
marked.getDefaults = getDefaults$1;
1790+
marked.getDefaults = getDefaults;
17831791

17841792
marked.defaults = defaults$5;
17851793

0 commit comments

Comments
 (0)