Skip to content

Commit 9128ace

Browse files
chore(details): improve return type for detected languages
1 parent 103de36 commit 9128ace

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/routes/[pid=pid]/[org]/[repo]/[id=number]/PageRenderer.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import rehypeShikiFromHighlighter from "@shikijs/rehype/core";
3333
import { transformerNotationDiff } from "@shikijs/transformers";
3434
import posthog from "posthog-js";
35+
import type { SpecialLanguage } from "shiki";
3536
import type { Plugin } from "svelte-exmarkdown";
3637
import type {
3738
DiscussionDetails,
@@ -101,15 +102,14 @@
101102
};
102103
103104
// Utils
104-
function detectLanguage(code: string): string | undefined {
105+
function detectLanguage(code: string): (SpecialLanguage | (string & {})) | undefined {
105106
const hasHTML = /<\/[a-zA-Z0-9-]+>/.test(code);
106107
const hasJS = / (let|var|const|=) /.test(code);
107108
108109
if (hasHTML && hasJS) return "svelte";
109110
if (hasHTML) return "html";
110111
if (hasJS) return /(: [A-Z]|type |interface )/.test(code) ? "ts" : "js";
111112
if (/[a-z-]+: \S+/.test(code)) return "css";
112-
return undefined;
113113
}
114114
115115
function formatToDateTime(date: string) {

0 commit comments

Comments
 (0)