From 874a1a559c64c113ae2dd3db5ce40575fb34a1fd Mon Sep 17 00:00:00 2001 From: lezi-fun <177434121+lezi-fun@users.noreply.github.com> Date: Thu, 25 Jun 2026 08:46:30 +0800 Subject: [PATCH 1/2] fix(markdown): only highlight code blocks with explicit language class hljs.highlightAll() applies auto-detection to all
blocks,
including those without a language-* class from markdown code fences
with no language specified.
Replace with selective highlightElement(): only target code blocks
that have an explicit language-* class, skip language-plain.
Closes OpenListTeam/OpenList#2342
---
src/components/Markdown.tsx | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/components/Markdown.tsx b/src/components/Markdown.tsx
index e1c66c47f..53362b5a8 100644
--- a/src/components/Markdown.tsx
+++ b/src/components/Markdown.tsx
@@ -273,7 +273,18 @@ export function Markdown(props: {
setTimeout(() => {
setShow(true)
- hljs.highlightAll()
+ // Only highlight code blocks with an explicit language (not plain/auto-detect)
+ markdownRef()
+ ?.querySelectorAll('pre code[class*="language-"]')
+ ?.forEach((el) => {
+ const classList = (el as HTMLElement).classList
+ const langClass = Array.from(classList).find((c) =>
+ c.startsWith("language-"),
+ )
+ if (langClass && langClass !== "language-plain") {
+ hljs.highlightElement(el as HTMLElement)
+ }
+ })
if (hasMermaid && window.mermaid) {
window.mermaid.initialize({
startOnLoad: false,
From 99844dc9b666a6c3984bde56d2792f90f0e87bd8 Mon Sep 17 00:00:00 2001
From: lezi-fun <177434121+lezi-fun@users.noreply.github.com>
Date: Thu, 25 Jun 2026 09:12:17 +0800
Subject: [PATCH 2/2] fix(markdown): skip plaintext/text and check
hljs.getLanguage()
- Add language-plaintext and language-text to the skip set
- Use hljs.getLanguage() to verify the language is supported by Highlight.js
before calling highlightElement(), preventing unnecessary handling of
unknown language classes
---
src/components/Markdown.tsx | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/components/Markdown.tsx b/src/components/Markdown.tsx
index 53362b5a8..a1809eb66 100644
--- a/src/components/Markdown.tsx
+++ b/src/components/Markdown.tsx
@@ -273,7 +273,12 @@ export function Markdown(props: {
setTimeout(() => {
setShow(true)
- // Only highlight code blocks with an explicit language (not plain/auto-detect)
+ // Only highlight code blocks with an explicit, supported language
+ const noHighlight = new Set([
+ "language-plain",
+ "language-plaintext",
+ "language-text",
+ ])
markdownRef()
?.querySelectorAll('pre code[class*="language-"]')
?.forEach((el) => {
@@ -281,7 +286,11 @@ export function Markdown(props: {
const langClass = Array.from(classList).find((c) =>
c.startsWith("language-"),
)
- if (langClass && langClass !== "language-plain") {
+ if (
+ langClass &&
+ !noHighlight.has(langClass) &&
+ hljs.getLanguage(langClass.replace("language-", ""))
+ ) {
hljs.highlightElement(el as HTMLElement)
}
})