Skip to content

Commit d127b0b

Browse files
committed
Update version templates docs
1 parent 07e4969 commit d127b0b

5 files changed

Lines changed: 1963 additions & 2691 deletions

File tree

.vitepress/theme/CodeBlock.vue

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,7 @@
8282

8383
<script setup>
8484
import { computed, ref, watch } from "vue";
85-
import {
86-
highlightCpp,
87-
highlightShell,
88-
highlightText,
89-
normalizeLang,
90-
} from "./highlighter";
85+
import { highlight, normalizeLang } from "./highlighter";
9186
9287
const props = defineProps({
9388
title: { type: String, default: "" },
@@ -155,21 +150,32 @@ function guessLang(tabKey) {
155150
if (props.lang) return props.lang;
156151
if (tabKey === "run" || tabKey === "out") return "shell";
157152
const s = (props.code || "").trim();
153+
// C++
158154
if (s.includes("#include") || s.includes("int main") || s.includes("std::"))
159155
return "cpp";
156+
// Shell
160157
if (s.startsWith("~$") || s.includes(" vix ") || s.startsWith("$ "))
161158
return "shell";
159+
// HTML / Vue
160+
if (
161+
/^\s*<(template|div|span|section|html|!DOCTYPE|script|style)\b/i.test(s) ||
162+
/<\/[a-z]+>/.test(s)
163+
)
164+
return "html";
165+
// CSS
166+
if (/[.#&][\w-]+\s*\{/.test(s) || /^\s*@(media|import|keyframes)/m.test(s))
167+
return "css";
168+
// JSON
169+
if (/^\s*[{\[]/.test(s) && /["}\]]\s*$/.test(s) && /":/.test(s))
170+
return "json";
171+
// JS / TS
172+
if (/\b(const|let|function|import|export|=>)\b/.test(s)) return "js";
162173
return "cpp";
163174
}
164175
165-
const activeHtml = computed(() => {
166-
const text = activeText.value || "";
167-
const lang = normalizeLang(activeLang.value);
168-
169-
if (lang === "shell") return highlightShell(text);
170-
if (lang === "cpp") return highlightCpp(text);
171-
return highlightText(text);
172-
});
176+
const activeHtml = computed(() =>
177+
highlight(activeText.value || "", normalizeLang(activeLang.value)),
178+
);
173179
174180
async function copy(text) {
175181
try {

0 commit comments

Comments
 (0)