colored diff

This commit is contained in:
mbecker20
2024-05-10 01:03:23 -07:00
parent ba19e45607
commit c7124bd63c
7 changed files with 62 additions and 61 deletions

View File

@@ -1,7 +1,9 @@
import { ResourceComponents } from "@components/resources";
import { Types } from "@monitor/client";
import { UsableResource } from "@types";
import Convert from "ansi-to-html";
import { type ClassValue, clsx } from "clsx";
import sanitizeHtml from "sanitize-html";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
@@ -96,3 +98,20 @@ export const usableResourcePath = (resource: UsableResource) => {
if (resource === "ServerTemplate") return "server-templates"
return `${resource.toLowerCase()}s`
}
const convert = new Convert();
/**
* Converts the ansi colors in log to html.
* sanitizes incoming log first for any eg. script tags.
* @param log incoming log string
*/
export const logToHtml = (log: string) => {
if (!log) return "No log.";
const sanitized = sanitizeHtml(log, {
allowedTags: sanitizeHtml.defaults.allowedTags.filter(
(tag) => tag !== "script"
),
allowedAttributes: sanitizeHtml.defaults.allowedAttributes,
});
return convert.toHtml(sanitized);
};