diff --git a/src/components/modules/toc/TocTree.tsx b/src/components/modules/toc/TocTree.tsx index 63ecce01bd..eb5ccce88d 100644 --- a/src/components/modules/toc/TocTree.tsx +++ b/src/components/modules/toc/TocTree.tsx @@ -76,7 +76,12 @@ export const TocTree: Component< const toc: ITocItem[] = useMemo(() => { return Array.from($headings).map((el, idx) => { const depth = +el.tagName.slice(1) - const title = el.textContent || '' + const elClone = el.cloneNode(true) as HTMLElement + elClone.querySelectorAll('del').forEach((del) => { + del.remove() + }) + + const title = elClone.textContent || '' const index = idx diff --git a/src/components/ui/code-highlighter/CodeHighlighter.tsx b/src/components/ui/code-highlighter/CodeHighlighter.tsx index 5048bd04bd..5a74f45d88 100644 --- a/src/components/ui/code-highlighter/CodeHighlighter.tsx +++ b/src/components/ui/code-highlighter/CodeHighlighter.tsx @@ -8,6 +8,7 @@ import type { FC } from 'react' import { useIsPrintMode } from '~/atoms/css-media' import { useIsDark } from '~/hooks/common/use-is-dark' +import { stopPropagation } from '~/lib/dom' import { clsxm } from '~/lib/helper' import { loadScript, loadStyleSheet } from '~/lib/load-script' import { toast } from '~/lib/toast' @@ -36,7 +37,7 @@ export const HighLighterPrismCdn: FC = (props) => { const ref = useRef(null) useLoadHighlighter(ref) return ( -
+
{language?.toUpperCase()} @@ -70,6 +71,7 @@ export const BaseCodeHighlighter: Component< }, [content, lang]) return (
 span:last-child {
+        @apply mr-5;
+      }
     }
 
     .highlighted,
     .diff {
       @apply relative break-all;
-      white-space: pre-wrap;
-      word-wrap: break-word;
-      overflow: auto;
 
       &::before {
         @apply absolute left-0 top-0 h-full w-[2px];
@@ -67,10 +63,6 @@
     .highlighted {
       @apply bg-accent/20;
 
-      white-space: pre-wrap;
-      word-wrap: break-word;
-      overflow: auto;
-
       &::before {
         @apply bg-accent;
       }
@@ -78,8 +70,8 @@
   }
 
   .scroll-container pre::-webkit-scrollbar-track {
-    margin-left: 3rem;
-    margin-right: 8rem;
+    margin-left: 1rem;
+    margin-right: var(--sr-margin, 0);
   }
 
   .scroll-container pre::-webkit-scrollbar {
diff --git a/src/components/ui/code-highlighter/shiki/Shiki.tsx b/src/components/ui/code-highlighter/shiki/Shiki.tsx
index 7d16751a6b..c7b5aa073e 100644
--- a/src/components/ui/code-highlighter/shiki/Shiki.tsx
+++ b/src/components/ui/code-highlighter/shiki/Shiki.tsx
@@ -14,6 +14,7 @@ import type { HighlighterCore } from 'shiki'
 import { getViewport } from '~/atoms/hooks'
 import { AutoResizeHeight } from '~/components/modules/shared/AutoResizeHeight'
 import { useMaskScrollArea } from '~/hooks/shared/use-mask-scrollarea'
+import { stopPropagation } from '~/lib/dom'
 import { clsxm } from '~/lib/helper'
 
 import { MotionButtonBase } from '../../button'
@@ -97,15 +98,38 @@ export const ShikiHighLighter: FC = (props) => {
     }
   }, [value, codeBlockRef])
 
-  const renderedHtml = useMemo(() => {
+  const highlightedHtml = useMemo(() => {
     if (!highlighter) return ''
     return codeHighlighter(highlighter, {
       attrs: attrs || '',
+      // code: `${value.split('\n')[0].repeat(10)} // [!code highlight]\n${value}`,
       code: value,
       lang: language ? language.toLowerCase() : '',
     })
   }, [attrs, language, value, highlighter])
 
+  const [renderedHtml, setRenderedHtml] = useState(highlightedHtml)
+  useEffect(() => {
+    setRenderedHtml(highlightedHtml)
+    requestAnimationFrame(() => {
+      if (!highlightedHtml) return
+      if (!codeBlockRef) return
+
+      const $lines = codeBlockRef.querySelectorAll('.line')
+      const maxLineWidth = Math.max(
+        ...Array.from($lines).map((el) => {
+          return (el as HTMLElement).scrollWidth
+        }),
+      )
+      $lines.forEach((el) => {
+        ;(el as HTMLElement).style.width = `${maxLineWidth}px`
+      })
+
+      const pre = codeBlockRef.querySelector('pre')
+      if (pre) setRenderedHtml(pre.outerHTML)
+    })
+  }, [codeBlockRef, highlightedHtml])
+
   const filename = useMemo(() => {
     return parseFilenameFromAttrs(attrs || '')
   }, [attrs])
@@ -114,10 +138,15 @@ export const ShikiHighLighter: FC = (props) => {
     size: 'lg',
   })
 
+  const hasHeader = !!filename
+
   return (
-    
+
{!!filename && ( -
+
{filename} = (props) => { {language.toUpperCase()}
)} -
+
= (props) => { !isCollapsed ? '!max-h-[100%]' : isOverflow ? maskClassName : '', styles['scroll-container'], )} + style={ + { + '--sr-margin': !hasHeader + ? `${(language?.length || 0) + 1}em` + : '1rem', + } as any + } dangerouslySetInnerHTML={ renderedHtml ? { @@ -165,8 +201,8 @@ export const ShikiHighLighter: FC = (props) => { } > {renderedHtml ? undefined : ( -
-                {value}
+              
+                {value}
               
)}
diff --git a/src/components/ui/link/MLink.tsx b/src/components/ui/link/MLink.tsx index 94841f3669..d3d1ecf3cc 100644 --- a/src/components/ui/link/MLink.tsx +++ b/src/components/ui/link/MLink.tsx @@ -50,7 +50,7 @@ export const MLink: FC<{ type="tooltip" TriggerComponent={useCallback( () => ( - +