@@ -11,6 +11,10 @@ import {
1111} from "obsidian" ;
1212
1313const VIEW_TYPE_HTML = "html-docs" ;
14+ const HTML_EXTENSIONS = [ "html" , "htm" ] as const ;
15+ type HtmlExtension = ( typeof HTML_EXTENSIONS ) [ number ] ;
16+ const isHtmlExtension = ( ext : string ) : ext is HtmlExtension =>
17+ ( HTML_EXTENSIONS as readonly string [ ] ) . includes ( ext ) ;
1418
1519interface EmbedContext {
1620 containerEl : HTMLElement ;
@@ -177,7 +181,7 @@ class HtmlView extends FileView {
177181 }
178182
179183 canAcceptExtension ( extension : string ) : boolean {
180- return extension === "html" ;
184+ return isHtmlExtension ( extension ) ;
181185 }
182186
183187 async onLoadFile ( file : TFile ) : Promise < void > {
@@ -258,16 +262,18 @@ export default class HtmlDocsPlugin extends Plugin {
258262 VIEW_TYPE_HTML ,
259263 ( leaf : WorkspaceLeaf ) => new HtmlView ( leaf ) ,
260264 ) ;
261- this . registerExtensions ( [ "html" ] , VIEW_TYPE_HTML ) ;
265+ this . registerExtensions ( [ ... HTML_EXTENSIONS ] , VIEW_TYPE_HTML ) ;
262266 this . registerExistingHtmlTabNavigation ( ) ;
263267 this . registerThemeRefresh ( ) ;
264268
265269 const embedRegistry = ( this . app as unknown as AppWithEmbedRegistry ) . embedRegistry ;
266270 if ( ! embedRegistry ) {
267271 throw new Error ( "HTML Docs: app.embedRegistry is unavailable; cannot register HTML embeds." ) ;
268272 }
269- embedRegistry . registerExtension ( "html" , ( context , file ) => new HtmlEmbed ( context . containerEl , this , file ) ) ;
270- this . register ( ( ) => embedRegistry . unregisterExtension ( "html" ) ) ;
273+ for ( const ext of HTML_EXTENSIONS ) {
274+ embedRegistry . registerExtension ( ext , ( context , file ) => new HtmlEmbed ( context . containerEl , this , file ) ) ;
275+ this . register ( ( ) => embedRegistry . unregisterExtension ( ext ) ) ;
276+ }
271277
272278 // Obsidian hides files with unrecognized extensions in the file
273279 // explorer unless "Show all file types" is on; registering the
@@ -359,7 +365,7 @@ export default class HtmlDocsPlugin extends Plugin {
359365 const file =
360366 this . app . metadataCache . getFirstLinkpathDest ( linkpath , sourcePath ) ??
361367 this . app . vault . getAbstractFileByPath ( linkpath ) ;
362- return file instanceof TFile && file . extension === "html" ? file : null ;
368+ return file instanceof TFile && isHtmlExtension ( file . extension ) ? file : null ;
363369 }
364370
365371 private findOpenHtmlLeaf ( file : TFile ) : WorkspaceLeaf | null {
0 commit comments