You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
All: Fixes #992: Allow non-ASCII chars when exporting MD and handle duplicate filenames
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
const { _ } = require('lib/locale');
|
||||
|
||||
function dirname(path) {
|
||||
if (!path) throw new Error('Path is empty');
|
||||
let s = path.split(/\/|\\/);
|
||||
@ -11,9 +13,9 @@ function basename(path) {
|
||||
return s[s.length - 1];
|
||||
}
|
||||
|
||||
function filename(path) {
|
||||
function filename(path, includeDir = false) {
|
||||
if (!path) throw new Error('Path is empty');
|
||||
let output = basename(path);
|
||||
let output = includeDir ? path : basename(path);
|
||||
if (output.indexOf('.') < 0) return output;
|
||||
|
||||
output = output.split('.');
|
||||
@ -48,6 +50,47 @@ function safeFilename(e, maxLength = null, allowSpaces = false) {
|
||||
return output.substr(0, maxLength);
|
||||
}
|
||||
|
||||
let friendlySafeFilename_blackListChars = '/<>:\'"\\|?*';
|
||||
for (let i = 0; i < 32; i++) {
|
||||
friendlySafeFilename_blackListChars += String.fromCharCode(i);
|
||||
}
|
||||
|
||||
const friendlySafeFilename_blackListNames = [".", "..", "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"];
|
||||
|
||||
function friendlySafeFilename(e, maxLength = null) {
|
||||
if (maxLength === null) maxLength = 255;
|
||||
if (!e || !e.replace) return _('Untitled');
|
||||
|
||||
let output = '';
|
||||
for (let i = 0; i < e.length; i++) {
|
||||
const c = e[i];
|
||||
if (friendlySafeFilename_blackListChars.indexOf(c) >= 0) {
|
||||
output += '_';
|
||||
} else {
|
||||
output += c;
|
||||
}
|
||||
}
|
||||
|
||||
if (output.length <= 4) {
|
||||
if (friendlySafeFilename_blackListNames.indexOf(output.toUpperCase()) >= 0) {
|
||||
output = '___';
|
||||
}
|
||||
}
|
||||
|
||||
while (output.length) {
|
||||
const c = output[output.length - 1];
|
||||
if (c === ' ' || c === '.') {
|
||||
output = output.substr(0, output.length - 1);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!output) return _('Untitled');
|
||||
|
||||
return output.substr(0, maxLength);
|
||||
}
|
||||
|
||||
function toSystemSlashes(path, os = null) {
|
||||
if (os === null) os = process.platform;
|
||||
if (os === 'win32') return path.replace(/\//g, "\\");
|
||||
@ -62,4 +105,4 @@ function ltrimSlashes(path) {
|
||||
return path.replace(/^\/+/, '');
|
||||
}
|
||||
|
||||
module.exports = { basename, dirname, filename, isHidden, fileExtension, safeFilename, safeFileExtension, toSystemSlashes, rtrimSlashes, ltrimSlashes };
|
||||
module.exports = { basename, dirname, filename, isHidden, fileExtension, safeFilename, friendlySafeFilename, safeFileExtension, toSystemSlashes, rtrimSlashes, ltrimSlashes };
|
Reference in New Issue
Block a user