1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Evernote plugin: fix crash with missing fields

This commit is contained in:
Jermolene 2016-02-05 23:05:24 +00:00
parent b3e0e134ab
commit 5238b4d503

View File

@ -35,10 +35,10 @@ exports["application/enex+xml"] = function(text,fields) {
var noteNodes = doc.querySelectorAll("note");
$tw.utils.each(noteNodes,function(noteNode) {
var result = {
title: noteNode.querySelector("title").textContent,
title: getTextContent(noteNode,"title"),
type: "text/html",
tags: [],
text: noteNode.querySelector("content").textContent
text: getTextContent(noteNode,"content")
};
$tw.utils.each(noteNode.querySelectorAll("tag"),function(tagNode) {
result.tags.push(tagNode.textContent);
@ -49,11 +49,11 @@ exports["application/enex+xml"] = function(text,fields) {
results.push(result);
$tw.utils.each(noteNode.querySelectorAll("resources"),function(resourceNode) {
results.push({
title: resourceNode.querySelector("resource-attributes>file-name").textContent,
type: resourceNode.querySelector("mime").textContent,
width: resourceNode.querySelector("width").textContent,
height: resourceNode.querySelector("height").textContent,
text: resourceNode.querySelector("data").textContent
title: getTextContent(resourceNode,"resource-attributes>file-name"),
type: getTextContent(resourceNode,"mime"),
width: getTextContent(resourceNode,"width"),
height: getTextContent(resourceNode,"height"),
text: getTextContent(resourceNode,"data")
});
});
});
@ -61,4 +61,8 @@ exports["application/enex+xml"] = function(text,fields) {
return results;
};
function getTextContent(node,selector) {
return (node.querySelector(selector) || {}).textContent;
}
})();