highlights 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +8 -8
- data/lib/highlights.rb +3 -0
- data/lib/highlights/cli.rb +5 -2
- data/lib/highlights/formatter/html.rb +15 -0
- data/lib/highlights/formatter/markdown.rb +23 -0
- data/lib/highlights/formatter/template.html.erb +61 -0
- data/lib/highlights/renderer.rb +12 -13
- data/lib/highlights/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b830065be619ca7e81760e4a73e69301dc252a78842ecf7c610d039eff09b047
|
4
|
+
data.tar.gz: a2bffd6eef6483a0a7e6c59b6d92ab91613b0c5e0a6b2a201ba4c76267f52e98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bc4ca0e237b017c2abd0d0fd2b3912aa9b59012dd6dcda7449e7ce4635a3080ccdc430e6f074cae419a61fbfc63665b9b1cc515b5d5aaaf0bee6d78cfb72884
|
7
|
+
data.tar.gz: 600de72f3bcc2cbaa05293280d58913099af1596878b2d8116f70178e1cc28643c8cf10da58eda838f27a843889bdd042d6bc1af0aa1b1336b7c443ac0579e7c
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Highlights
|
2
2
|
|
3
|
-
A CLI that converts Kindle CSV documents to Markdown.
|
3
|
+
A CLI that converts Kindle CSV documents to Markdown or HTML.
|
4
4
|
|
5
5
|
## Example
|
6
6
|
|
@@ -13,15 +13,16 @@ Outputs:
|
|
13
13
|
|
14
14
|
```
|
15
15
|
# ZEN AND THE ART OF MOTORCYCLE MAINTENANCE: AN INQUIRY INTO VALUES
|
16
|
-
## by Robert M. Pirsig
|
17
16
|
|
18
|
-
|
17
|
+
by Robert M. Pirsig
|
19
18
|
|
20
|
-
|
19
|
+
## Notes
|
20
|
+
|
21
|
+
> You�re a passive observer and it is all moving by you boringly in a frame.
|
21
22
|
|
22
23
|
Highlight (Yellow): Page 4
|
23
24
|
|
24
|
-
> Instead you spend your time being aware of things and meditating on them. On sights and sounds, on the mood of the weather and things remembered, on the machine and the countryside you�re in, thinking about things at great leisure and length without being hurried and without feeling you�re losing time.
|
25
|
+
> Instead you spend your time being aware of things and meditating on them. On sights and sounds, on the mood of the weather and things remembered, on the machine and the countryside you�re in, thinking about things at great leisure and length without being hurried and without feeling you�re losing time.
|
25
26
|
|
26
27
|
Highlight (Yellow): Page 6
|
27
28
|
```
|
@@ -41,9 +42,9 @@ $ highlights -f zamm_notes.csv
|
|
41
42
|
```
|
42
43
|
$ highlights -h
|
43
44
|
|
44
|
-
Usage: highlights [
|
45
|
+
Usage: highlights -f file.csv -o [output file]
|
45
46
|
-f, --file=FILENAME Kindle notes CSV file
|
46
|
-
-o, --output=OUTPUT Output file (default: notes.md)
|
47
|
+
-o, --output=OUTPUT Output file. Accepts HTML and markdown (default: notes.md)
|
47
48
|
-h, --help Show help
|
48
49
|
-v, --version Show version
|
49
50
|
```
|
@@ -58,7 +59,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
58
59
|
|
59
60
|
Bug reports and pull requests are welcome on GitHub at https://github.com/mgmarlow/highlights.
|
60
61
|
|
61
|
-
|
62
62
|
## License
|
63
63
|
|
64
64
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/highlights.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require "csv"
|
2
|
+
require "erb"
|
2
3
|
require "optparse"
|
3
4
|
|
4
5
|
require "highlights/error"
|
5
6
|
require "highlights/version"
|
6
7
|
require "highlights/parser"
|
8
|
+
require "highlights/formatter/markdown"
|
9
|
+
require "highlights/formatter/html"
|
7
10
|
require "highlights/renderer"
|
8
11
|
|
9
12
|
module Highlights
|
data/lib/highlights/cli.rb
CHANGED
@@ -3,24 +3,27 @@ module Highlights
|
|
3
3
|
Options = Struct.new(:filename, :output)
|
4
4
|
|
5
5
|
def initialize(args)
|
6
|
+
args << '-h' if ARGV.empty?
|
6
7
|
@args = args
|
7
8
|
end
|
8
9
|
|
9
10
|
def run
|
10
11
|
options = get_options
|
11
12
|
document = Parser.new(options.filename).parse
|
12
|
-
Renderer.
|
13
|
+
Renderer.render(document, options.output)
|
13
14
|
end
|
14
15
|
|
15
16
|
def get_options
|
16
17
|
options = Options.new(nil, "notes.md")
|
17
18
|
|
18
19
|
OptionParser.new do |opts|
|
20
|
+
opts.banner = "Usage: highlights -f file.csv -o [output file]"
|
21
|
+
|
19
22
|
opts.on("-fFILENAME", "--file=FILENAME", "Kindle notes CSV file") do |f|
|
20
23
|
options.filename = f
|
21
24
|
end
|
22
25
|
|
23
|
-
opts.on("-oOUTPUT", "--output=OUTPUT", "Output file (default: notes.md)") do |o|
|
26
|
+
opts.on("-oOUTPUT", "--output=OUTPUT", "Output file. Accepts HTML and markdown (default: notes.md)") do |o|
|
24
27
|
options.output = o
|
25
28
|
end
|
26
29
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Highlights
|
2
|
+
module Formatter
|
3
|
+
module HTML
|
4
|
+
def render_html
|
5
|
+
file = File.join(File.dirname(__FILE__), "./template.html.erb")
|
6
|
+
template = File.read(file)
|
7
|
+
|
8
|
+
File.open(@outfile, 'w') do |file|
|
9
|
+
file.write(ERB.new(template).result(binding))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Highlights
|
2
|
+
module Formatter
|
3
|
+
module Markdown
|
4
|
+
def render_markdown
|
5
|
+
File.open(@outfile, 'w') do |file|
|
6
|
+
file.puts("# #{@document.title}")
|
7
|
+
file.write("\n")
|
8
|
+
file.puts(@document.author)
|
9
|
+
file.write("\n")
|
10
|
+
file.puts("## Notes")
|
11
|
+
file.write("\n")
|
12
|
+
|
13
|
+
@document.notes.each do |note|
|
14
|
+
file.puts("> #{note.annotation}")
|
15
|
+
file.write("\n")
|
16
|
+
file.puts("#{note.type}: #{note.location}")
|
17
|
+
file.write("\n")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title><%= @document.title %></title>
|
7
|
+
<style>
|
8
|
+
body {
|
9
|
+
width: calc(100% - 40px);
|
10
|
+
max-width: 675px;
|
11
|
+
margin: 0 auto;
|
12
|
+
}
|
13
|
+
|
14
|
+
body, * {
|
15
|
+
font-family: Georgia, serif;
|
16
|
+
}
|
17
|
+
|
18
|
+
p {
|
19
|
+
font-size: 18px;
|
20
|
+
line-height: 1.45;
|
21
|
+
}
|
22
|
+
|
23
|
+
ul {
|
24
|
+
margin: 0;
|
25
|
+
padding: 0;
|
26
|
+
list-style: none;
|
27
|
+
}
|
28
|
+
|
29
|
+
li {
|
30
|
+
margin-bottom: 2.5rem;
|
31
|
+
}
|
32
|
+
|
33
|
+
blockquote {
|
34
|
+
margin: 0;
|
35
|
+
border-left: 8px solid rgba(255, 222, 3, 0.5);
|
36
|
+
padding-left: 1rem;
|
37
|
+
}
|
38
|
+
|
39
|
+
figcaption {
|
40
|
+
margin-left: 1rem;
|
41
|
+
}
|
42
|
+
</style>
|
43
|
+
</head>
|
44
|
+
<body>
|
45
|
+
<h1><%= @document.title %></h1>
|
46
|
+
<p><%= @document.author %></p>
|
47
|
+
|
48
|
+
<h2>Notes</h2>
|
49
|
+
|
50
|
+
<ul>
|
51
|
+
<% for @note in @document.notes %>
|
52
|
+
<li>
|
53
|
+
<div>
|
54
|
+
<blockquote><p><%= @note.annotation %></p></blockquote>
|
55
|
+
<figcaption><%= @note.type %>: <%= @note.location %></figcaption>
|
56
|
+
</div>
|
57
|
+
</li>
|
58
|
+
<% end %>
|
59
|
+
</ul>
|
60
|
+
</body>
|
61
|
+
</html>
|
data/lib/highlights/renderer.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
module Highlights
|
2
2
|
class Renderer
|
3
|
+
include Formatter::HTML
|
4
|
+
include Formatter::Markdown
|
5
|
+
|
3
6
|
def initialize(document, outfile)
|
4
7
|
@document = document
|
5
8
|
@outfile = outfile
|
6
9
|
end
|
7
10
|
|
8
|
-
def render
|
9
|
-
|
10
|
-
|
11
|
-
file.puts("## #{@document.author}")
|
12
|
-
file.write("\n")
|
13
|
-
file.puts("### Notes")
|
14
|
-
file.write("\n")
|
11
|
+
def self.render(*args)
|
12
|
+
new(*args).render
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
def render
|
16
|
+
case File.extname(@outfile)
|
17
|
+
when '.md', '.markdown'
|
18
|
+
render_markdown
|
19
|
+
when '.html'
|
20
|
+
render_html
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
data/lib/highlights/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: highlights
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Graham Marlow
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A CLI tool that converts a Kindle CSV file to markdown.
|
14
14
|
email:
|
@@ -31,6 +31,9 @@ files:
|
|
31
31
|
- lib/highlights.rb
|
32
32
|
- lib/highlights/cli.rb
|
33
33
|
- lib/highlights/error.rb
|
34
|
+
- lib/highlights/formatter/html.rb
|
35
|
+
- lib/highlights/formatter/markdown.rb
|
36
|
+
- lib/highlights/formatter/template.html.erb
|
34
37
|
- lib/highlights/parser.rb
|
35
38
|
- lib/highlights/renderer.rb
|
36
39
|
- lib/highlights/version.rb
|