diff --git a/apps/web/package.json b/apps/web/package.json index dd1f0ae..1ebc570 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -18,9 +18,10 @@ "bcrypt": "^5.1.0", "date-fns": "^2.29.3", "debounce": "^1.2.1", - "marked": "^4.3.0", + "marked": "^5.0.0", + "marked-highlight": "^1.0.1", "cheerio": "1.0.0-rc.12", - "highlight.js": "^11.7.0", + "highlight.js": "^11.8.0", "jsonwebtoken": "^9.0.0", "trpc-sveltekit": "^3.5.1" }, @@ -33,7 +34,7 @@ "@types/bcrypt": "^5.0.0", "@types/debounce": "^1.2.1", "@types/jsonwebtoken": "^9.0.1", - "@types/marked": "^4.0.8", + "@types/marked": "^4.3.0", "@types/node": "18.15.5", "svelte": "^3.57.0", "svelte-check": "^3.1.4", diff --git a/apps/web/src/lib/components/testview/TestResult.svelte b/apps/web/src/lib/components/testview/TestResult.svelte index 5f15e90..e6449f0 100644 --- a/apps/web/src/lib/components/testview/TestResult.svelte +++ b/apps/web/src/lib/components/testview/TestResult.svelte @@ -38,20 +38,12 @@ let isDarkMode: boolean = false; - import hljs from 'highlight.js'; import 'highlight.js/styles/github-dark.css'; - import { onMount } from 'svelte'; import type { Answer, Heading, Prisma, Question, Submission } from '@testy/database'; import Answers from './Answers.svelte'; import { getInBetweenQuestionRows } from '$lib/utils/headings'; - - onMount(() => { - document.querySelectorAll('.description code').forEach((el) => { - hljs.highlightElement(el as HTMLElement); - }); - });
{ }; export const parseMd = async (md: string, timeLimit: number): Promise => { + marked.use( + markedHighlight({ + langPrefix: 'hljs language-', + highlight(code: string, lang: string) { + const language = hljs.getLanguage(lang) ? lang : 'plaintext'; + return hljs.highlight(code, { language }).value; + } + }) + ); const html = marked.parse(md); console.log(html); const document = load(html); diff --git a/apps/web/src/routes/(user)/(authenticated)/home/test/[id]/+page.svelte b/apps/web/src/routes/(user)/(authenticated)/home/test/[id]/+page.svelte index a0e9de1..0155479 100644 --- a/apps/web/src/routes/(user)/(authenticated)/home/test/[id]/+page.svelte +++ b/apps/web/src/routes/(user)/(authenticated)/home/test/[id]/+page.svelte @@ -41,7 +41,6 @@ let isDarkMode: boolean = false; - import hljs from 'highlight.js'; import 'highlight.js/styles/github-dark.css'; import { onDestroy, onMount } from 'svelte'; @@ -51,16 +50,6 @@ import { getInBetweenQuestionRows } from '$lib/utils/headings'; onMount(() => { - document.querySelectorAll('.description code').forEach((el) => { - // create pre element and insert it before the code element and put the code element inside the pre element - const pre = document.createElement('pre'); - pre.className = 'hljs'; - el.parentNode?.insertBefore(pre, el); - pre.appendChild(el); - - hljs.highlightElement(el as HTMLElement); - }); - updateTimeRemaining(); updateTimeRemainingInterval = setInterval(() => updateTimeRemaining(), 1000); }); @@ -156,7 +145,7 @@ {/if} {#if heading && heading.description}

{@html heading.description}

@@ -203,7 +192,7 @@