Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix editor katex expressions #162

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions apps/api/src/app/cards/dto/createCard.dto.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,59 @@
import { IsNotEmpty, IsNumber, IsOptional, IsString, IsUUID, Max, Min } from "class-validator";
import {
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
IsUUID,
Max,
Min,
} from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
import { Transform, TransformFnParams } from "class-transformer";
import * as sanitizeHtml from "sanitize-html";
import { sanitizationConfig } from "../../shared/sanitization/sanitization-config";

export class CreateCardDto {
@ApiProperty({
description: "The ID of the set that the card will belong to",
example: "27758237-5f57-4f6c-b483-6161056dad76",
minLength: 36,
maxLength: 36
maxLength: 36,
})
@IsUUID("4")
@IsNotEmpty()
setId: string;
setId: string;

@ApiProperty({
description: "The index of the card in the set",
example: 0,
minimum: 0,
maximum: 2147483647
maximum: 2147483647,
})
@IsNumber()
@Min(0)
@Max(2147483647)
@IsOptional()
index: number;
index: number;

@ApiProperty({
description: "The front or \"term\" of the card",
example: "The definition of the card"
description: 'The front or "term" of the card',
example: "The definition of the card",
})
@IsString()
@IsNotEmpty()
@Transform((params: TransformFnParams) => sanitizeHtml(params.value, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedAttributes: { "img": ["src", "width", "height"], "span": ["style"] },
allowedSchemes: ["data"]
}))
term: string;
@Transform((params: TransformFnParams) =>
sanitizeHtml(params.value, sanitizationConfig)
)
term: string;

@ApiProperty({
description: "The back or \"definition\" of the card",
example: "The definition of the card"
description: 'The back or "definition" of the card',
example: "The definition of the card",
})
@IsString()
@IsNotEmpty()
@Transform((params: TransformFnParams) => sanitizeHtml(params.value, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedAttributes: { "img": ["src", "width", "height"], "span": ["style"] },
allowedSchemes: ["data"]
}))
definition: string;
@Transform((params: TransformFnParams) =>
sanitizeHtml(params.value, sanitizationConfig)
)
definition: string;
}
42 changes: 23 additions & 19 deletions apps/api/src/app/cards/dto/updateCard.dto.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
import { IsNotEmpty, IsNumber, IsOptional, IsString, Max, Min } from "class-validator";
import {
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
Max,
Min,
} from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
import { Transform, TransformFnParams } from "class-transformer";
import * as sanitizeHtml from "sanitize-html";
import { sanitizationConfig } from "../../shared/sanitization/sanitization-config";

export class UpdateCardDto {
@ApiProperty({
description: "The index of the card in the set",
example: 0,
required: false,
minimum: 0,
maximum: 2147483647
maximum: 2147483647,
})
@IsNumber()
@IsOptional()
@Min(0)
@Max(2147483647)
@IsNotEmpty()
index?: number;
index?: number;

@ApiProperty({
description: "The front or \"term\" of the card",
description: 'The front or "term" of the card',
example: "The definition of the card",
required: false
required: false,
})
@IsString()
@IsOptional()
@IsNotEmpty()
@Transform((params: TransformFnParams) => sanitizeHtml(params.value, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedAttributes: { "img": ["src", "width", "height"], "span": ["style"] },
allowedSchemes: ["data"]
}))
term?: string;
@Transform((params: TransformFnParams) =>
sanitizeHtml(params.value, sanitizationConfig)
)
term?: string;

@ApiProperty({
description: "The back or \"definition\" of the card",
description: 'The back or "definition" of the card',
example: "The definition of the card",
required: false
required: false,
})
@IsString()
@IsOptional()
@IsNotEmpty()
@Transform((params: TransformFnParams) => sanitizeHtml(params.value, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedAttributes: { "img": ["src", "width", "height"], "span": ["style"] },
allowedSchemes: ["data"]
}))
definition?: string;
@Transform((params: TransformFnParams) =>
sanitizeHtml(params.value, sanitizationConfig)
)
definition?: string;
}
33 changes: 15 additions & 18 deletions apps/api/src/app/sets/validator/card.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,40 @@ import { IsNotEmpty, IsNumber, IsString, Max, Min } from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
import { Transform, TransformFnParams } from "class-transformer";
import * as sanitizeHtml from "sanitize-html";
import { sanitizationConfig } from "../../shared/sanitization/sanitization-config";

