single-file-core 1.7.1 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/modules/template-formatter.js +47 -8
- package/package.json +1 -1
- package/single-file.js +3 -0
|
@@ -33,6 +33,23 @@ const URLSearchParams = globalThis.URLSearchParams;
|
|
|
33
33
|
const navigator = globalThis.navigator;
|
|
34
34
|
|
|
35
35
|
const REGEXP_ESCAPE = /([{}()^$&.*?/+|[\\\\]|\]|-)/g;
|
|
36
|
+
const REGEXP_ENTITY = /&(#\d+|#[xX][\da-fA-F]+|[a-zA-Z][a-zA-Z\d]*);/g;
|
|
37
|
+
const NAMED_ENTITIES = {
|
|
38
|
+
amp: "&", lt: "<", gt: ">", quot: "\"", apos: "'", nbsp: " ",
|
|
39
|
+
copy: "©", reg: "®", trade: "™", deg: "°",
|
|
40
|
+
ndash: "–", mdash: "—", hellip: "…", middot: "·", bull: "•",
|
|
41
|
+
lsquo: "‘", rsquo: "’", ldquo: "“", rdquo: "”", laquo: "«", raquo: "»",
|
|
42
|
+
euro: "€", pound: "£", yen: "¥", cent: "¢", sect: "§", para: "¶",
|
|
43
|
+
times: "×", divide: "÷", plusmn: "±", frac12: "½", frac14: "¼", frac34: "¾",
|
|
44
|
+
agrave: "à", aacute: "á", acirc: "â", atilde: "ã", auml: "ä", aring: "å", aelig: "æ", ccedil: "ç",
|
|
45
|
+
egrave: "è", eacute: "é", ecirc: "ê", euml: "ë", igrave: "ì", iacute: "í", icirc: "î", iuml: "ï",
|
|
46
|
+
ntilde: "ñ", ograve: "ò", oacute: "ó", ocirc: "ô", otilde: "õ", ouml: "ö", oslash: "ø",
|
|
47
|
+
ugrave: "ù", uacute: "ú", ucirc: "û", uuml: "ü", yacute: "ý", yuml: "ÿ", szlig: "ß",
|
|
48
|
+
Agrave: "À", Aacute: "Á", Acirc: "Â", Atilde: "Ã", Auml: "Ä", Aring: "Å", AElig: "Æ", Ccedil: "Ç",
|
|
49
|
+
Egrave: "È", Eacute: "É", Ecirc: "Ê", Euml: "Ë", Igrave: "Ì", Iacute: "Í", Icirc: "Î", Iuml: "Ï",
|
|
50
|
+
Ntilde: "Ñ", Ograve: "Ò", Oacute: "Ó", Ocirc: "Ô", Otilde: "Õ", Ouml: "Ö", Oslash: "Ø",
|
|
51
|
+
Ugrave: "Ù", Uacute: "Ú", Ucirc: "Û", Uuml: "Ü", Yacute: "Ý"
|
|
52
|
+
};
|
|
36
53
|
|
|
37
54
|
const EMOJI_NAMES = {
|
|
38
55
|
"😀": "grinning-face",
|
|
@@ -16930,13 +16947,13 @@ async function evalTemplate(template = "", options, content, doc, context = {})
|
|
|
16930
16947
|
}
|
|
16931
16948
|
const variables = {
|
|
16932
16949
|
"navigator-language": { getter: () => navigator.language },
|
|
16933
|
-
"page-title": { getter: () => options.title },
|
|
16934
|
-
"page-heading": { getter: () => options.info.heading },
|
|
16950
|
+
"page-title": { getter: () => decodeEntities(options.title) },
|
|
16951
|
+
"page-heading": { getter: () => decodeEntities(options.info.heading) },
|
|
16935
16952
|
"page-language": { getter: () => options.info.lang },
|
|
16936
|
-
"page-description": { getter: () => options.info.description },
|
|
16937
|
-
"page-author": { getter: () => options.info.author },
|
|
16938
|
-
"page-creator": { getter: () => options.info.creator },
|
|
16939
|
-
"page-publisher": { getter: () => options.info.publisher },
|
|
16953
|
+
"page-description": { getter: () => decodeEntities(options.info.description) },
|
|
16954
|
+
"page-author": { getter: () => decodeEntities(options.info.author) },
|
|
16955
|
+
"page-creator": { getter: () => decodeEntities(options.info.creator) },
|
|
16956
|
+
"page-publisher": { getter: () => decodeEntities(options.info.publisher) },
|
|
16940
16957
|
"url-hash": { getter: () => url.hash.substring(1) },
|
|
16941
16958
|
"url-host": { getter: () => url.host.replace(/\/$/, "") },
|
|
16942
16959
|
"url-hostname": { getter: () => url.hostname.replace(/\/$/, "") },
|
|
@@ -17226,7 +17243,7 @@ async function getValue(valueGetter, dontReplaceSlash, replacementCharacter, len
|
|
|
17226
17243
|
if (maxLength) {
|
|
17227
17244
|
value = await truncateText(value, maxLength);
|
|
17228
17245
|
} else if (maxCharLength) {
|
|
17229
|
-
value = value.
|
|
17246
|
+
value = Array.from(value).slice(0, maxCharLength).join("");
|
|
17230
17247
|
}
|
|
17231
17248
|
return value;
|
|
17232
17249
|
}
|
|
@@ -17235,7 +17252,7 @@ function extractMaxLength(lengthData) {
|
|
|
17235
17252
|
if (lengthData) {
|
|
17236
17253
|
const { unit, length } = lengthData;
|
|
17237
17254
|
let maxLength, maxCharLength;
|
|
17238
|
-
if (unit == "
|
|
17255
|
+
if (unit == "ch") {
|
|
17239
17256
|
maxCharLength = length;
|
|
17240
17257
|
} else {
|
|
17241
17258
|
maxLength = length;
|
|
@@ -17255,6 +17272,28 @@ function decode(value) {
|
|
|
17255
17272
|
}
|
|
17256
17273
|
}
|
|
17257
17274
|
|
|
17275
|
+
function decodeEntities(value) {
|
|
17276
|
+
if (!value || !REGEXP_ENTITY.test(value)) {
|
|
17277
|
+
return value;
|
|
17278
|
+
}
|
|
17279
|
+
if (globalThis.DOMParser) {
|
|
17280
|
+
const doc = new globalThis.DOMParser().parseFromString("<textarea>" + value.replace(/<\/textarea/gi, "</textarea") + "</textarea>", "text/html");
|
|
17281
|
+
const textarea = doc.querySelector("textarea");
|
|
17282
|
+
if (textarea) {
|
|
17283
|
+
return textarea.textContent;
|
|
17284
|
+
}
|
|
17285
|
+
}
|
|
17286
|
+
return value.replace(REGEXP_ENTITY, (match, name) => {
|
|
17287
|
+
if (name.startsWith("#x") || name.startsWith("#X")) {
|
|
17288
|
+
return String.fromCodePoint(parseInt(name.substring(2), 16));
|
|
17289
|
+
} else if (name.startsWith("#")) {
|
|
17290
|
+
return String.fromCodePoint(parseInt(name.substring(1), 10));
|
|
17291
|
+
} else {
|
|
17292
|
+
return Object.hasOwn(NAMED_ENTITIES, name) ? NAMED_ENTITIES[name] : match;
|
|
17293
|
+
}
|
|
17294
|
+
});
|
|
17295
|
+
}
|
|
17296
|
+
|
|
17258
17297
|
function getLastSegment(url, replacementCharacter) {
|
|
17259
17298
|
let lastSegmentMatch = url.pathname.match(/\/([^/]+)$/),
|
|
17260
17299
|
lastSegment = lastSegmentMatch && lastSegmentMatch[0];
|
package/package.json
CHANGED
package/single-file.js
CHANGED
|
@@ -130,6 +130,9 @@ async function getPageData(options = {}, initOptions, doc, win) {
|
|
|
130
130
|
arrayBuffer = await blob.arrayBuffer();
|
|
131
131
|
}
|
|
132
132
|
pageData.content = Array.from(new Uint8Array(arrayBuffer));
|
|
133
|
+
if (options.addProof) {
|
|
134
|
+
pageData.hash = await helper.digest("SHA-256", new Uint8Array(arrayBuffer));
|
|
135
|
+
}
|
|
133
136
|
}
|
|
134
137
|
if (pageData.manifest) {
|
|
135
138
|
const content = options.compressContent ? new Uint8Array(pageData.content) : pageData.content;
|