@@ -6,6 +6,7 @@ import { v4 as uuidv4 } from "uuid";
66import { JSDOM } from "jsdom" ;
77import { hasSomeRoles } from "./utils.js" ;
88import * as lucideIcons from "lucide-static" ;
9+ import { get } from "http" ;
910
1011const internalTags = {
1112 callout : {
@@ -668,15 +669,33 @@ function replaceObsidianImageLinks(html, req) {
668669 }
669670 }
670671 const serverUrl = `${ req . protocol } ://${ req . get ( "host" ) } ` ;
671- return `<img alt="${ fileName } " src="${ serverUrl } /${
672- dirPrefix + f
673- } " style="${ r ? `width: ${ r . width } ; height: ${ r . height } ;` : "" } " />`;
672+ return getHtmlFor ( getFileExtension ( f ) , fileName , serverUrl , dirPrefix , f ) ;
674673 } else {
675674 return match ;
676675 }
677676 } ) ;
678677}
679678
679+ const imageFileTypes = [ 'png' , 'jpg' , 'jpeg' , 'apng' , 'avif' , 'gif' , 'jfif' , 'pjpeg' , 'pjp' , 'svg' , 'webp' , 'bmp' , 'ico' , 'tiff' , 'tif' , 'heif' , 'heic' ] ;
680+
681+ function getHtmlFor ( fileType , fileName , serverUrl , dirPrefix , file ) {
682+ const type = fileType . toLowerCase ( ) ;
683+ if ( imageFileTypes . includes ( type ) ) {
684+ return `<img src="${ serverUrl } /${ dirPrefix + file } " alt="${ fileName } " style="${ r ? `width: ${ r . width } ; height: ${ r . height } ;` : "" } "/>` ;
685+ } else if ( type === "svg" ) {
686+ return `<img src="${ serverUrl } /${ dirPrefix + file } " alt="${ fileName } " />` ;
687+ } else if ( type === "pdf" ) {
688+ return `<iframe src="${ serverUrl } /${ dirPrefix + file } " style="${ r ? `width: ${ r . width } ; height: ${ r . height } ;` : "" } "></iframe>` ;
689+ } else if ( type === "mp4" ) {
690+ return `<video controls><source src="${ serverUrl } /${ dirPrefix + file } " type="video/mp4"></video>` ;
691+ } else if ( type === "webm" ) {
692+ return `<video controls><source src="${ serverUrl } /${ dirPrefix + file } " type="video/webm"></video>` ;
693+ } else if ( type === "ogg" ) {
694+ return `<audio controls><source src="${ serverUrl } /${ dirPrefix + file } " type="audio/ogg"></audio>` ;
695+ }
696+ return `${ serverUrl } /${ dirPrefix + file } ` ;
697+ }
698+
680699function replacePreMarkCallouts ( html ) {
681700 const regex = new RegExp (
682701 `${ internalTags . callout . regexp . start } ([\\s\\S]*?)${ internalTags . callout . regexp . end } ` ,
0 commit comments