mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-20 13:39:33 +01:00
Merge branch 'main' of https://github.com/streetwriters/notesnook
This commit is contained in:
52
packages/importer/__tests__/__snapshots__/keep.test.js.snap
Normal file
52
packages/importer/__tests__/__snapshots__/keep.test.js.snap
Normal file
File diff suppressed because one or more lines are too long
141
packages/importer/__tests__/__snapshots__/nimbus.test.js.snap
Normal file
141
packages/importer/__tests__/__snapshots__/nimbus.test.js.snap
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`convert simplenote backup zip file: nimbus-export 1`] = `
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"content": Object {
|
||||||
|
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
|
||||||
|
<div class=\\"editor-body\\">
|
||||||
|
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
|
||||||
|
</div>
|
||||||
|
</div>",
|
||||||
|
"type": "html",
|
||||||
|
},
|
||||||
|
"notebooks": Object {
|
||||||
|
"notebook": "My Notes",
|
||||||
|
"topic": "My Notes",
|
||||||
|
},
|
||||||
|
"title": "ringing the bell",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"content": Object {
|
||||||
|
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
|
||||||
|
<div class=\\"editor-body\\">
|
||||||
|
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
|
||||||
|
</div>
|
||||||
|
</div>",
|
||||||
|
"type": "html",
|
||||||
|
},
|
||||||
|
"notebooks": Object {
|
||||||
|
"notebook": "My Notes",
|
||||||
|
"topic": "My Notes",
|
||||||
|
},
|
||||||
|
"title": "Wow",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"content": Object {
|
||||||
|
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
|
||||||
|
<div class=\\"editor-body\\">
|
||||||
|
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
|
||||||
|
</div>
|
||||||
|
</div>",
|
||||||
|
"type": "html",
|
||||||
|
},
|
||||||
|
"notebooks": Object {
|
||||||
|
"notebook": "My Notes",
|
||||||
|
"topic": "My Notes",
|
||||||
|
},
|
||||||
|
"title": "This is a new day and I am writi",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"content": Object {
|
||||||
|
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
|
||||||
|
<div class=\\"editor-body\\">
|
||||||
|
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
|
||||||
|
</div>
|
||||||
|
</div>",
|
||||||
|
"type": "html",
|
||||||
|
},
|
||||||
|
"notebooks": Object {
|
||||||
|
"notebook": "My Notes",
|
||||||
|
"topic": "My Notes",
|
||||||
|
},
|
||||||
|
"title": "my note",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"content": Object {
|
||||||
|
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
|
||||||
|
<div class=\\"editor-body\\">
|
||||||
|
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
|
||||||
|
</div>
|
||||||
|
</div>",
|
||||||
|
"type": "html",
|
||||||
|
},
|
||||||
|
"notebooks": Object {
|
||||||
|
"notebook": "Bingo",
|
||||||
|
"topic": "Bingo",
|
||||||
|
},
|
||||||
|
"title": "Oh okay I am making a note now.",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"content": Object {
|
||||||
|
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
|
||||||
|
<div class=\\"editor-body\\">
|
||||||
|
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
|
||||||
|
</div>
|
||||||
|
</div>",
|
||||||
|
"type": "html",
|
||||||
|
},
|
||||||
|
"notebooks": Object {
|
||||||
|
"notebook": "Bingo",
|
||||||
|
"topic": "Rope",
|
||||||
|
},
|
||||||
|
"title": "New note",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"content": Object {
|
||||||
|
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
|
||||||
|
<div class=\\"editor-body\\">
|
||||||
|
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
|
||||||
|
</div>
|
||||||
|
</div>",
|
||||||
|
"type": "html",
|
||||||
|
},
|
||||||
|
"notebooks": Object {
|
||||||
|
"notebook": "Bingo",
|
||||||
|
"topic": "Rope",
|
||||||
|
},
|
||||||
|
"title": "New note",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"content": Object {
|
||||||
|
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
|
||||||
|
<div class=\\"editor-body\\">
|
||||||
|
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
|
||||||
|
</div>
|
||||||
|
</div>",
|
||||||
|
"type": "html",
|
||||||
|
},
|
||||||
|
"notebooks": Object {
|
||||||
|
"notebook": "Bingo",
|
||||||
|
"topic": "Rope",
|
||||||
|
},
|
||||||
|
"title": "home",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"content": Object {
|
||||||
|
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
|
||||||
|
<div class=\\"editor-body\\">
|
||||||
|
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
|
||||||
|
</div>
|
||||||
|
</div>",
|
||||||
|
"type": "html",
|
||||||
|
},
|
||||||
|
"notebooks": Object {
|
||||||
|
"notebook": "Bingo",
|
||||||
|
"topic": "Rope",
|
||||||
|
},
|
||||||
|
"title": "This is a new note that I am wor",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`;
|
||||||
Binary file not shown.
BIN
packages/importer/__tests__/fixtures/takeout.zip
Normal file
BIN
packages/importer/__tests__/fixtures/takeout.zip
Normal file
Binary file not shown.
8
packages/importer/__tests__/keep.test.js
Normal file
8
packages/importer/__tests__/keep.test.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const keep = require("../providers/keep");
|
||||||
|
const utils = require("./utils");
|
||||||
|
|
||||||
|
test("convert google keep backup", () => {
|
||||||
|
let file = utils.getFile("takeout.zip");
|
||||||
|
|
||||||
|
expect(keep.convert([file])).toMatchSnapshot("keep-backup");
|
||||||
|
});
|
||||||
7
packages/importer/__tests__/nimbus.test.js
Normal file
7
packages/importer/__tests__/nimbus.test.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
const nimbusnote = require("../providers/nimbusnote");
|
||||||
|
const utils = require("./utils");
|
||||||
|
|
||||||
|
test("convert simplenote backup zip file", () => {
|
||||||
|
let file = utils.getFile("export-2021-08-27_10-11-56.zip");
|
||||||
|
expect(nimbusnote.convert([file])).toMatchSnapshot("nimbus-export");
|
||||||
|
});
|
||||||
@@ -69,7 +69,7 @@ function isNotebook(notes, fileName) {
|
|||||||
* @returns the created notebook using file name
|
* @returns the created notebook using file name
|
||||||
*/
|
*/
|
||||||
function getNotebooks(fileName) {
|
function getNotebooks(fileName) {
|
||||||
return [{ notebook: getName(fileName), topic: "All notes" }];
|
return [{ notebook: extension.getName(fileName), topic: "All notes" }];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,6 +18,22 @@ const colors = {
|
|||||||
brown: "orange"
|
brown: "orange"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {object} keepNote A google keep note object
|
||||||
|
* @returns parsed html list from json.
|
||||||
|
*/
|
||||||
|
function makeListHtml(keepNote) {
|
||||||
|
let content = '<ul class="tox-checklist">';
|
||||||
|
for (item of keepNote.listContent) {
|
||||||
|
content += `<li class="${
|
||||||
|
item.isChecked ? "tox-checklist--checked" : ""
|
||||||
|
}" >${item.text}</li>`;
|
||||||
|
}
|
||||||
|
content += "</ul>";
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Array<{data:string | Buffer,createdAt:number,modifiedAt:number,fileName:string}>} files
|
* @param {Array<{data:string | Buffer,createdAt:number,modifiedAt:number,fileName:string}>} files
|
||||||
@@ -62,14 +78,7 @@ function convert(files) {
|
|||||||
note.tags = keepNote.labels.map((label) => label.name);
|
note.tags = keepNote.labels.map((label) => label.name);
|
||||||
}
|
}
|
||||||
if (keepNote.listContent) {
|
if (keepNote.listContent) {
|
||||||
let content = '<ul class="tox-checklist">';
|
note.content.data = makeListHtml(keepNote);
|
||||||
for (item of keepNote.listContent) {
|
|
||||||
content += `<li class="${
|
|
||||||
item.isChecked ? "tox-checklist--checked" : ""
|
|
||||||
}" >${item.text}</li>`;
|
|
||||||
}
|
|
||||||
content += "</ul>";
|
|
||||||
note.content.data = content;
|
|
||||||
}
|
}
|
||||||
if (keepNote.color && keepNote.color !== "DEFAULT") {
|
if (keepNote.color && keepNote.color !== "DEFAULT") {
|
||||||
note.color = colors[keepNote.color.toLowerCase()];
|
note.color = colors[keepNote.color.toLowerCase()];
|
||||||
|
|||||||
72
packages/importer/providers/nimbusnote.js
Normal file
72
packages/importer/providers/nimbusnote.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
const templates = require("../utils/template");
|
||||||
|
const uzip = require("uzip");
|
||||||
|
const extension = require("../utils/extension");
|
||||||
|
const parser = new window.DOMParser();
|
||||||
|
|
||||||
|
function getNotebook(path) {
|
||||||
|
let parts = path.split("/");
|
||||||
|
let notebook = parts[2];
|
||||||
|
let topic = "All notes";
|
||||||
|
if (parts.length > 3) {
|
||||||
|
topic = parts[parts.length - 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
notebook,
|
||||||
|
topic
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Array<{data:string | Buffer,createdAt:number,modifiedAt:number,fileName:string}>} files
|
||||||
|
* @returns array of notes
|
||||||
|
*/
|
||||||
|
function convert(files) {
|
||||||
|
let notes = [];
|
||||||
|
|
||||||
|
for (var file of files) {
|
||||||
|
let unzip = uzip.parse(file.data);
|
||||||
|
let items = Object.keys(unzip);
|
||||||
|
let zipName = extension.getName(file.fileName);
|
||||||
|
items = items.filter((i) => i.startsWith(zipName) && extension.get(i));
|
||||||
|
|
||||||
|
if (items.find((i) => i.includes(`${zipName}/All Notes`))) {
|
||||||
|
for (zip of items) {
|
||||||
|
let raw = uzip.parse(unzip[zip]);
|
||||||
|
let html = Buffer.from(raw["note.html"].buffer).toString();
|
||||||
|
html = parser.parseFromString(html, "text/html");
|
||||||
|
|
||||||
|
let note = templates.note();
|
||||||
|
note.title = html.title;
|
||||||
|
note.notebooks = getNotebook(zip);
|
||||||
|
let images = html.getElementsByClassName("image-wrapper");
|
||||||
|
if (images.length > 0) {
|
||||||
|
for (let image of images) {
|
||||||
|
let imageNode = image.querySelector("img");
|
||||||
|
if (imageNode) {
|
||||||
|
let base64 = Buffer.from(
|
||||||
|
raw[imageNode.src.replace("./", "")].buffer
|
||||||
|
).toString("base64");
|
||||||
|
let img = html.createElement("img");
|
||||||
|
img.src = base64;
|
||||||
|
img.width = imageNode.width;
|
||||||
|
image.parentElement.replaceChild(img, image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
note.content.data = html.body.innerHTML.trim();
|
||||||
|
notes.push(note);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
`${file.fileName} is not a nimbus note exported zip file, skipping`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
convert
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user