Jelajahi Sumber

define a default value for the replacement char in filenames

Former-commit-id: 7df0a9b84cfde90a477f57a92d1030e09db5b79f
Gildas 6 tahun lalu
induk
melakukan
76e43cf224
2 mengubah file dengan 6 tambahan dan 1 penghapusan
  1. 4 0
      cli/single-file
  2. 2 1
      lib/single-file/single-file-util.js

+ 4 - 0
cli/single-file

@@ -47,6 +47,7 @@ const args = require("yargs")
 		"compress-CSS": true,
 		"compress-HTML": true,
 		"filename-template": "",
+		"filename-replacement-character": "_",
 		"group-duplicate-images": true,
 		"include-infobar": false,
 		"load-deferred-images": true,
@@ -96,6 +97,9 @@ const args = require("yargs")
 	.boolean("compress-HTML")
 	.options("filename-template", { description: "Template used to generate the output filename (see help page of the extension for more info)" })
 	.string("filename-template")
+	.options("filename-replacement-character", { description: "The character used for replacing invalid characters in filenames" })
+	.string("filename-replacement-character")
+	.string("filename-template")
 	.options("group-duplicate-images", { description: "Group duplicate images into CSS custom properties" })
 	.boolean("group-duplicate-images")
 	.options("include-infobar", { description: "Include the infobar" })

+ 2 - 1
lib/single-file/single-file-util.js

@@ -29,6 +29,7 @@ this.singlefile.lib.util = this.singlefile.lib.util || (() => {
 	const ONE_MB = 1024 * 1024;
 	const PREFIX_CONTENT_TYPE_TEXT = "text/";
 	const DEFAULT_REPLACED_CHARACTERS = ["~", "+", "\\\\", "?", "%", "*", ":", "|", "\"", "<", ">", "\x00-\x1f", "\x7F"];
+	const DEFAULT_REPLACEMENT_CHARACTER = "_";
 
 	const URL = window.URL;
 	const DOMParser = window.DOMParser;
@@ -83,7 +84,7 @@ this.singlefile.lib.util = this.singlefile.lib.util || (() => {
 				resolveURL(resourceURL, baseURI) {
 					return this.parseURL(resourceURL, baseURI).href;
 				},
-				getValidFilename(filename, replacedCharacters = DEFAULT_REPLACED_CHARACTERS, replacementCharacter) {
+				getValidFilename(filename, replacedCharacters = DEFAULT_REPLACED_CHARACTERS, replacementCharacter = DEFAULT_REPLACEMENT_CHARACTER) {
 					replacedCharacters.forEach(replacedCharacter => filename = filename.replace(new RegExp("[" + replacedCharacter + "]+", "g"), replacementCharacter));
 					filename = filename
 						.replace(/\.\.\//g, "")