Skip to content

Commit 70b8afa

Browse files
yolo-samsmcllns
andauthored
Support .htm extension alongside .html (#13)
* feat: Support .htm extension alongside .html Closes #9 * refactor: Inline html/htm checks instead of const+type guard Three-similar-lines beats a premature abstraction here — the set of HTML extension aliases is closed at html/htm. --------- Co-authored-by: Sam Collins <81678+smcllns@users.noreply.github.com>
1 parent f971d8b commit 70b8afa

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

main.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class HtmlView extends FileView {
177177
}
178178

179179
canAcceptExtension(extension: string): boolean {
180-
return extension === "html";
180+
return extension === "html" || extension === "htm";
181181
}
182182

183183
async onLoadFile(file: TFile): Promise<void> {
@@ -258,7 +258,7 @@ export default class HtmlDocsPlugin extends Plugin {
258258
VIEW_TYPE_HTML,
259259
(leaf: WorkspaceLeaf) => new HtmlView(leaf),
260260
);
261-
this.registerExtensions(["html"], VIEW_TYPE_HTML);
261+
this.registerExtensions(["html", "htm"], VIEW_TYPE_HTML);
262262
this.registerExistingHtmlTabNavigation();
263263
this.registerThemeRefresh();
264264

@@ -267,7 +267,11 @@ export default class HtmlDocsPlugin extends Plugin {
267267
throw new Error("HTML Docs: app.embedRegistry is unavailable; cannot register HTML embeds.");
268268
}
269269
embedRegistry.registerExtension("html", (context, file) => new HtmlEmbed(context.containerEl, this, file));
270-
this.register(() => embedRegistry.unregisterExtension("html"));
270+
embedRegistry.registerExtension("htm", (context, file) => new HtmlEmbed(context.containerEl, this, file));
271+
this.register(() => {
272+
embedRegistry.unregisterExtension("html");
273+
embedRegistry.unregisterExtension("htm");
274+
});
271275

272276
// Obsidian hides files with unrecognized extensions in the file
273277
// explorer unless "Show all file types" is on; registering the
@@ -359,7 +363,7 @@ export default class HtmlDocsPlugin extends Plugin {
359363
const file =
360364
this.app.metadataCache.getFirstLinkpathDest(linkpath, sourcePath) ??
361365
this.app.vault.getAbstractFileByPath(linkpath);
362-
return file instanceof TFile && file.extension === "html" ? file : null;
366+
return file instanceof TFile && (file.extension === "html" || file.extension === "htm") ? file : null;
363367
}
364368

365369
private findOpenHtmlLeaf(file: TFile): WorkspaceLeaf | null {

test/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,9 @@ check "theme class re-render flips scheme" "$(echo "$THEME_RERENDER" | jq -r '.a
447447
check "theme class re-render swaps blob" "$(echo "$THEME_RERENDER" | jq -r .rerendered)" "true"
448448
check "theme class test restores classes" "$(echo "$THEME_RERENDER" | jq -r .restored)" "true"
449449
check ".html routes to html-docs view" "$(echo "$REGISTRY" | jq -r .htmlViewType)" "html-docs"
450-
check ".htm is not registered" "$(echo "$REGISTRY" | jq -r .htmViewType)" "null"
450+
check ".htm routes to html-docs view" "$(echo "$REGISTRY" | jq -r .htmViewType)" "html-docs"
451451
check ".html embed registered" "$(echo "$REGISTRY" | jq -r .htmlEmbedRegistered)" "true"
452-
check ".htm embed not registered" "$(echo "$REGISTRY" | jq -r .htmEmbedRegistered)" "false"
452+
check ".htm embed registered" "$(echo "$REGISTRY" | jq -r .htmEmbedRegistered)" "true"
453453
check "open existing html tab from link" "$(echo "$DEDUPED_NAVIGATION" | jq -r .htmlLeafCount)" "1"
454454
check "existing html tab is focused" "$(echo "$DEDUPED_NAVIGATION" | jq -r .activeFile)" "$FIXTURE_REL"
455455
check "deferred html state is reused" "$(echo "$DEFERRED_STATE_NAVIGATION" | jq -r .activeIsFakeDeferredLeaf)" "true"

0 commit comments

Comments
 (0)