Evernote plugin: fix crash with missing fields

print-window-tiddler
Jermolene 2016-02-05 23:05:24 +00:00
rodzic b3e0e134ab
commit 5238b4d503
1 zmienionych plików z 11 dodań i 7 usunięć

Wyświetl plik

@ -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;
}
})();