mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
limited latex support
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 })
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user