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

Cli: Allow importing ENEX files as HTML

This commit is contained in:
Laurent Cozic 2020-06-14 16:45:17 +00:00
parent 3733858145
commit 6a41d6e85a
3 changed files with 23 additions and 24 deletions

View File

@ -21,7 +21,11 @@ class Command extends BaseCommand {
.filter(m => m.type === 'importer')
.map(m => m.format);
return [['--format <format>', _('Source format: %s', ['auto'].concat(formats).join(', '))], ['-f, --force', _('Do not ask for confirmation.')]];
return [
['--format <format>', _('Source format: %s', ['auto'].concat(formats).join(', '))],
['-f, --force', _('Do not ask for confirmation.')],
['--output-format <output-format>', _('Output format: %s', 'md, html')],
];
}
async action(args) {
@ -55,9 +59,9 @@ class Command extends BaseCommand {
this.stdout(s);
};
app()
.gui()
.showConsole();
if (args.options.outputFormat) importOptions.outputFormat = args.options.outputFormat;
app().gui().showConsole();
this.stdout(_('Importing notes...'));
const service = new InteropService();
const result = await service.import(importOptions);

View File

@ -52,8 +52,6 @@ BaseItem.loadClass('Revision', Revision);
Setting.setConstant('appId', `net.cozic.joplin${env === 'dev' ? 'dev' : ''}-cli`);
Setting.setConstant('appType', 'cli');
console.info(Setting.value('appId'));
shimInit();
const application = app();

View File

@ -55,6 +55,7 @@ class InteropService {
description: _('Evernote Export File (as HTML)'),
// TODO: Consider doing this the same way as the multiple `md` importers are handled
importerClass: 'InteropService_Importer_EnexToHtml',
outputFormat: 'html',
},
];
@ -97,14 +98,11 @@ class InteropService {
importModules = importModules.map(a => {
const className = a.importerClass || `InteropService_Importer_${toTitleCase(a.format)}`;
const output = Object.assign(
{},
{
type: 'importer',
path: `lib/services/${className}`,
},
a
);
const output = Object.assign({}, {
type: 'importer',
path: `lib/services/${className}`,
outputFormat: 'md',
}, a);
if (!('isNoteArchive' in output)) output.isNoteArchive = true;
return output;
});
@ -142,15 +140,17 @@ class InteropService {
// 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, target = null) {
findModuleByFormat_(type, format, target = null, outputFormat = null) {
const modules = this.modules();
const matches = [];
for (let i = 0; i < modules.length; i++) {
const m = modules[i];
if (m.format === format && m.type === type) {
if (target === null) {
if (!target && !outputFormat) {
matches.push(m);
} else if (target === m.target) {
} else if (target && target === m.target) {
matches.push(m);
} else if (outputFormat && outputFormat === m.outputFormat) {
matches.push(m);
}
}
@ -169,9 +169,9 @@ class InteropService {
* https://github.com/laurent22/joplin/pull/1795#discussion_r322379121) but
* we can do it if it ever becomes necessary.
*/
newModuleByFormat_(type, format) {
const moduleMetadata = this.findModuleByFormat_(type, format);
if (!moduleMetadata) throw new Error(_('Cannot load "%s" module for format "%s"', type, format));
newModuleByFormat_(type, format, outputFormat = 'md') {
const moduleMetadata = this.findModuleByFormat_(type, format, null, outputFormat);
if (!moduleMetadata) throw new Error(_('Cannot load "%s" module for format "%s" and output "%s"', type, format, outputFormat));
const ModuleClass = require(moduleMetadata.path);
const output = new ModuleClass();
output.setMetadata(moduleMetadata);
@ -243,15 +243,12 @@ class InteropService {
let result = { warnings: [] };
// console.log('options passed to InteropService:');
// console.log(JSON.stringify({options}, null, 2));
let importer = null;
if (options.modulePath) {
importer = this.newModuleFromPath_('importer', options);
} else {
importer = this.newModuleByFormat_('importer', options.format);
importer = this.newModuleByFormat_('importer', options.format, options.outputFormat);
}
await importer.init(options.path, options);