Skip to content

Commit 10ade59

Browse files
committed
formatting options for current time
and small changes to popup dialogs and help menu and update README.md
1 parent 30e0abc commit 10ade59

File tree

4 files changed

+90
-54
lines changed

4 files changed

+90
-54
lines changed

README.md

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,72 @@
1-
Highlights to Obsidian is a plugin for Calibre ebook manager that formats and sends highlights to Obsidian.md markdown editor. This plugin's calibre forum post can be found [here](https://www.mobileread.com/forums/showthread.php?t=351283).
21

3-
After installing, go to Preferences -> Toolbars & menus -> The main toolbar. The highlights to obsidian menu button is listed as H2O.
2+
# Highlights to Obsidian
43

5-
---
4+
Highlights to Obsidian is a plugin for the calibre ebook manager that formats and sends highlights to Obsidian.md markdown editor. This plugin [can be found](https://www.mobileread.com/forums/showthread.php?t=351283) on the calibre forum.
65

7-
You can update the formatting of highlights sent to Obsidian in this plugin's config menu at Preferences -> Plugins -> User interface action -> Highlights to Obsidian.
6+
After installing, go to Preferences -> Toolbars & menus -> The main toolbar. The Highlights to Obsidian menu button is listed as H2O.
87

9-
If you don't want your first time sending new highlights to Obsidian to send all highlights, update the last send time in the config.
8+
1. [[#Useful Info]]
9+
2. [[#Formatting Options]]
10+
3. [[#Misc]]
1011

11-
In the formatting config menu, the 'title' is the title of the note that a highlight will be sent to. The 'body' is the text that will be sent to that note for each highlight. The 'header' will be sent to each note exactly once when you send highlights.
12+
## Useful Info
1213

13-
Sometimes, if you send highlights while your obsidian vault is closed, not all highlights will be sent. If this happens, you can use the "Resend Previously Sent Highlights" function.
14+
- You can update the formatting of highlights sent to Obsidian in the config menu at Preferences -> Plugins -> User interface action -> Highlights to Obsidian.
1415

15-
You can set keyboard shortcuts in Preferences -> Shortcuts -> H2O. Some available keyboard shortcuts include CTRL+S, CTRL+E, CTRL+G, CTRL+H, CTRL+J, and CTRL+K.
16+
- If you don't want the first time sending new highlights to send all of your highlights, you can update the last send time in the config.
1617

17-
---
18+
- In the formatting config menu, the 'title' is the title of the note that a highlight will be sent to. The 'body' is the text that will be sent to that note for each highlight. The 'header' will be sent to each note exactly once when you send highlights.
1819

19-
Available formatting options are as follows:
20+
- In a note's title, you can include slashes "/" to specify what folder the note should be in.
2021

22+
- Sometimes, if you send highlights while your Obsidian vault is closed, not all highlights will be sent. If this happens, you can use the "Resend Previously Sent Highlights" function.
23+
24+
- You can set keyboard shortcuts in Preferences -> Shortcuts -> H2O.
25+
26+
- Due to URI length limits, H2O can only send a few thousand words to a single note at once. Extra text will be sent to different notes with increasing numbers added to the end of the title.
27+
28+
## Formatting Options
29+
30+
For an example of how to use these, see the default format settings in the plugin's config menu.
31+
32+
**Book:**
2133
- {title}: Title of the book the highlight is in.
2234
- {authors}: Authors of the book the highlight is in.
35+
- {bookid}: The book's ID in calibre.
36+
37+
**Highlight:**
2338
- {highlight}: The highlighted text.
2439
- {blockquote}: The highlighted text, formatted as a blockquote. an arrow and a space "> " are added to the beginning of each line.
2540
- {notes}: The user's notes on this highlight, if any notes exist. There is a config option that allows you to set different formatting depending on whether a highlight includes notes.
26-
- {date}: Date the highlight was made, formatted as YYYY-MM-DD
27-
- {time}: Time the highlight was made, formatted as HH:MM:SS
28-
- {datetime}: Date and time highlight was made, formatted as YYYY-MM-DD HH:MM:SS
29-
- {localdate}, {localtime}, {localdatetime}
30-
- {timezone}: The timezone that your computer is currently set to. Note that this may not always match the timezone the highlight was made in. This uses the full name, as in "Coordinated Universal Time", instead of the abbreviation, as in "UTC".
31-
- {utcoffset} or {timeoffset}: The UTC offset of your computer's current time zone. For example, UTC time gives +0:00. EST time can be -4:00 or -5:00, depending on daylight savings time.
32-
- {day}: Day of the month the highlight was made, as in 3 or 17
33-
- {month}: Month the highlight was made, as in 4 for April or 10 for October
34-
- {year}: Full year the highlight was made, as in 2022
35-
- {localday}, {localmonth}, {localyear}
36-
- {utcnow}: current UTC time, formatted same as {datetime}.
37-
- {localnow}
3841
- {url}: A [calibre:// url](https://manual.calibre-ebook.com/url_scheme.html) to open the ebook viewer to this highlight. Note that this may not work if your library's name contains unsafe URL characters. Numbers, letters, spaces, underscores, and hyphens are all safe.
3942
- {location}: The highlight's EPUB CFI location in the book. For example, "/2/8/6/5:192". As a sort key, this will order highlights by their position in the book.
40-
- {timestamp}: The highlight's Unix timestamp. This is the default sort key used to determine what order to send highlights in.
43+
- {timestamp}: The highlight's Unix timestamp. As a sort key, this will order highlights by when they were made.
44+
- {uuid}: The highlight's unique ID in calibre. For example, "TlNlh8_I5VGKUtqdfbOxDw".
45+
46+
**Time:**
47+
- {date}: Date the highlight was made, formatted as YYYY-MM-DD.
48+
- {time}: Time the highlight was made, formatted as HH:MM:SS.
49+
- {datetime}: Date and time highlight was made, formatted as YYYY-MM-DD HH:MM:SS.
50+
- {day}: Day of the month the highlight was made, as in 3 or 17.
51+
- {month}: Month the highlight was made, as in 4 for April or 10 for October.
52+
- {year}: Full year the highlight was made, as in 2022.
53+
- {hour}: Hour the highlight was made, based on a 24-hour (not 12-hour) system.
54+
- {minute}: Minute the highlight was made.
55+
- {second}: Second the highlight was made.
56+
- {utcnow}: current time, formatted same as {datetime}.
57+
- {datenow}: Current date, formatted same as {date}.
58+
- {timenow}: Current time, formatted same as {time}.
59+
- {timezone}: The timezone that your computer is currently set to. Note that this may not always match the timezone the highlight was made in. Also note that this might use the full name "Coordinated Universal Time" instead of the abbreviation "UTC".
60+
- {utcoffset}: The UTC offset of your computer's current time zone. For example, UTC time gives +0:00. EST time can be -4:00 or -5:00, depending on daylight savings time.
61+
- All time options use UTC by default. To use your computer's local time zone instead, add "local" to the beginning: {localdate}, {localtime}, {localdatetime}, {localday}, {localmonth}, {localyear}, {localhour}, {localminute}, {localsecond}, {localnow}, {localdatenow}, {localtimenow}.
62+
63+
**Highlights to Obsidian:**
4164
- {totalsent}: The total number of highlights being sent.
4265
- {booksent}: The total number of highlights being sent to this Obsidian note.
4366
- {highlightsent}: This highlight's position in the highlights being sent to this note. For example, "{highlightsent} out of {booksent}" might result in "3 out of 5".
44-
- {bookid}: The book's ID in calibre.
45-
- {uuid}: The highlight's unique ID in calibre. For example, "TlNlh8_I5VGKUtqdfbOxDw".
46-
47-
For an example of how to use these, see the default format settings in the plugin's config.
4867

49-
---
68+
## Misc
5069

51-
Formatting options are based on the [Obsidian Clipper](https://github.com/jplattel/obsidian-clipper) Chrome extension.
70+
This plugin is loosely based on the [Obsidian Clipper](https://github.com/jplattel/obsidian-clipper) Chrome extension.
5271

53-
h2o-index.txt is for the [plugin index page](https://www.mobileread.com/forums/showthread.php?t=118764) on the Calibre forum.
72+
The file `h2o-index.txt` is for the [plugin index page](https://www.mobileread.com/forums/showthread.php?t=118764) on the calibre forum.

h2o/button_actions.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ def help_menu(parent):
1010
title = "Highlights to Obsidian Help Menu"
1111
body = "You can update the formatting of highlights sent to Obsidian in this plugin's config menu at " + \
1212
"Preferences -> Plugins -> User interface action -> Highlights to Obsidian.\n\n" + \
13-
"If you don't want your first time sending new highlights to Obsidian to send all highlights, " + \
13+
"If you don't want the first time sending new highlights to Obsidian to send all highlights, " + \
1414
"update the last send time in the config.\n\n" + \
1515
"In the formatting config menu, the 'title' is the title of the note that a highlight will be " + \
1616
"sent to. The 'body' is the text that will be sent to that note for each highlight. The " + \
1717
"'header' will be sent to each note exactly once when you send highlights.\n\n" + \
18+
"In a note's title, you can include slashes \"/\" to specify what folder the note should be in.\n\n" + \
1819
"Sometimes, if you send highlights while your obsidian vault is closed, not all highlights will " + \
1920
"be sent. If this happens, you can use the \"Resend Previously Sent Highlights\" function.\n\n" + \
20-
"You can set keyboard shortcuts in Preferences -> Shortcuts -> H2O. " + \
21-
"Some available keyboard shortcuts include CTRL+S, CTRL+E, CTRL+G, CTRL+H, CTRL+J, and CTRL+K."
21+
"You can set keyboard shortcuts in calibre's Preferences -> Shortcuts -> H2O.\n\n" + \
22+
"Due to URI length limits, H2O can only send a few thousand words to a single note at once. Extra text " \
23+
"will be sent to different notes with increasing numbers added to the end of the title."
2224
info_dialog(parent, title, body, show=True)
2325

2426

@@ -59,11 +61,11 @@ def make_sender() -> HighlightSender:
5961
# timezone changes.
6062
prefs["last_send_time"] = strftime("%Y-%m-%d %H:%M:%S", gmtime())
6163

62-
info = f"Success: {amt} highlight{' has' if amt == 1 else 's have'} been sent to obsidian."
64+
info = f"Success: {amt} highlight{' has' if amt == 1 else 's have'} been sent to Obsidian."
6365
if prefs['highlights_sent_dialog']:
6466
info_dialog(parent, "Highlights Sent", info, show=True)
6567
else:
66-
info_dialog(parent, "No Highlights Sent", "No highlights to send.", show=True)
68+
info_dialog(parent, "No Highlights Sent", "There are no highlights to send.", show=True)
6769

6870
return amt
6971

@@ -100,7 +102,7 @@ def send_all_highlights(parent, db):
100102
"""
101103
if prefs['confirm_send_all']:
102104
confirm = QMessageBox()
103-
confirm.setText("Are you sure you want to send ALL highlights to obsidian? This cannot be undone.")
105+
confirm.setText("Are you sure you want to send ALL highlights to Obsidian? This cannot be undone.")
104106
confirm.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
105107
confirm.setIcon(QMessageBox.Question)
106108
confirmed = confirm.exec()
@@ -151,7 +153,7 @@ def send_all_selected_highlights(parent, db):
151153

152154
if prefs['confirm_send_all']:
153155
confirm = QMessageBox()
154-
confirm.setText("Are you sure you want to send ALL highlights of the selected books to obsidian? This cannot be undone.")
156+
confirm.setText("Are you sure you want to send ALL highlights of the selected books to Obsidian? This cannot be undone.")
155157
confirm.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
156158
confirm.setIcon(QMessageBox.Question)
157159
confirmed = confirm.exec()

h2o/config.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,14 @@ def make_format_info_label(self):
161161
# list of formatting options
162162
format_options = [
163163
"title", "authors",
164-
"highlight", "blockquote",
165-
"notes", "date",
166-
"localdate", "time",
167-
"localtime", "datetime",
168-
"localdatetime", "timezone",
169-
"utcoffset", "day",
170-
"localday", "month",
171-
"localmonth", "year",
172-
"localyear", "utcnow",
173-
"localnow", "url",
174-
"location", "timestamp",
175-
"totalsent", "booksent",
176-
"highlightsent",
164+
"highlight", "blockquote", "notes",
165+
"date", "time", "datetime",
166+
"day", "month", "year",
167+
"hour", "minute", "second",
168+
"utcnow", "datenow", "timenow",
169+
"timezone", "utcoffset",
170+
"url", "location", "timestamp",
171+
"totalsent", "booksent", "highlightsent",
177172
"bookid", "uuid",
178173
]
179174
f_opt_str = "'" + "', '".join(format_options) + "'"
@@ -193,8 +188,12 @@ def make_format_info_label(self):
193188
self.note_format_list_label = QLabel(one_str, self)
194189
self.l.addWidget(self.note_format_list_label)
195190

196-
time_note = QLabel("Note that times are the time the highlight was made, not the current time " + \
197-
"(except 'utcnow' and 'localnow').")
191+
local_note = QLabel("All times use UTC by default. To use local time instead, add 'local' " +
192+
"to the beginning: {localdatetime}, {localnow}, etc.")
193+
self.l.addWidget(local_note)
194+
195+
time_note = QLabel("Note that all times, except 'now' times, are the time the highlight was made, not the " +
196+
"current time.")
198197
self.l.addWidget(time_note)
199198

200199
def save_settings(self):

h2o/highlight_sender.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
title_default_format = "Books/{title} by {authors}"
1515
body_default_format = "\n[Highlighted]({url}) on {date} at {time} UTC {timeoffset}:\n{blockquote}\n\n{notes}\n\n---\n"
1616
no_notes_default_format = "\n[Highlighted]({url}) on {date} at {time} UTC {timeoffset}:\n{blockquote}\n\n---\n"
17-
header_default_format = "" # by default, no header
17+
header_default_format = "\n{booksent} highlights sent to this note on {datenow} at {timenow} UTC.\n\n---\n"
18+
1819
sort_key_default = "location"
1920

2021

@@ -100,16 +101,28 @@ def make_time_format_dict(data: Dict) -> Dict[str, str]:
100101
# https://github.com/kovidgoyal/calibre/blob/master/src/calibre/gui2/library/annotations.py#L34
101102
# todo: timezone currently displays "Coordinated Universal Time" instead of the abbreviation, "UTC"
102103
"timezone": h_local.tzname(), # local timezone
104+
"localtimezone": h_local.tzname(), # so that the config menu's explanation doesn't confuse users
103105
"utcoffset": utc_offset,
106+
"localoffset": utc_offset, # so that the config menu's explanation doesn't confuse users
104107
"timeoffset": utc_offset, # for backwards compatibility
105108
"day": str(h_time.day),
106109
"localday": str(h_local.day),
107110
"month": str(h_time.month),
108111
"localmonth": str(h_local.month),
109112
"year": str(h_time.year),
110113
"localyear": str(h_local.year),
114+
"hour": str(h_time.hour),
115+
"localhour": str(h_local.hour),
116+
"minute": str(h_time.minute),
117+
"localminute": str(h_local.minute),
118+
"second": str(h_time.second),
119+
"localsecond": str(h_local.second),
111120
"utcnow": time.strftime("%Y-%m-%d %H:%M:%S", utc),
121+
"datenow": time.strftime("%Y-%m-%d", utc),
122+
"timenow": time.strftime("%H:%M:%S", utc),
112123
"localnow": time.strftime("%Y-%m-%d %H:%M:%S", local),
124+
"localdatenow": time.strftime("%Y-%m-%d", local),
125+
"localtimenow": time.strftime("%H:%M:%S", local),
113126
"timestamp": str(h_time.timestamp()), # Unix timestamp of highlight time. uses UTC.
114127
}
115128

@@ -209,6 +222,9 @@ def make_format_dict(data, calibre_library: str, book_titles_authors: Dict[int,
209222

210223
# formatting options are based on https://github.com/jplattel/obsidian-clipper
211224

225+
# todo: could be optimized by taking as input the formatting options that are needed, and then
226+
# only calculating values for those options
227+
212228
# if you add a format option, also update the format_options local variable in config.py and the docs in README.md
213229
time_options = make_time_format_dict(data)
214230
highlight_options = make_highlight_format_dict(data, calibre_library)
@@ -383,7 +399,7 @@ def is_valid_highlight(_dat: Dict):
383399
if _annot.get("removed"):
384400
return False # don't try to send highlights that have been removed
385401

386-
if not condition(_dat):
402+
if not condition(_dat): # or return condition(_dat)
387403
return False # user-defined condition must be true for this highlight
388404

389405
return True

0 commit comments

Comments
 (0)