refactor: class-methods-use-this

This commit is contained in:
Tibo De Peuter 2025-03-23 13:39:10 +01:00
parent a42add7131
commit af57cb5d71
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
12 changed files with 48 additions and 45 deletions

View file

@ -15,11 +15,20 @@ class MarkdownProcessor extends StringProcessor {
super(DwengoContentType.TEXT_MARKDOWN);
}
static replaceLinks(html: string): string {
const proc = new InlineImageProcessor();
html = html.replace(
/<img.*?src="(.*?)".*?(alt="(.*?)")?.*?(title="(.*?)")?.*?>/g,
(_match: string, src: string, _alt: string, _altText: string, _title: string, _titleText: string) => proc.render(src)
);
return html;
}
override renderFn(mdText: string): string {
try {
marked.use({ renderer: dwengoMarkedRenderer });
const html = marked(mdText, { async: false });
return this.replaceLinks(html); // Replace html image links path
return MarkdownProcessor.replaceLinks(html); // Replace html image links path
} catch (e: unknown) {
if (e instanceof YAMLException) {
throw new ProcessingError(e.message);
@ -28,15 +37,6 @@ class MarkdownProcessor extends StringProcessor {
throw new ProcessingError('Unknown error while processing markdown: ' + e);
}
}
replaceLinks(html: string): string {
const proc = new InlineImageProcessor();
html = html.replace(
/<img.*?src="(.*?)".*?(alt="(.*?)")?.*?(title="(.*?)")?.*?>/g,
(_match: string, src: string, _alt: string, _altText: string, _title: string, _titleText: string) => proc.render(src)
);
return html;
}
}
export { MarkdownProcessor };