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:
parent
3733858145
commit
6a41d6e85a
@ -21,7 +21,11 @@ class Command extends BaseCommand {
|
|||||||
.filter(m => m.type === 'importer')
|
.filter(m => m.type === 'importer')
|
||||||
.map(m => m.format);
|
.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) {
|
async action(args) {
|
||||||
@ -55,9 +59,9 @@ class Command extends BaseCommand {
|
|||||||
this.stdout(s);
|
this.stdout(s);
|
||||||
};
|
};
|
||||||
|
|
||||||
app()
|
if (args.options.outputFormat) importOptions.outputFormat = args.options.outputFormat;
|
||||||
.gui()
|
|
||||||
.showConsole();
|
app().gui().showConsole();
|
||||||
this.stdout(_('Importing notes...'));
|
this.stdout(_('Importing notes...'));
|
||||||
const service = new InteropService();
|
const service = new InteropService();
|
||||||
const result = await service.import(importOptions);
|
const result = await service.import(importOptions);
|
||||||
|
@ -52,8 +52,6 @@ BaseItem.loadClass('Revision', Revision);
|
|||||||
Setting.setConstant('appId', `net.cozic.joplin${env === 'dev' ? 'dev' : ''}-cli`);
|
Setting.setConstant('appId', `net.cozic.joplin${env === 'dev' ? 'dev' : ''}-cli`);
|
||||||
Setting.setConstant('appType', 'cli');
|
Setting.setConstant('appType', 'cli');
|
||||||
|
|
||||||
console.info(Setting.value('appId'));
|
|
||||||
|
|
||||||
shimInit();
|
shimInit();
|
||||||
|
|
||||||
const application = app();
|
const application = app();
|
||||||
|
@ -55,6 +55,7 @@ class InteropService {
|
|||||||
description: _('Evernote Export File (as HTML)'),
|
description: _('Evernote Export File (as HTML)'),
|
||||||
// TODO: Consider doing this the same way as the multiple `md` importers are handled
|
// TODO: Consider doing this the same way as the multiple `md` importers are handled
|
||||||
importerClass: 'InteropService_Importer_EnexToHtml',
|
importerClass: 'InteropService_Importer_EnexToHtml',
|
||||||
|
outputFormat: 'html',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -97,14 +98,11 @@ class InteropService {
|
|||||||
|
|
||||||
importModules = importModules.map(a => {
|
importModules = importModules.map(a => {
|
||||||
const className = a.importerClass || `InteropService_Importer_${toTitleCase(a.format)}`;
|
const className = a.importerClass || `InteropService_Importer_${toTitleCase(a.format)}`;
|
||||||
const output = Object.assign(
|
const output = Object.assign({}, {
|
||||||
{},
|
type: 'importer',
|
||||||
{
|
path: `lib/services/${className}`,
|
||||||
type: 'importer',
|
outputFormat: 'md',
|
||||||
path: `lib/services/${className}`,
|
}, a);
|
||||||
},
|
|
||||||
a
|
|
||||||
);
|
|
||||||
if (!('isNoteArchive' in output)) output.isNoteArchive = true;
|
if (!('isNoteArchive' in output)) output.isNoteArchive = true;
|
||||||
return output;
|
return output;
|
||||||
});
|
});
|
||||||
@ -142,15 +140,17 @@ class InteropService {
|
|||||||
// or exporters, such as ENEX. In this case, the one marked as "isDefault"
|
// 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.
|
// is returned. This is useful to auto-detect the module based on the format.
|
||||||
// For more precise matching, newModuleFromPath_ should be used.
|
// 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 modules = this.modules();
|
||||||
const matches = [];
|
const matches = [];
|
||||||
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) {
|
if (m.format === format && m.type === type) {
|
||||||
if (target === null) {
|
if (!target && !outputFormat) {
|
||||||
matches.push(m);
|
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);
|
matches.push(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,9 +169,9 @@ class InteropService {
|
|||||||
* https://github.com/laurent22/joplin/pull/1795#discussion_r322379121) but
|
* https://github.com/laurent22/joplin/pull/1795#discussion_r322379121) but
|
||||||
* we can do it if it ever becomes necessary.
|
* we can do it if it ever becomes necessary.
|
||||||
*/
|
*/
|
||||||
newModuleByFormat_(type, format) {
|
newModuleByFormat_(type, format, outputFormat = 'md') {
|
||||||
const moduleMetadata = this.findModuleByFormat_(type, format);
|
const moduleMetadata = this.findModuleByFormat_(type, format, null, outputFormat);
|
||||||
if (!moduleMetadata) throw new Error(_('Cannot load "%s" module for format "%s"', type, format));
|
if (!moduleMetadata) throw new Error(_('Cannot load "%s" module for format "%s" and output "%s"', type, format, outputFormat));
|
||||||
const ModuleClass = require(moduleMetadata.path);
|
const ModuleClass = require(moduleMetadata.path);
|
||||||
const output = new ModuleClass();
|
const output = new ModuleClass();
|
||||||
output.setMetadata(moduleMetadata);
|
output.setMetadata(moduleMetadata);
|
||||||
@ -243,15 +243,12 @@ class InteropService {
|
|||||||
|
|
||||||
let result = { warnings: [] };
|
let result = { warnings: [] };
|
||||||
|
|
||||||
// console.log('options passed to InteropService:');
|
|
||||||
// console.log(JSON.stringify({options}, null, 2));
|
|
||||||
|
|
||||||
let importer = null;
|
let importer = null;
|
||||||
|
|
||||||
if (options.modulePath) {
|
if (options.modulePath) {
|
||||||
importer = this.newModuleFromPath_('importer', options);
|
importer = this.newModuleFromPath_('importer', options);
|
||||||
} else {
|
} else {
|
||||||
importer = this.newModuleByFormat_('importer', options.format);
|
importer = this.newModuleByFormat_('importer', options.format, options.outputFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
await importer.init(options.path, options);
|
await importer.init(options.path, options);
|
||||||
|
Loading…
Reference in New Issue
Block a user