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

Fixed enex issue

This commit is contained in:
Laurent Cozic 2017-07-13 19:16:01 +00:00
parent 7859a1b990
commit e28ccdb05a
3 changed files with 53 additions and 3 deletions

View File

@ -18,6 +18,7 @@ class Command extends BaseCommand {
options() {
return [
['-f, --force', 'Do not ask for confirmation.'],
['--fuzzy-matching', 'For debugging purposes. Do not use.'],
];
}
@ -26,11 +27,12 @@ class Command extends BaseCommand {
let filePath = args.file;
let folder = null;
let folderTitle = args['notebook'];
let force = args.options.force === true;
if (folderTitle) {
folder = await Folder.loadByField('title', folderTitle);
if (!folder) {
let ok = await vorpalUtils.cmdPromptConfirm(this, _('Folder does not exists: "%s". Create it?', folderTitle))
let ok = force ? true : await vorpalUtils.cmdPromptConfirm(this, _('Folder does not exists: "%s". Create it?', folderTitle))
if (!ok) return;
folder = await Folder.save({ title: folderTitle });
@ -50,7 +52,7 @@ class Command extends BaseCommand {
}
}
let ok = await vorpalUtils.cmdPromptConfirm(this, _('File "%s" will be imported into notebook "%s". Continue?', basename(filePath), folderTitle))
let ok = force ? true : await vorpalUtils.cmdPromptConfirm(this, _('File "%s" will be imported into notebook "%s". Continue?', basename(filePath), folderTitle))
if (!ok) return;
let options = {

View File

@ -244,6 +244,30 @@ function enexXmlToMdArray(stream, resources) {
output = collapseWhiteSpaceAndAppend(output, state, text);
})
// Section: {
// type: "block/table/tr/td",
// lines: []
// }
// [
// {
// type: "text",
// lines: [],
// },
// {
// type: "table",
// trs: [
// {
// tds: [
// {
// lines: [],
// }
// ],
// }
// ],
// ]
saxStream.on('opentag', function(node) {
let n = node.name.toLowerCase();
if (n == 'en-note') {
@ -396,7 +420,24 @@ function enexXmlToMdArray(stream, resources) {
} else if (isAnchor(n)) {
let attributes = state.anchorAttributes.pop();
let url = attributes && attributes.href ? attributes.href : '';
output.push('](' + url + ')');
if (output.length < 1) throw new Error('Invalid anchor tag closing'); // Sanity check, but normally not possible
// When closing the anchor tag, check if there's is any text content. If not
// put the URL as is (don't wrap it in [](url)). The markdown parser, using
// GitHub flavour, will turn this URL into a link. This is to generate slightly
// cleaner markdown.
let previous = output[output.length - 1];
if (previous == '[') {
output.pop();
output.push(url);
} else if (!previous || previous == url) {
output.pop();
output.pop();
output.push(url);
} else {
output.push('](' + url + ')');
}
} else if (isListTag(n)) {
output.push(BLOCK_CLOSE);
state.lists.pop();
@ -427,6 +468,7 @@ function enexXmlToMdArray(stream, resources) {
async function enexXmlToMd(stream, resources) {
let result = await enexXmlToMdArray(stream, resources);
let mdLines = result.lines;
let firstAttachment = true;
for (let i = 0; i < result.resources.length; i++) {
@ -437,6 +479,8 @@ async function enexXmlToMd(stream, resources) {
firstAttachment = false;
}
//console.info(mdLines);
return processMdArrayNewLines(mdLines);
}

View File

@ -223,6 +223,10 @@ function importEnex(parentFolderId, filePath, importOptions = null) {
return enexXmlToMd(contentStream, note.resources).then((body) => {
delete note.bodyXml;
//console.info('-----------------------------------------------------------');
//console.info(body);
//console.info('-----------------------------------------------------------');
note.id = uuid.create();
note.parent_id = parentFolderId;
note.body = body;