Skip to content

Commit

Permalink
Merge remote-tracking branch 'james-xli/feature/note-max-width'
Browse files Browse the repository at this point in the history
  • Loading branch information
philips committed Dec 19, 2024
2 parents f3224f1 + 101ff45 commit 97caef4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
37 changes: 29 additions & 8 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface SupernotePluginSettings {
showTOC: boolean;
showExportButtons: boolean;
collapseRecognizedText: boolean,
noteImageMaxDim: number;
}

const DEFAULT_SETTINGS: SupernotePluginSettings = {
Expand All @@ -15,7 +16,8 @@ const DEFAULT_SETTINGS: SupernotePluginSettings = {
showTOC: true,
showExportButtons: true,
collapseRecognizedText: false,
};
noteImageMaxDim: 800, // Sensible default for Nomad pages to be legible but not too big. Unit: px
}

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

const pageContainer = container.createEl("div", {
cls: 'page-container',
})
pageContainer.setAttr('style', 'max-width: ' + this.settings.noteImageMaxDim + 'px;')

if (images.length > 1 && this.settings.showTOC) {
const a = container.createEl("a");
const a = pageContainer.createEl("a");
a.id = `page${i + 1}`;
a.href = "#toc";
a.createEl("h3", { text: `Page ${i + 1}` });
Expand All @@ -176,30 +183,31 @@ export class SupernoteView extends FileView {

// If Collapse Text setting is enabled, place the text into an HTML `details` element
if (this.settings.collapseRecognizedText) {
text = container.createEl('details', {
text = pageContainer.createEl('details', {
text: '\n' + sn.pages[i].text,
cls: 'page-recognized-text',
});
text.createEl('summary', { text: `Page ${i + 1} Recognized Text` });
} else {
text = container.createEl('div', {
text = pageContainer.createEl('div', {
text: sn.pages[i].text,
cls: 'page-recognized-text',
});
}

text.setAttr('style', 'user-select: text; white-space: pre-line; margin-top: 1.2em;');
}

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

// Create a button to save image to vault
if (this.settings.showExportButtons) {
const saveButton = container.createEl("button", {
const saveButton = pageContainer.createEl("button", {
text: "Save image to vault",
cls: "mod-cta",
});
Expand Down Expand Up @@ -464,5 +472,18 @@ class SupernoteSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);

new Setting(containerEl)
.setName('Max image side length in .note files')
.setDesc('Maximum width and height (in pixels) of the note image when viewing .note files. Does not affect exported images and markdown.')
.addSlider(text => text
.setLimits(200, 1900, 100) // Resolution of an A5X/A6X2/Nomad page is 1404 x 1872 px (with no upscaling)
.setDynamicTooltip()
.setValue(this.plugin.settings.noteImageMaxDim)
.onChange(async (value) => {
this.plugin.settings.noteImageMaxDim = value;
await this.plugin.saveSettings();
})
);
}
}
15 changes: 15 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,19 @@

.theme-light img.supernote-invert-light {
filter: invert(1);
}

button.mod-cta {
display: block;
}

.page-recognized-text {
user-select: text;
white-space: pre-line;
margin-top: 1.2em;
}

div.page-container {
display: inline-block;
vertical-align: top;
}

0 comments on commit 97caef4

Please sign in to comment.