Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class HtmlView extends FileView {
}

canAcceptExtension(extension: string): boolean {
return extension === "html";
return extension === "html" || extension === "htm";
}

async onLoadFile(file: TFile): Promise<void> {
Expand Down Expand Up @@ -258,7 +258,7 @@ export default class HtmlDocsPlugin extends Plugin {
VIEW_TYPE_HTML,
(leaf: WorkspaceLeaf) => new HtmlView(leaf),
);
this.registerExtensions(["html"], VIEW_TYPE_HTML);
this.registerExtensions(["html", "htm"], VIEW_TYPE_HTML);
this.registerExistingHtmlTabNavigation();
this.registerThemeRefresh();

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

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

private findOpenHtmlLeaf(file: TFile): WorkspaceLeaf | null {
Expand Down
4 changes: 2 additions & 2 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ check "theme class re-render flips scheme" "$(echo "$THEME_RERENDER" | jq -r '.a
check "theme class re-render swaps blob" "$(echo "$THEME_RERENDER" | jq -r .rerendered)" "true"
check "theme class test restores classes" "$(echo "$THEME_RERENDER" | jq -r .restored)" "true"
check ".html routes to html-docs view" "$(echo "$REGISTRY" | jq -r .htmlViewType)" "html-docs"
check ".htm is not registered" "$(echo "$REGISTRY" | jq -r .htmViewType)" "null"
check ".htm routes to html-docs view" "$(echo "$REGISTRY" | jq -r .htmViewType)" "html-docs"
check ".html embed registered" "$(echo "$REGISTRY" | jq -r .htmlEmbedRegistered)" "true"
check ".htm embed not registered" "$(echo "$REGISTRY" | jq -r .htmEmbedRegistered)" "false"
check ".htm embed registered" "$(echo "$REGISTRY" | jq -r .htmEmbedRegistered)" "true"
check "open existing html tab from link" "$(echo "$DEDUPED_NAVIGATION" | jq -r .htmlLeafCount)" "1"
check "existing html tab is focused" "$(echo "$DEDUPED_NAVIGATION" | jq -r .activeFile)" "$FIXTURE_REL"
check "deferred html state is reused" "$(echo "$DEFERRED_STATE_NAVIGATION" | jq -r .activeIsFakeDeferredLeaf)" "true"
Expand Down