refactor: class-methods-use-this
This commit is contained in:
parent
a42add7131
commit
af57cb5d71
12 changed files with 48 additions and 45 deletions
|
@ -14,7 +14,7 @@ class AudioProcessor extends StringProcessor {
|
|||
super(DwengoContentType.AUDIO_MPEG);
|
||||
}
|
||||
|
||||
protected renderFn(audioUrl: string): string {
|
||||
override renderFn(audioUrl: string): string {
|
||||
return DOMPurify.sanitize(`<audio controls>
|
||||
<source src="${audioUrl}" type=${type}>
|
||||
Your browser does not support the audio element.
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Category } from 'gift-pegjs';
|
|||
import { ProcessingError } from '../../processing-error.js';
|
||||
|
||||
export class CategoryQuestionRenderer extends GIFTQuestionRenderer<Category> {
|
||||
render(_question: Category, _questionNumber: number): string {
|
||||
override render(_question: Category, _questionNumber: number): string {
|
||||
throw new ProcessingError("The question type 'Category' is not supported yet!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Description } from 'gift-pegjs';
|
|||
import { ProcessingError } from '../../processing-error.js';
|
||||
|
||||
export class DescriptionQuestionRenderer extends GIFTQuestionRenderer<Description> {
|
||||
render(_question: Description, _questionNumber: number): string {
|
||||
override render(_question: Description, _questionNumber: number): string {
|
||||
throw new ProcessingError("The question type 'Description' is not supported yet!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { GIFTQuestionRenderer } from './gift-question-renderer.js';
|
|||
import { Essay } from 'gift-pegjs';
|
||||
|
||||
export class EssayQuestionRenderer extends GIFTQuestionRenderer<Essay> {
|
||||
render(question: Essay, questionNumber: number): string {
|
||||
override render(question: Essay, questionNumber: number): string {
|
||||
let renderedHtml = '';
|
||||
if (question.title) {
|
||||
renderedHtml += `<h2 class='gift-title' id='gift-q${questionNumber}-title'>${question.title}</h2>\n`;
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Matching } from 'gift-pegjs';
|
|||
import { ProcessingError } from '../../processing-error.js';
|
||||
|
||||
export class MatchingQuestionRenderer extends GIFTQuestionRenderer<Matching> {
|
||||
render(_question: Matching, _questionNumber: number): string {
|
||||
override render(_question: Matching, _questionNumber: number): string {
|
||||
throw new ProcessingError("The question type 'Matching' is not supported yet!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { GIFTQuestionRenderer } from './gift-question-renderer.js';
|
|||
import { MultipleChoice } from 'gift-pegjs';
|
||||
|
||||
export class MultipleChoiceQuestionRenderer extends GIFTQuestionRenderer<MultipleChoice> {
|
||||
render(question: MultipleChoice, questionNumber: number): string {
|
||||
override render(question: MultipleChoice, questionNumber: number): string {
|
||||
let renderedHtml = '';
|
||||
if (question.title) {
|
||||
renderedHtml += `<h2 class='gift-title' id='gift-q${questionNumber}-title'>${question.title}</h2>\n`;
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Numerical } from 'gift-pegjs';
|
|||
import { ProcessingError } from '../../processing-error.js';
|
||||
|
||||
export class NumericalQuestionRenderer extends GIFTQuestionRenderer<Numerical> {
|
||||
render(_question: Numerical, _questionNumber: number): string {
|
||||
override render(_question: Numerical, _questionNumber: number): string {
|
||||
throw new ProcessingError("The question type 'Numerical' is not supported yet!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { ShortAnswer } from 'gift-pegjs';
|
|||
import { ProcessingError } from '../../processing-error.js';
|
||||
|
||||
export class ShortQuestionRenderer extends GIFTQuestionRenderer<ShortAnswer> {
|
||||
render(_question: ShortAnswer, _questionNumber: number): string {
|
||||
override render(_question: ShortAnswer, _questionNumber: number): string {
|
||||
throw new ProcessingError("The question type 'ShortAnswer' is not supported yet!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { TrueFalse } from 'gift-pegjs';
|
|||
import { ProcessingError } from '../../processing-error.js';
|
||||
|
||||
export class TrueFalseQuestionRenderer extends GIFTQuestionRenderer<TrueFalse> {
|
||||
render(_question: TrueFalse, _questionNumber: number): string {
|
||||
override render(_question: TrueFalse, _questionNumber: number): string {
|
||||
throw new ProcessingError("The question type 'TrueFalse' is not supported yet!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue