1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Revert "Desktop, Cli: Fixed interop service so that it still allow auto-detecting importer based on format (required for Cli and for test units)"

Reverting PR #1795 due to broken MD import and other issues

This reverts commit 558b6443bc.
This commit is contained in:
Laurent Cozic 2019-09-20 22:13:34 +01:00
parent 558b6443bc
commit c7c57ab2a5

View File

@ -43,7 +43,6 @@ class InteropService {
sources: ['file'], sources: ['file'],
description: _('Evernote Export File (as Markdown)'), description: _('Evernote Export File (as Markdown)'),
importerClass: 'InteropService_Importer_EnexToMd', importerClass: 'InteropService_Importer_EnexToMd',
isDefault: true,
}, },
{ {
format: 'enex', format: 'enex',
@ -121,23 +120,14 @@ class InteropService {
return this.modules_; return this.modules_;
} }
// Find the module that matches the given type ("importer" or "exporter")
// and the given format. Some formats can have multiple assocated importers
// or exporters, such as ENEX. In this case, the one marked as "isDefault"
// is returned. This is useful to auto-detect the module based on the format.
// For more precise matching, newModuleFromPath_ should be used.
findModuleByFormat_(type, format) { findModuleByFormat_(type, format) {
const modules = this.modules(); const modules = this.modules();
const matches = []; // console.log(JSON.stringify({modules}, null, 2))
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 (m.format === format && m.type === type) matches.push(modules[i]); if (m.format === format && m.type === type) return modules[i];
} }
return null;
const output = matches.find(m => !!m.isDefault);
if (output) return output;
return matches.length ? matches[0] : null;
} }
newModuleByFormat_(type, format) { newModuleByFormat_(type, format) {
@ -155,6 +145,10 @@ class InteropService {
* but now that we have 2 possible outputs for an `enex` input, we need to be * but now that we have 2 possible outputs for an `enex` input, we need to be
* explicit with which importer we want to use. * explicit with which importer we want to use.
* *
* In the long run, it might make sense to simply move all the existing
* formatters to the `newModuleFromPath_` approach, so that there's only one
* way to do this mapping.
*
* https://github.com/laurent22/joplin/pull/1795#pullrequestreview-281574417 * https://github.com/laurent22/joplin/pull/1795#pullrequestreview-281574417
*/ */
newModuleFromPath_(options) { newModuleFromPath_(options) {
@ -211,14 +205,7 @@ class InteropService {
// console.log('options passed to InteropService:'); // console.log('options passed to InteropService:');
// console.log(JSON.stringify({options}, null, 2)); // console.log(JSON.stringify({options}, null, 2));
let importer = null; const importer = this.newModuleFromPath_(options);
if (options.modulePath) {
importer = this.newModuleFromPath_(options);
} else {
importer = this.newModuleByFormat_('importer', options.format);
}
await importer.init(options.path, options); await importer.init(options.path, options);
result = await importer.exec(result); result = await importer.exec(result);