Compare commits

...

2 Commits

Author SHA1 Message Date
Riccardo Ferretti
53c758f5d4 lint 2022-11-01 19:21:20 +01:00
Riccardo Ferretti
d1e71953af Fixed regex 2022-11-01 19:14:57 +01:00
2 changed files with 15 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ import { FoamWorkspace } from '../model/workspace';
import { IDisposable } from '../common/lifecycle';
import { ResourceProvider } from '../model/provider';
import { getFoamVsCodeConfig } from '../../services/config';
import { imageExtensions } from '../../utils';
const attachmentExtConfig = getFoamVsCodeConfig(
'files.attachmentExtensions',
@@ -12,7 +13,6 @@ const attachmentExtConfig = getFoamVsCodeConfig(
.split(' ')
.map(ext => '.' + ext.trim());
const imageExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'];
const attachmentExtensions = [...attachmentExtConfig, ...imageExtensions];
const asResource = (uri: URI): Resource => {

View File

@@ -22,6 +22,15 @@ export const mdDocSelector = [
{ language: 'markdown', scheme: 'untitled' },
];
export const imageExtensions = [
'.png',
'.jpg',
'.jpeg',
'.gif',
'.svg',
'.webp',
];
export function loadDocConfig() {
// Load workspace config
const activeEditor = window.activeTextEditor;
@@ -215,9 +224,10 @@ export function stripFrontMatter(markdown: string): string {
return matter(markdown).content.trim();
}
const imgRegex = new RegExp(
`!\\[(.*)\\]\\(.*(${imageExtensions.join('|')})\\)`
);
export function stripImages(markdown: string): string {
return markdown.replace(
/!\[(.*)\]\([-/\\.A-Za-z]*\)/gi,
'$1'.length ? '[Image: $1]' : ''
);
return markdown.replace(imgRegex, '$1'.length ? '[Image: $1]' : '');
}