Event description now supports markdown formatting (#3688)

* yarn

* yarn update

* added Mardown style formatting with sanitized inputs

* Revert "yarn"

This reverts commit 46eb3595cf687504c6783315749b3124936080b9.

* Revert "yarn"

This reverts commit 46eb3595cf687504c6783315749b3124936080b9.

* Revert "yarn update"

This reverts commit f4600d83a67b930c6dd72e292827578856ca5428.

* Revert "yarn"

This reverts commit 46eb3595cf687504c6783315749b3124936080b9.

* Revert "yarn update"

This reverts commit f4600d83a67b930c6dd72e292827578856ca5428.

* Revert "Revert "yarn update""

This reverts commit 8ccab5ee237fb228115229f3c89cf4b848bc9449.

* Revert "Revert "yarn""

This reverts commit 78a755eb39cb518eb0526272a3c11882c48004de.

* yarn.lock removed

* Parses using prisma middleware

* Reverting changes

* Fixes hydration warning

* Fixes Dom warnings

* Update yarn.lock

Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: zomars <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-08-05 18:44:30 +00:00
1 parent be16b72400
commit ff3bd5fc61
10 files changed
+114 -14

No files matched your search

+2 -1
View File
@@ -1,6 +1,6 @@
import { Prisma, PrismaClient } from "@prisma/client";
import { bookingReferenceMiddleware } from "./middleware";
import { bookingReferenceMiddleware, eventTypeDescriptionParseAndSanitizeMiddleware } from "./middleware";
declare global {
// eslint-disable-next-line no-var
@@ -21,6 +21,7 @@ if (process.env.NODE_ENV !== "production") {
}
// If any changed on middleware server restart is required
bookingReferenceMiddleware(prisma);
eventTypeDescriptionParseAndSanitizeMiddleware(prisma);
export default prisma;
@@ -1,6 +1,6 @@
import { PrismaClient } from "@prisma/client";
async function middleware(prisma: PrismaClient) {
function middleware(prisma: PrismaClient) {
/***********************************/
/* SOFT DELETE MIDDLEWARE */
/***********************************/
@@ -0,0 +1,40 @@
import type { PrismaClient } from "@prisma/client";
import MarkdownIt from "markdown-it";
const md = new MarkdownIt("zero").enable([
//
"emphasis",
"list",
"newline",
"strikethrough",
]);
function parseAndSanitize(description: string) {
const parsedMarkdown = md.render(description);
return parsedMarkdown;
}
/**
* Parses event type descriptions and treat them as markdown,
* then sanitizes the resulting HTML and adds a new `descriptionAsSafeHTML` property.
*/
function eventTypeDescriptionParseAndSanitize(prisma: PrismaClient) {
prisma.$use(async (params, next) => {
if (params.model === "EventType") {
const result = await next(params);
if (result) {
const results = Array.isArray(result) ? result : [result];
const parsedResults = results.map((record) => ({
...record,
descriptionAsSafeHTML: record.description ? parseAndSanitize(record.description) : null,
}));
/* If the original result was an array, return the parsed array, otherwise is a single record */
return Array.isArray(result) ? parsedResults : parsedResults[0];
}
return result;
}
return next(params);
});
}
export default eventTypeDescriptionParseAndSanitize;
+1
View File
@@ -1 +1,2 @@
export { default as bookingReferenceMiddleware } from "./bookingReference";
export { default as eventTypeDescriptionParseAndSanitizeMiddleware } from "./eventTypeDescriptionParseAndSanitize";