Changeset View
Changeset View
Standalone View
Standalone View
src/app/_pipes/marked.pipe.ts
Show All 21 Lines | getImageMatchesByGroup(index: number, str: string, reg: RegExp): string[] { | ||||
while ((match = reg.exec(str))) { | while ((match = reg.exec(str))) { | ||||
if (match[index] !== undefined) { | if (match[index] !== undefined) { | ||||
matches.push(match[index]); | matches.push(match[index]); | ||||
} | } | ||||
} | } | ||||
return matches; | return matches; | ||||
} | } | ||||
transform(value: string, post: Post, comment: Comment): string { | transform(value: string, post?: Post, comment?: Comment): string { | ||||
md.use(markdownItRegex, { | md.use(markdownItRegex, { | ||||
name: 'customImage', | name: 'customImage', | ||||
regex: /(\[img: \d\])/gm, | regex: /(\[img: \d\])/gm, | ||||
replace: (match: string) => { | replace: (match: string) => { | ||||
const index = Number.parseInt(this.getImageMatchesByGroup(2, match, /(\[img: (\d)\])/gm)[0]); | const index = Number.parseInt(this.getImageMatchesByGroup(2, match, /(\[img: (\d)\])/gm)[0]); | ||||
if (!post.additional_images[index]) { | if (!post.additional_images[index]) { | ||||
return ''; | return ''; | ||||
Show All 11 Lines |