Skip to content

Commit

Permalink
Fix media snippet markup insertion to article content's #874
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Oct 23, 2024
1 parent 9f2aa34 commit 1d485ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### 🐞 Fixes

- [#874](https://github.com/estruyf/vscode-front-matter/issues/874): Fix media snippet markup insertion to article content's

## [10.5.0] - 2024-10-21 - [Release notes](https://beta.frontmatter.codes/updates/v10.5.0)

### 🎨 Enhancements
Expand Down
17 changes: 14 additions & 3 deletions src/helpers/MediaHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SETTING_MEDIA_SUPPORTED_MIMETYPES
} from '../constants';
import { SortingOption } from '../dashboardWebView/models';
import { MediaInfo, MediaPaths, SortOrder, SortType } from '../models';
import { BlockFieldData, MediaInfo, MediaPaths, SortOrder, SortType } from '../models';
import { basename, join, parse, dirname, relative } from 'path';
import { statSync } from 'fs';
import { Uri, workspace, window, Position } from 'vscode';
Expand Down Expand Up @@ -376,7 +376,18 @@ export class MediaHelpers {
* Insert an image into the front matter or contents
* @param data
*/
public static async insertMediaToMarkdown(data: any) {
public static async insertMediaToMarkdown(data: {
file: string;
relPath: string;
snippet: string;
position: Position;
title?: string;
alt?: string;
caption?: string;
fieldName: string;
parents: string[];
blockData: BlockFieldData;
}) {
if (data?.file && data?.relPath) {
await EditorHelper.showFile(data.file);
Dashboard.resetViewData();
Expand Down Expand Up @@ -444,7 +455,7 @@ export class MediaHelpers {
const docType = Wysiwyg.getDocType(filePath);

let snippet = data.snippet || '';
if (!data.Snippet) {
if (!snippet) {
if (docType === 'markdown') {
snippet = `${isFile ? '' : '!'}[${caption}](${FrameworkDetector.relAssetPathUpdate(
relPath,
Expand Down

0 comments on commit 1d485ad

Please sign in to comment.