limited latex support

This commit is contained in:
2024-09-18 21:50:40 -06:00
parent 31f39b8193
commit 395e9934e6
12 changed files with 195 additions and 50 deletions

View File

@@ -31,20 +31,26 @@ axiosClient.interceptors.response.use(
(response) => response,
(error: AxiosError) => {
if (error.response) {
console.log("response error", error.response);
// console.log("response error", error.response);
const responseErrorText =
typeof error.response.data === "object"
? (error.response.data as any).error
: error.response.data;
toast.error(
`Error: ${error.response.status} - ${responseErrorText}, ${decodeURI(
error.response.config.url ?? ""
)}`
);
if (!isServer) {
toast.error(
`Error: ${error.response.status} - ${responseErrorText}, ${decodeURI(
error.response.config.url ?? ""
)}`
);
}
} else if (error.request) {
toast.error("Error: No response from server");
if (!isServer) {
toast.error("Error: No response from server");
}
} else {
toast.error(`Error: ${error.message}`);
if (!isServer) {
toast.error(`Error: ${error.message}`);
}
}
return Promise.reject(error);
}

View File

@@ -5,6 +5,10 @@ import { axiosClient } from "../axiosUtils";
import { markdownToHTMLSafe } from "../htmlMarkdownUtils";
import { CanvasRubricCreationResponse } from "@/models/canvas/assignments/canvasRubricCreationResponse";
import { assignmentPoints } from "@/models/local/assignment/utils/assignmentPointsUtils";
import {
getDateFromString,
getDateFromStringOrThrow,
} from "@/models/local/timeUtils";
const createRubric = async (
courseId: number,
@@ -77,18 +81,22 @@ export const canvasAssignmentService = {
console.log(`Creating assignment: ${localAssignment.name}`);
const url = `${canvasApi}/courses/${canvasCourseId}/assignments`;
const body = {
name: localAssignment.name,
submission_types: localAssignment.submissionTypes.map((t) =>
t.toString()
),
allowed_extensions: localAssignment.allowedFileUploadExtensions.map((e) =>
e.toString()
),
description: markdownToHTMLSafe(localAssignment.description),
due_at: localAssignment.dueAt,
lock_at: localAssignment.lockAt,
points_possible: assignmentPoints(localAssignment),
assignment_group_id: canvasAssignmentGroupId,
assignment: {
name: localAssignment.name,
submission_types: localAssignment.submissionTypes.map((t) =>
t.toString()
),
allowed_extensions: localAssignment.allowedFileUploadExtensions.map(
(e) => e.toString()
),
description: markdownToHTMLSafe(localAssignment.description),
due_at: getDateFromString(localAssignment.dueAt)?.toISOString(),
lock_at:
localAssignment.lockAt &&
getDateFromString(localAssignment.lockAt)?.toISOString(),
points_possible: assignmentPoints(localAssignment),
assignment_group_id: canvasAssignmentGroupId,
},
};
const response = await axiosClient.post<CanvasAssignment>(url, body);

View File

@@ -1,8 +1,16 @@
"use client";
import { marked } from "marked";
import markedKatex from "marked-katex-extension";
import * as DOMPurify from "isomorphic-dompurify";
export function markdownToHTMLSafe(markdownString: string) {
const options = {
throwOnError: false,
nonStandard: true
};
marked.use(markedKatex(options));
const clean = DOMPurify.sanitize(
marked.parse(markdownString, { async: false, pedantic: false, gfm: true })
);