Skip to content

Commit 97caef4

Browse files
committed
Merge remote-tracking branch 'james-xli/feature/note-max-width'
2 parents f3224f1 + 101ff45 commit 97caef4

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

main.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface SupernotePluginSettings {
77
showTOC: boolean;
88
showExportButtons: boolean;
99
collapseRecognizedText: boolean,
10+
noteImageMaxDim: number;
1011
}
1112

1213
const DEFAULT_SETTINGS: SupernotePluginSettings = {
@@ -15,7 +16,8 @@ const DEFAULT_SETTINGS: SupernotePluginSettings = {
1516
showTOC: true,
1617
showExportButtons: true,
1718
collapseRecognizedText: false,
18-
};
19+
noteImageMaxDim: 800, // Sensible default for Nomad pages to be legible but not too big. Unit: px
20+
}
1921

2022
function generateTimestamp(): string {
2123
const date = new Date();
@@ -163,8 +165,13 @@ export class SupernoteView extends FileView {
163165
for (let i = 0; i < images.length; i++) {
164166
const imageDataUrl = images[i].toDataURL();
165167

168+
const pageContainer = container.createEl("div", {
169+
cls: 'page-container',
170+
})
171+
pageContainer.setAttr('style', 'max-width: ' + this.settings.noteImageMaxDim + 'px;')
172+
166173
if (images.length > 1 && this.settings.showTOC) {
167-
const a = container.createEl("a");
174+
const a = pageContainer.createEl("a");
168175
a.id = `page${i + 1}`;
169176
a.href = "#toc";
170177
a.createEl("h3", { text: `Page ${i + 1}` });
@@ -176,30 +183,31 @@ export class SupernoteView extends FileView {
176183

177184
// If Collapse Text setting is enabled, place the text into an HTML `details` element
178185
if (this.settings.collapseRecognizedText) {
179-
text = container.createEl('details', {
186+
text = pageContainer.createEl('details', {
180187
text: '\n' + sn.pages[i].text,
188+
cls: 'page-recognized-text',
181189
});
182190
text.createEl('summary', { text: `Page ${i + 1} Recognized Text` });
183191
} else {
184-
text = container.createEl('div', {
192+
text = pageContainer.createEl('div', {
185193
text: sn.pages[i].text,
194+
cls: 'page-recognized-text',
186195
});
187196
}
188-
189-
text.setAttr('style', 'user-select: text; white-space: pre-line; margin-top: 1.2em;');
190197
}
191198

192199
// Show the img of the page
193-
const imgElement = container.createEl("img");
200+
const imgElement = pageContainer.createEl("img");
194201
imgElement.src = imageDataUrl;
195202
if (this.settings.invertColorsWhenDark) {
196203
imgElement.addClass("supernote-invert-dark");
197204
}
205+
imgElement.setAttr('style', 'max-height: ' + this.settings.noteImageMaxDim + 'px;')
198206
imgElement.draggable = true;
199207

200208
// Create a button to save image to vault
201209
if (this.settings.showExportButtons) {
202-
const saveButton = container.createEl("button", {
210+
const saveButton = pageContainer.createEl("button", {
203211
text: "Save image to vault",
204212
cls: "mod-cta",
205213
});
@@ -464,5 +472,18 @@ class SupernoteSettingTab extends PluginSettingTab {
464472
await this.plugin.saveSettings();
465473
})
466474
);
475+
476+
new Setting(containerEl)
477+
.setName('Max image side length in .note files')
478+
.setDesc('Maximum width and height (in pixels) of the note image when viewing .note files. Does not affect exported images and markdown.')
479+
.addSlider(text => text
480+
.setLimits(200, 1900, 100) // Resolution of an A5X/A6X2/Nomad page is 1404 x 1872 px (with no upscaling)
481+
.setDynamicTooltip()
482+
.setValue(this.plugin.settings.noteImageMaxDim)
483+
.onChange(async (value) => {
484+
this.plugin.settings.noteImageMaxDim = value;
485+
await this.plugin.saveSettings();
486+
})
487+
);
467488
}
468489
}

styles.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,19 @@
1212

1313
.theme-light img.supernote-invert-light {
1414
filter: invert(1);
15+
}
16+
17+
button.mod-cta {
18+
display: block;
19+
}
20+
21+
.page-recognized-text {
22+
user-select: text;
23+
white-space: pre-line;
24+
margin-top: 1.2em;
25+
}
26+
27+
div.page-container {
28+
display: inline-block;
29+
vertical-align: top;
1530
}

0 commit comments

Comments
 (0)