Closed fireundubh closed 1 year ago
I do not think it is worth the work. This is a scripting engine, where those things can be handled by the user script. If we start with this, where should we stop with providing pre-processed data? @SamuelPlentz ? What do you think?
Worth the work? This is low-hanging fruit. These two functions appear in the Mozilla Toolkit:
function getFileExtension(path) {
if (!path) {
return "";
}
const lastIndex = path.lastIndexOf(".");
return lastIndex !== -1 ? path.slice(lastIndex + 1).toLowerCase() : "";
}
function getFileExtension(aFile) {
return Services.io.newFileURI(aFile).QueryInterface(Ci.nsIURL).fileExtension;
}
As for providing preprocessed data... that's a core feature of Quicktext, if not its entire purpose.
const persistentTags = ['COUNTER', 'ORGATT', 'ORGHEADER', 'VERSION'];
const allowedTags = ['ATT', 'CLIPBOARD', 'COUNTER', 'DATE', 'FILE', 'IMAGE', 'FROM', 'INPUT', 'ORGATT', 'ORGHEADER', 'SCRIPT', 'SUBJECT', 'TEXT', 'TIME', 'TO', 'URL', 'VERSION', 'SELECTION', 'HEADER'];
Am I to understand you're okay with preprocessing file names and file sizes but you draw the line at file extensions? 🤨
I think any pull request extending current possibilities is fine.
For a workaround one could for now use a custom script RemoveExtension
like this:
let text = this.mVariables[0];
text = text.replace(/(\.pdf|\.txt|\.docx)/ig, ""); // replace ".pdf", ".txt", ".docx"
return text;
It would be called like this:
[[SCRIPT=RemoveExtension|[[ATT=name|, ]]]]
My script-based solution was this:
let filename = await this.mQuicktext.get_att(["name"]);
const lastIndex = filename.lastIndexOf(".");
return lastIndex !== -1 ? filename.slice(0, lastIndex) : filename;
This works for any file extension. No idea what happens when there are multiple attachments.
You got a good point there. However, my code handles several files at a time, your code only one.
File1.pdf, File2.png, File3.txt
will convert to File1.txt, File2.png, File3
(your code)
File1.pdf, File2.png, File3.txt
will convert to File1, File2.png, File3
(my code)
Sorry did not mention you already mentioned this.
I think this can be closed, since you got a working solution.
Currently, variables exist for attachment file names and attachment file names with file sizes. A variable for attachment file names without file extensions would also be useful. For example,
Project Name.pdf
would become simplyProject Name
and could be more generally used throughout a template without needing to be manually revised.