Skip to content

Commit

Permalink
Version 1.0.12
Browse files Browse the repository at this point in the history
1. Add supporting extra file extensions for HTML files. (#18)
2. Modify scaling method to avoid conflict with some HTML files' CSS attributes. (#20)
  • Loading branch information
nuthrash committed Dec 12, 2023
1 parent da5fdbb commit 0cafd18
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ This section would try to explain some terms used by Operating Mode more detail.
#### Background Color
Set HTML <body> element background color forcely.

#### Extra File Extensions
Open HTML format files with user defined file extensions (list of comma separated strings). Change this setting may cause other plugins un-workable, so you shall know very clearly what you are doing. Remember to relaunch the Obsidian app after change this setting!

### Hotkeys and touch gestures settings
Almost all keyboard hotkeys are taken from Obsidian's global hotkey settings, so you shall modify them via ⚙"Settings" ⇨ "Hotkeys" options page. <br>
Expand Down
Binary file modified assets/images/screenshots/HtmlReadedSettings1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-html-plugin",
"name": "HTML Reader",
"version": "1.0.11",
"version": "1.0.12",
"minAppVersion": "0.15.3",
"description": "This is a HTML file reader plugin for Obsidian. Can open document with \".html\" and \".htm\" file extensions.",
"author": "Nuthrash",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-html-plugin",
"version": "1.0.11",
"version": "1.0.12",
"description": "This is a HTML file reader plugin for Obsidian. Can open document with \".html\" and \".htm\" file extensions.",
"main": "main.js",
"scripts": {
Expand Down
12 changes: 11 additions & 1 deletion src/HtmlPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ export default class HtmlPlugin extends Plugin {
});

try {
this.registerExtensions(HTML_FILE_EXTENSIONS, VIEW_TYPE_HTML);
if( this.settings.extraFileExt === '' ) {
this.registerExtensions(HTML_FILE_EXTENSIONS, VIEW_TYPE_HTML);
} else {
let efe = this.settings.extraFileExt.split(",").map(s => s.trim()).filter(s => s.length > 0); // Array<string>
if( efe && efe.length > 0 ) {
for( let i = 0; i < efe.length; ++i )
HTML_FILE_EXTENSIONS.push( efe[i] );
}

this.registerExtensions(HTML_FILE_EXTENSIONS, VIEW_TYPE_HTML);
}
} catch (error) {
await showError(`File extensions ${HTML_FILE_EXTENSIONS} had been registered by other plugin!`);
}
Expand Down
17 changes: 17 additions & 0 deletions src/HtmlPluginSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface HtmlPluginSettings {
opMode: HtmlPluginOpMode;
zoomByWheelAndGesture: boolean;
zoomValue: number;
extraFileExt: string;
}

export const DEFAULT_SETTINGS: HtmlPluginSettings = {
Expand All @@ -16,6 +17,7 @@ export const DEFAULT_SETTINGS: HtmlPluginSettings = {
opMode: HtmlPluginOpMode.Balance,
zoomByWheelAndGesture: true,
zoomValue: 1.0,
extraFileExt: '',
}

export class HtmlSettingTab extends PluginSettingTab {
Expand Down Expand Up @@ -82,6 +84,21 @@ export class HtmlSettingTab extends PluginSettingTab {
});
});

// ----- General Settings: Extra File Extensions -----
const extraFileExtSetting = new Setting(containerEl);
extraFileExtSetting
.setName("Extra File Extensions")
.setDesc("Open HTML format files with user defined file extensions (list of comma separated strings). Change this setting may cause other plugins un-workable, so you shall know very clearly what you are doing. Remember to relaunch the Obsidian app after change this setting!")
.addText((val) =>
val
.setValue(this.plugin.settings.extraFileExt)
.setPlaceholder("e.g. xhtml, htm123")
.onChange( async (value: string) => {
this.plugin.settings.extraFileExt = value;
await this.plugin.saveSettings();
})
);

// ----- HotKeys and Touch Gestures Settings -----
containerEl.createEl('h2', { text: 'HotKeys and Touch Gestures Settings' });
containerEl.createEl('small', { text: `Almost all keyboard hotkeys are taken from Obsidian's global hotkey settings, so you shall modify them via ⚙"Settings" ⇨ "Hotkeys" options page.` });
Expand Down
11 changes: 6 additions & 5 deletions src/HtmlView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,9 @@ async function modifyAnchorTarget( doc: HTMLDocument ): Promise<void> {
}

async function restoreStateBySettings( doc: HTMLDocument, settings: HtmlPluginSettings ): Promise<void> {
doc.body.style.transformOrigin = "left top"; // CSS transform-origin
doc.body.style.transform = `scale(${settings.zoomValue})`;
// all[0] ==> <html>
doc.all[0].style.transformOrigin = "left top"; // CSS transform-origin
doc.all[0].style.transform = `scale(${settings.zoomValue})`;

if( settings.bgColorEnabled ) {
doc.body.setAttribute( "bgColor", settings.bgColor );
Expand Down Expand Up @@ -707,20 +708,20 @@ async function buildUserInteractiveFacilities( mainView: HTMLElement ): Promise<
};
mainView.ZoomIn = () => {
settings.zoomValue = NP.plus( settings.zoomValue, 0.1 );
iframeDoc.body.style.transform = `scale(${settings.zoomValue})`;
iframeDoc.all[0].style.transform = `scale(${settings.zoomValue})`;
iframe.contentWindow.focus();
};
mainView.ZoomOut = () => {
let scaleValue = NP.minus( settings.zoomValue, 0.1 );
if( scaleValue <= 0.1 )
scaleValue = 0.1;
settings.zoomValue = scaleValue;
iframeDoc.body.style.transform = `scale(${settings.zoomValue})`;
iframeDoc.all[0].style.transform = `scale(${settings.zoomValue})`;
iframe.contentWindow.focus();
};
mainView.ResetZoom = () => {
settings.zoomValue = 1.0;
iframeDoc.body.style.transform = `scale(${settings.zoomValue})`;
iframeDoc.all[0].style.transform = `scale(${settings.zoomValue})`;
iframe.contentWindow.focus();
};

Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"1.0.8": "0.15.3",
"1.0.9": "0.15.3",
"1.0.10": "0.15.3",
"1.0.11": "0.15.3"
"1.0.11": "0.15.3",
"1.0.12": "0.15.3"
}

0 comments on commit 0cafd18

Please sign in to comment.