mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-10-05 10:20:45 +00:00
4b70257aca
Relates to Issue #2268 Based in the [example XML][1] attachments are listed in the <resources> node. Since in TiddlyWiki these would be media tiddlers I add then one by one as separate tiddlers. There are some things that still need to happen. There should be a mime type check so we don't attempt to import media tha TiddlyWiki doesn't support. Also the example suggests the data is base64 encoded so I blindly use that for the text attribute. Should there be a `data:mediatyp;base64,…` prefix? [1]: https://gist.github.com/evernotegists/6116886
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
/*\
|
|
title: $:/plugins/tiddlywiki/evernote/modules/enex-deserializer.js
|
|
type: application/javascript
|
|
module-type: tiddlerdeserializer
|
|
|
|
ENEX file deserializer
|
|
|
|
For details see: https://blog.evernote.com/tech/2013/08/08/evernote-export-format-enex/
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
// DOMParser = require("$:/plugins/tiddlywiki/xmldom/dom-parser").DOMParser;
|
|
|
|
/*
|
|
Parse an ENEX file into tiddlers
|
|
*/
|
|
exports["application/enex+xml"] = function(text,fields) {
|
|
// Collect output tiddlers in an array
|
|
var results = [];
|
|
// Parse the XML document
|
|
var parser = new DOMParser(),
|
|
doc = parser.parseFromString(text,"application/xml");
|
|
// Output a report tiddler with information about the import
|
|
var enex = doc.querySelector("en-export");
|
|
results.push({
|
|
title: "Evernote Import Report",
|
|
text: "Evernote file imported on " + enex.getAttribute("export-date") + " from " + enex.getAttribute("application") + " (" + enex.getAttribute("version") + ")"
|
|
})
|
|
// Get all the "note" nodes
|
|
var noteNodes = doc.querySelectorAll("note");
|
|
$tw.utils.each(noteNodes,function(noteNode) {
|
|
var result = {
|
|
title: noteNode.querySelector("title").textContent,
|
|
type: "text/html",
|
|
text: noteNode.querySelector("content").textContent
|
|
};
|
|
$tw.utils.each(noteNodes.querySelector("note-attributes").childNodes,function(attrNode) {
|
|
result[attrNode.tagName] = attrNode.textContent;
|
|
});
|
|
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
|
|
});
|
|
});
|
|
});
|
|
// Return the output tiddlers
|
|
return results;
|
|
};
|
|
|
|
})();
|