export class CardValidator {
@ApiProperty({
description: "The index of the card in the set",
example: 0,
minimum: 0,
maximum: 2147483647
maximum: 2147483647,
})
@IsNumber()
@Min(0)
@Max(2147483647)
@IsNotEmpty()
index: number;
index: number;

@ApiProperty({
description: "The front or \"term\" of the card",
example: "The term of the card"
description: 'The front or "term" of the card',
example: "The term of the card",
})
@IsString()
@IsNotEmpty()
@Transform((params: TransformFnParams) => sanitizeHtml(params.value, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedAttributes: { "img": ["src", "width", "height"], "span": ["style"] },
allowedSchemes: ["data"]
}))
term: string;
@Transform((params: TransformFnParams) =>
sanitizeHtml(params.value, sanitizationConfig)
)
term: string;

@ApiProperty({
description: "The back or \"definition\" of the card",
example: "The definition of the card"
description: 'The back or "definition" of the card',
example: "The definition of the card",
})
@IsString()
@IsNotEmpty()
@Transform((params: TransformFnParams) => sanitizeHtml(params.value, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedAttributes: { "img": ["src", "width", "height"], "span": ["style"] },
allowedSchemes: ["data"]
}))
definition: string;
@Transform((params: TransformFnParams) =>
sanitizeHtml(params.value, sanitizationConfig)
)
definition: string;
}
46 changes: 25 additions & 21 deletions apps/api/src/app/sets/validator/cardWithId.validator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { IsNotEmpty, IsNumber, IsOptional, IsString, Max, Min } from "class-validator";
import {
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
Max,
Min,
} from "class-validator";
import { Transform, TransformFnParams } from "class-transformer";
import * as sanitizeHtml from "sanitize-html";
import { ApiProperty } from "@nestjs/swagger";
import { sanitizationConfig } from "../../shared/sanitization/sanitization-config";

export class CardWithIdValidator {
/*
Expand All @@ -11,46 +19,42 @@ export class CardWithIdValidator {
description: "The ID of the card",
example: "27758237-5f57-4f6c-b483-6161056dad76",
maxLength: 36,
minLength: 36
minLength: 36,
})
@IsOptional()
id?: string;
id?: string;

@ApiProperty({
description: "The index of the card in the set",
example: 0,
minimum: 0,
maximum: 2147483647
maximum: 2147483647,
})
@IsNumber()
@Min(0)
@Max(2147483647)
@IsNotEmpty()
index: number;
index: number;

@ApiProperty({
description: "The front or \"term\" of the card",
example: "The term of the card"
description: 'The front or "term" of the card',
example: "The term of the card",
})
@IsString()
@IsNotEmpty()
@Transform((params: TransformFnParams) => sanitizeHtml(params.value, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedAttributes: { "img": ["src", "width", "height"], "span": ["style"] },
allowedSchemes: ["data"]
}))
term: string;
@Transform((params: TransformFnParams) =>
sanitizeHtml(params.value, sanitizationConfig)
)
term: string;

@ApiProperty({
description: "The back or \"definition\" of the card",
example: "The definition of the card"
description: 'The back or "definition" of the card',
example: "The definition of the card",
})
@IsString()
@IsNotEmpty()
@Transform((params: TransformFnParams) => sanitizeHtml(params.value, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
allowedAttributes: { "img": ["src", "width", "height"], "span": ["style"] },
allowedSchemes: ["data"]
}))
definition: string;
@Transform((params: TransformFnParams) =>
sanitizeHtml(params.value, sanitizationConfig)
)
definition: string;
}
Loading
Loading