single-file-core 1.2.13 → 1.2.14
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/core/helper.js +3 -1
- package/core/index.js +2 -2
- package/core/util.js +5 -5
- package/modules/template-formatter.js +15164 -135
- package/modules/template-grammar.txt +14 -0
- package/modules/template-parser.js +856 -0
- package/package.json +1 -1
package/core/helper.js
CHANGED
|
@@ -496,7 +496,9 @@ function getStylesheetsData(doc) {
|
|
|
496
496
|
doc.body.appendChild(tempStyleElement);
|
|
497
497
|
const stylesheet = tempStyleElement.sheet;
|
|
498
498
|
tempStyleElement.remove();
|
|
499
|
-
|
|
499
|
+
const textContentStylesheet = Array.from(stylesheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
|
|
500
|
+
const sheetStylesheet = Array.from(styleElement.sheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
|
|
501
|
+
if (!stylesheet || textContentStylesheet != sheetStylesheet) {
|
|
500
502
|
styleElement.setAttribute(STYLESHEET_ATTRIBUTE_NAME, styleIndex);
|
|
501
503
|
contents[styleIndex] = Array.from(styleElement.sheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
|
|
502
504
|
}
|
package/core/index.js
CHANGED
|
@@ -569,7 +569,7 @@ class Processor {
|
|
|
569
569
|
this.stats.set("processed", "HTML bytes", contentSize);
|
|
570
570
|
this.stats.add("discarded", "HTML bytes", size - contentSize);
|
|
571
571
|
}
|
|
572
|
-
const filename = await util.formatFilename(content, this.options);
|
|
572
|
+
const filename = await util.formatFilename(content, this.doc, this.options);
|
|
573
573
|
const matchTitle = this.baseURI.match(/([^/]*)\/?(\.html?.*)$/) || this.baseURI.match(/\/\/([^/]*)\/?$/);
|
|
574
574
|
const additionalData = this.processorHelper.getAdditionalPageData(this.doc, content, this.resources);
|
|
575
575
|
const pageData = Object.assign({
|
|
@@ -1427,7 +1427,7 @@ class Processor {
|
|
|
1427
1427
|
publisher: publisherElement && publisherElement.content ? publisherElement.content.trim() : "",
|
|
1428
1428
|
heading: headingElement && headingElement.textContent ? headingElement.textContent.trim() : ""
|
|
1429
1429
|
};
|
|
1430
|
-
this.options.infobarContent = await util.evalTemplate(this.options.infobarTemplate, this.options, null, true);
|
|
1430
|
+
this.options.infobarContent = await util.evalTemplate(this.options.infobarTemplate, this.options, null, this.doc, true);
|
|
1431
1431
|
}
|
|
1432
1432
|
}
|
|
1433
1433
|
|
package/core/util.js
CHANGED
|
@@ -130,11 +130,11 @@ function getInstance(utilOptions) {
|
|
|
130
130
|
getContentSize(content) {
|
|
131
131
|
return new Blob([content]).size;
|
|
132
132
|
},
|
|
133
|
-
formatFilename(content, options) {
|
|
134
|
-
return modules.templateFormatter.formatFilename(content, options, this);
|
|
133
|
+
formatFilename(content, doc, options) {
|
|
134
|
+
return modules.templateFormatter.formatFilename(content, doc, options, this);
|
|
135
135
|
},
|
|
136
|
-
evalTemplate(template, options, content, dontReplaceSlash) {
|
|
137
|
-
return modules.templateFormatter.evalTemplate(template, options, this, content, dontReplaceSlash);
|
|
136
|
+
async evalTemplate(template, options, content, doc, dontReplaceSlash) {
|
|
137
|
+
return modules.templateFormatter.evalTemplate(template, options, this, content, doc, dontReplaceSlash);
|
|
138
138
|
},
|
|
139
139
|
minifyHTML(doc, options) {
|
|
140
140
|
return modules.htmlMinifier.process(doc, options);
|
|
@@ -313,7 +313,7 @@ function getInstance(utilOptions) {
|
|
|
313
313
|
async function getFetchResponse(resourceURL, options, data, charset, contentType) {
|
|
314
314
|
if (data) {
|
|
315
315
|
if (options.asBinary) {
|
|
316
|
-
if (options.inline)
|
|
316
|
+
if (options.inline) {
|
|
317
317
|
const reader = new FileReader();
|
|
318
318
|
reader.readAsDataURL(new Blob([data], { type: contentType + (options.charset ? ";charset=" + options.charset : "") }));
|
|
319
319
|
data = await new Promise((resolve, reject) => {
|