This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
230 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[](https://github.com/prettier/prettier) | ||
|
||
|
||
This is a tool which converts the Google Keep archive to markdown documents with YAML front matter. The Google Keep archive can be obtained from the Google Takeout page. | ||
|
||
https://www.google.com/settings/takeout/custom/keep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env node | ||
|
||
var fs = require("fs"); | ||
var parser = require("./parser.js"); | ||
var serializer = require("./serializer.js"); | ||
|
||
// TODO: parse argv and get directory file list | ||
// parse output | ||
// | ||
|
||
// Take notes and then convert it into markdown | ||
// | ||
// .content | ||
// -> This needs to be converted to markdown | ||
// -> listitem | ||
// | ||
|
||
if (process.argv.length != 4) { | ||
console.log("Usage main.js inputDir outputDir"); | ||
process.exit(1); | ||
} | ||
|
||
var inputDir = process.argv[2]; | ||
var outputDir = process.argv[3]; | ||
|
||
var convert = function(filePath, outputDir) { | ||
var data = fs.readFileSync(filePath); | ||
var note = parser(data); | ||
var output = serializer.serialize(note); | ||
|
||
output.forEach(d => { | ||
console.log(filePath, d[0]); | ||
fs.writeFileSync(outputDir + "/" + d[0], d[1]); | ||
}); | ||
}; | ||
|
||
var files = fs.readdirSync(inputDir); | ||
files = files.filter(t => t.endsWith(".html")); | ||
files.forEach(filePath => convert(inputDir + "/" + filePath, outputDir)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var assert = require("chai").assert; | ||
import { parse } from "./parser"; | ||
|
||
suite("Parser", function() { | ||
test("Should parse some basic info", function() { | ||
var data = ` | ||
<html><body><div class="note DEFAULT"><div class="heading"> | ||
21 Jun 2016, 22:39:47</div> | ||
<div class="title">Ll</div> | ||
<div class="content">Hearts of darkness<br>Water ship down<br>The Dubliners<br><br></div> | ||
<div class="labels"><span class="label">Reading List</span><span class="label">Another Tag</span></div> | ||
</div></body></html> | ||
`; | ||
|
||
console.log(parse); | ||
var note = parse(data); | ||
assert.deepEqual(note.title, "Ll"); | ||
// FIXME: Is the extra space really required? | ||
assert.deepEqual( | ||
note.content, | ||
"Hearts of darkness \nWater ship down \nThe Dubliners" | ||
); | ||
assert.deepEqual(note.tags, ["Reading List", "Another Tag"]); | ||
assert.notOk(note.archived); | ||
assert.deepEqual(note.date, "2016-06-21T20:39:47.000Z"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
var cheerio = require("cheerio"); | ||
var toMarkdown = require("to-markdown"); | ||
var moment = require("moment"); | ||
|
||
function getImages(node) { | ||
var images = []; | ||
if (node instanceof Array) { | ||
node.forEach(child => { | ||
images = images.concat(getImages(child)); | ||
}); | ||
return images; | ||
} | ||
|
||
if (node.name == "img") { | ||
var img = node.attribs.src; | ||
images.push(img); | ||
return images; | ||
} | ||
|
||
if (!node.children) return []; | ||
|
||
node.children.forEach(child => { | ||
images = images.concat(getImages(child)); | ||
}); | ||
return images; | ||
} | ||
|
||
var converter = { | ||
filter: "div", | ||
/* | ||
filter: function(node) { | ||
return node.className.indexOf('listitem') != -1; | ||
}, | ||
*/ | ||
replacement: function(innerHTML, node) { | ||
return innerHTML + " "; | ||
} | ||
}; | ||
|
||
export interface Note { | ||
content: string; | ||
title: string; | ||
date: string; | ||
archived: boolean; | ||
tags: string[]; | ||
attachments: string[]; | ||
} | ||
|
||
export function parse(data) { | ||
var $ = cheerio.load(data); | ||
|
||
var note = {} as Note; | ||
note.content = $(".content").html(); | ||
note.content = toMarkdown(note.content, { converters: [converter] }).trim(); | ||
|
||
// FIXME: What about timezone? | ||
note.date = $(".heading") | ||
.text() | ||
.trim(); | ||
note.date = moment(note.date).toISOString(); | ||
|
||
note.title = $(".title") | ||
.text() | ||
.trim(); | ||
note.archived = $.contains(".archived"); | ||
|
||
note.tags = $("span.label").toArray().map(function(elem) { | ||
if (!elem.children) { | ||
return null; | ||
} | ||
return elem.children[0].data; | ||
}); | ||
|
||
var attachments = $("div.attachments").toArray(); | ||
note.attachments = getImages(attachments); | ||
|
||
return note; | ||
} |
Oops, something went wrong.