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