6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/bookflow/apple_books/render_markdown.rb', line 6
def render(book_export, exported_at:)
lines = []
lines << "# #{book_export.book.title}"
lines << ""
lines << "- Author: #{book_export.book.author}"
lines << "- Asset ID: #{book_export.book.asset_id}"
lines << "- Source Path: #{book_export.book.source_path}"
lines << "- Exported At: #{Utils.format_timestamp(exported_at)}"
lines << "- Annotation Count: #{book_export.annotations.length}"
lines << ""
lines << "## Highlights"
book_export.annotations.each_with_index do |annotation, index|
lines << ""
lines << "### #{index + 1}"
lines << ""
lines << "> #{annotation.highlight_text.to_s.rstrip}"
lines << ""
lines << "- Created At: #{Utils.format_timestamp(annotation.created_at)}" if annotation.created_at
location = format_location(annotation)
lines << "- Location: #{location}" unless location.nil?
note = annotation.note_text.to_s.rstrip
next if note.empty?
lines << ""
lines << "Note:"
lines << note
end
"#{lines.join("\n")}\n"
end
|