Skip to content

Commit dd0cce5

Browse files
authored
fix: support percentage sizes in wiki link images (#120)
1 parent 85481db commit dd0cce5

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const ATTACHMENT_URL_REGEXP =
2-
/!\[\[((.*?)\.(\w+))(?:\s*\|\s*(?<width>\d+)\s*(?:[*|x]\s*(?<height>\d+))?)?\]\]/g;
2+
/!\[\[((.*?)\.(\w+))(?:\s*\|\s*(?<width>\d+%?)\s*(?:[*|x]\s*(?<height>\d+%?))?)?\]\]/g;
33

44
export const MARKDOWN_ATTACHMENT_URL_REGEXP = /!\[(.*?)\]\(((.*?)\.(\w+))\)/g;
55

src/utils.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,13 +771,18 @@ export async function tryCopyMarkdownByRead(
771771
if (plugin.settings.displayImageAsHtml) {
772772
const { width = null, height = null } =
773773
imageLinks[index]?.groups || {};
774+
// Helper to format size value - append 'px' only if not a percentage
775+
const formatSize = (value: string | null) => {
776+
if (!value) return "";
777+
return value.includes("%") ? value : `${value}px`;
778+
};
774779
const style =
775780
width && height
776-
? ` style='width: {${width}}px; height: ${height}px;'`
781+
? ` style='width: ${formatSize(width)}; height: ${formatSize(height)};'`
777782
: width
778-
? ` style='width: ${width}px;'`
783+
? ` style='width: ${formatSize(width)};'`
779784
: height
780-
? ` style='height: ${height}px;'`
785+
? ` style='height: ${formatSize(height)};'`
781786
: "";
782787

783788
content = content.replace(

0 commit comments

Comments
 (0)