Skip to content

Commit f50e81b

Browse files
author
Ozan Tellioglu
committed
Webp Support for Images
1 parent 46c3268 commit f50e81b

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/cm6/linkDetector.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export const detectLink = (params: { lineText: string; sourceFile: TFile; plugin
2626

2727
// --> A. Internal Image Links
2828
// 1. [[ ]] format
29-
const internalImageWikiRegex = /!\[\[.*?(jpe?g|png|gif|svg|bmp).*?\]\]/;
29+
const internalImageWikiRegex = /!\[\[.*?(jpe?g|png|gif|svg|bmp|webp).*?\]\]/;
3030
const internalImageWikiMatch = lineText.match(internalImageWikiRegex);
3131

3232
if (internalImageWikiMatch) {
33-
const fileNameRegex = /\[\[.*(jpe?g|png|gif|svg|bmp)/;
33+
const fileNameRegex = /\[\[.*(jpe?g|png|gif|svg|bmp|webp)/;
3434
const fileMatch = internalImageWikiMatch[0].match(fileNameRegex);
3535
if (fileMatch) {
3636
const fileMatchClear = fileMatch[0].replace('[[', '');
@@ -136,11 +136,11 @@ export const detectLink = (params: { lineText: string; sourceFile: TFile; plugin
136136
}
137137

138138
// 2. ![ ]( ) format
139-
const internalImageMdRegex = /!\[(^$|.*?)\]\(.*?(jpe?g|png|gif|svg|bmp)\)/;
139+
const internalImageMdRegex = /!\[(^$|.*?)\]\(.*?(jpe?g|png|gif|svg|bmp|webp)\)/;
140140
const internalImageMdMatch = lineText.match(internalImageMdRegex);
141141

142142
if (internalImageMdMatch) {
143-
const fileNameRegex = /\(.*(jpe?g|png|gif|svg|bmp)/;
143+
const fileNameRegex = /\(.*(jpe?g|png|gif|svg|bmp|webp)/;
144144
const fileMatch = internalImageMdMatch[0].match(fileNameRegex);
145145
if (fileMatch) {
146146
const fileMatchClear = fileMatch[0].replace('(', '');
@@ -322,8 +322,8 @@ export const detectLink = (params: { lineText: string; sourceFile: TFile; plugin
322322
*/
323323

324324
// --> G: Local File Markdown
325-
const localFileMdRegex = /!\[(^$|.*)\]\((file\:\/\/\/|app\:\/\/local\/).*(.pdf|.jpe?g|.png|.gif|.svg|.bmp)(.*)?\)/;
326-
const localFileNameRegex = /(file\:\/\/\/|app\:\/\/local\/).*(.pdf|.jpe?g|.png|.gif|.svg|.bmp)/;
325+
const localFileMdRegex = /!\[(^$|.*)\]\((file\:\/\/\/|app\:\/\/local\/).*(.pdf|.jpe?g|.png|.gif|.svg|.bmp|.webp)(.*)?\)/;
326+
const localFileNameRegex = /(file\:\/\/\/|app\:\/\/local\/).*(.pdf|.jpe?g|.png|.gif|.svg|.bmp|.webp)/;
327327
const localFileMatchMd = lineText.match(localFileMdRegex);
328328

329329
if (localFileMatchMd) {

src/util/imageHandler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { Menu, TFile } from 'obsidian';
22
import OzanImagePlugin from 'src/main';
33

44
// General Image Regex
5-
const image_regex = /.*.(jpe?g|png|gif|svg|bmp)/;
5+
const image_regex = /.*.(jpe?g|png|gif|svg|bmp|webp)/;
66

77
// Regex for [[ ]] format
8-
const image_line_regex_1 = /!\[\[.*?(jpe?g|png|gif|svg|bmp).*?\]\]/;
9-
const file_name_regex_1 = /\[\[.*(jpe?g|png|gif|svg|bmp)/;
8+
const image_line_regex_1 = /!\[\[.*?(jpe?g|png|gif|svg|bmp|webp).*?\]\]/;
9+
const file_name_regex_1 = /\[\[.*(jpe?g|png|gif|svg|bmp|webp)/;
1010

1111
// Regex for ![ ]( ) format
12-
const image_line_regex_2 = /!\[(^$|.*?)\]\(.*?(jpe?g|png|gif|svg|bmp)\)/;
13-
const file_name_regex_2 = /\(.*(jpe?g|png|gif|svg|bmp)/;
12+
const image_line_regex_2 = /!\[(^$|.*?)\]\(.*?(jpe?g|png|gif|svg|bmp|webp)\)/;
13+
const file_name_regex_2 = /\(.*(jpe?g|png|gif|svg|bmp|webp)/;
1414

1515
// Regex for Links
1616
const file_name_regex_3 = /\[\[.*(?=\|)|\[\[.*(?=\]\])/;

0 commit comments

Comments
 (0)