mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
All: Resolves #644: Added support for .markdown extension when importing files
This commit is contained in:
parent
0027cb9036
commit
595fd7a9aa
@ -11,7 +11,7 @@ class InteropServiceHelper {
|
||||
|
||||
if (module.target === 'file') {
|
||||
path = bridge().showSaveDialog({
|
||||
filters: [{ name: module.description, extensions: [module.fileExtension]}]
|
||||
filters: [{ name: module.description, extensions: module.fileExtension}]
|
||||
});
|
||||
} else {
|
||||
path = bridge().showOpenDialog({
|
||||
|
@ -285,7 +285,7 @@ class Application extends BaseApplication {
|
||||
|
||||
if (moduleSource === 'file') {
|
||||
path = bridge().showOpenDialog({
|
||||
filters: [{ name: module.description, extensions: [module.fileExtension]}]
|
||||
filters: [{ name: module.description, extensions: module.fileExtensions}]
|
||||
});
|
||||
} else {
|
||||
path = bridge().showOpenDialog({
|
||||
|
@ -27,12 +27,12 @@ class InteropService {
|
||||
let importModules = [
|
||||
{
|
||||
format: 'jex',
|
||||
fileExtension: 'jex',
|
||||
fileExtensions: ['jex'],
|
||||
sources: ['file'],
|
||||
description: _('Joplin Export File'),
|
||||
}, {
|
||||
format: 'md',
|
||||
fileExtension: 'md',
|
||||
fileExtensions: ['md', 'markdown'],
|
||||
sources: ['file', 'directory'],
|
||||
isNoteArchive: false, // Tells whether the file can contain multiple notes (eg. Enex or Jex format)
|
||||
description: _('Markdown'),
|
||||
@ -42,7 +42,7 @@ class InteropService {
|
||||
description: _('Joplin Export Directory'),
|
||||
}, {
|
||||
format: 'enex',
|
||||
fileExtension: 'enex',
|
||||
fileExtensions: ['enex'],
|
||||
sources: ['file'],
|
||||
description: _('Evernote Export File'),
|
||||
},
|
||||
@ -51,7 +51,7 @@ class InteropService {
|
||||
let exportModules = [
|
||||
{
|
||||
format: 'jex',
|
||||
fileExtension: 'jex',
|
||||
fileExtensions: ['jex'],
|
||||
target: 'file',
|
||||
description: _('Joplin Export File'),
|
||||
}, {
|
||||
@ -108,7 +108,9 @@ class InteropService {
|
||||
const module = this.moduleByFormat_(type, format);
|
||||
if (!module) throw new Error(_('Cannot load "%s" module for format "%s"', type, format));
|
||||
const ModuleClass = require(module.path);
|
||||
return new ModuleClass();
|
||||
const output = new ModuleClass();
|
||||
output.setMetadata(module);
|
||||
return output;
|
||||
}
|
||||
|
||||
moduleByFileExtension_(type, ext) {
|
||||
@ -119,7 +121,7 @@ class InteropService {
|
||||
for (let i = 0; i < modules.length; i++) {
|
||||
const m = modules[i];
|
||||
if (type !== m.type) continue;
|
||||
if (m.fileExtension === ext) return m;
|
||||
if (m.fileExtensions.indexOf(ext) >= 0) return m;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -5,6 +5,14 @@ class InteropService_Exporter_Base {
|
||||
async processResource(resource, filePath) {}
|
||||
async close() {}
|
||||
|
||||
setMetadata(md) {
|
||||
this.metadata_ = md;
|
||||
}
|
||||
|
||||
metadata() {
|
||||
return this.metadata_;
|
||||
}
|
||||
|
||||
async temporaryDirectory_(createIt) {
|
||||
const md5 = require('md5');
|
||||
const tempDir = require('os').tmpdir() + '/' + md5(Math.random() + Date.now());
|
||||
|
@ -1,5 +1,13 @@
|
||||
class InteropService_Importer_Base {
|
||||
|
||||
setMetadata(md) {
|
||||
this.metadata_ = md;
|
||||
}
|
||||
|
||||
metadata() {
|
||||
return this.metadata_;
|
||||
}
|
||||
|
||||
async init(sourcePath, options) {
|
||||
this.sourcePath_ = sourcePath;
|
||||
this.options_ = options;
|
||||
|
@ -21,12 +21,14 @@ class InteropService_Importer_Md extends InteropService_Importer_Base {
|
||||
async exec(result) {
|
||||
let parentFolderId = null;
|
||||
|
||||
const supportedFileExtension = this.metadata().fileExtensions;
|
||||
|
||||
const filePaths = [];
|
||||
if (await shim.fsDriver().isDirectory(this.sourcePath_)) {
|
||||
const stats = await shim.fsDriver().readDirStats(this.sourcePath_);
|
||||
for (let i = 0; i < stats.length; i++) {
|
||||
const stat = stats[i];
|
||||
if (fileExtension(stat.path).toLowerCase() === 'md') {
|
||||
if (supportedFileExtension.indexOf(fileExtension(stat.path).toLowerCase()) >= 0) {
|
||||
filePaths.push(this.sourcePath_ + '/' + stat.path);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user