From 8991bf6fb3d57904232d2785b9911b374cb6236d Mon Sep 17 00:00:00 2001 From: clark-cui Date: Mon, 2 Jan 2023 16:52:35 +0800 Subject: [PATCH 1/3] fix: language label caused 404 --- src/node/markdown/plugins/highlight.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/node/markdown/plugins/highlight.ts b/src/node/markdown/plugins/highlight.ts index 186d9bc93447..b265deb40acd 100644 --- a/src/node/markdown/plugins/highlight.ts +++ b/src/node/markdown/plugins/highlight.ts @@ -80,13 +80,20 @@ export async function highlight( const vPre = vueRE.test(lang) ? '' : 'v-pre' lang = lang.replace(lineNoRE, '').replace(vueRE, '').toLowerCase() || defaultLang - + const langExists = highlighter.getLoadedLanguages().includes(lang as any) + if (!langExists) { + console.warn( + `The language "${lang}" doesn't exist, falling back to plaintext.` + ) + lang = defaultLang + } const lineOptions = attrsToLines(attrs) const cleanup = (str: string) => str .replace(preRE, (_, attributes) => `
`)
         .replace(styleRE, (_, style) => _.replace(style, ''))
 
+
     if (hasSingleTheme) {
       return cleanup(
         highlighter.codeToHtml(str, {

From 6c0d20f13f4489042c33ec0c8d19e2bd087d2e7b Mon Sep 17 00:00:00 2001
From: clark-cui 
Date: Mon, 2 Jan 2023 17:02:57 +0800
Subject: [PATCH 2/3] chore: format

---
 src/node/markdown/plugins/highlight.ts | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/node/markdown/plugins/highlight.ts b/src/node/markdown/plugins/highlight.ts
index b265deb40acd..383ec204cbc2 100644
--- a/src/node/markdown/plugins/highlight.ts
+++ b/src/node/markdown/plugins/highlight.ts
@@ -93,7 +93,6 @@ export async function highlight(
         .replace(preRE, (_, attributes) => `
`)
         .replace(styleRE, (_, style) => _.replace(style, ''))
 
-
     if (hasSingleTheme) {
       return cleanup(
         highlighter.codeToHtml(str, {

From 4f15c2020ecb4d13f008f86f5befd64d7515f55c Mon Sep 17 00:00:00 2001
From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
Date: Sat, 14 Jan 2023 19:49:46 +0530
Subject: [PATCH 3/3] feat(build): don't hard fail on unknown languages

---
 src/node/markdown/plugins/highlight.ts | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/node/markdown/plugins/highlight.ts b/src/node/markdown/plugins/highlight.ts
index 63c790d6f12f..72bb3f2224b3 100644
--- a/src/node/markdown/plugins/highlight.ts
+++ b/src/node/markdown/plugins/highlight.ts
@@ -1,3 +1,5 @@
+import { customAlphabet } from 'nanoid'
+import c from 'picocolors'
 import type { HtmlRendererOptions, IThemeRegistration } from 'shiki'
 import {
   addClass,
@@ -10,7 +12,6 @@ import {
   type Processor
 } from 'shiki-processor'
 import type { ThemeOptions } from '../markdown'
-import { customAlphabet } from 'nanoid'
 
 const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 10)
 
@@ -84,13 +85,19 @@ export async function highlight(
     const vPre = vueRE.test(lang) ? '' : 'v-pre'
     lang =
       lang.replace(lineNoRE, '').replace(vueRE, '').toLowerCase() || defaultLang
-    const langExists = highlighter.getLoadedLanguages().includes(lang as any)
-    if (!langExists) {
+
+    const langLoaded = highlighter.getLoadedLanguages().includes(lang as any)
+    if (!langLoaded) {
       console.warn(
-        `The language "${lang}" doesn't exist, falling back to plaintext.`
+        c.yellow(
+          `The language '${lang}' is not loaded, falling back to '${
+            defaultLang || 'txt'
+          }' for syntax highlighting.`
+        )
       )
       lang = defaultLang
     }
+
     const lineOptions = attrsToLines(attrs)
     const cleanup = (str: string) =>
       str