11import { initCopyButton } from '../../../copybutton'
2+ import { hljs } from '../../../hljs'
23import { GeneratingStatus } from './GeneratingStatus'
34import { References } from './RelatedResources'
45import { ChatMessage as ChatMessageType } from './chat.store'
@@ -19,7 +20,6 @@ import {
1920} from '@elastic/eui'
2021import { css } from '@emotion/react'
2122import DOMPurify from 'dompurify'
22- import hljs from 'highlight.js/lib/core'
2323import { Marked , RendererObject , Tokens } from 'marked'
2424import * as React from 'react'
2525import { useEffect , useMemo } from 'react'
@@ -28,9 +28,15 @@ import { useEffect, useMemo } from 'react'
2828const createMarkedInstance = ( ) => {
2929 const renderer : RendererObject = {
3030 code ( { text, lang } : Tokens . Code ) : string {
31- const highlighted = lang
32- ? hljs . highlight ( text , { language : lang } ) . value
33- : hljs . highlightAuto ( text ) . value
31+ let highlighted : string
32+ try {
33+ highlighted = lang
34+ ? hljs . highlight ( text , { language : lang } ) . value
35+ : hljs . highlightAuto ( text ) . value
36+ } catch {
37+ // Fallback to auto highlighting if the specified language is not found
38+ highlighted = hljs . highlightAuto ( text ) . value
39+ }
3440 return `<div class="highlight">
3541 <pre>
3642 <code class="language-${ lang } ">${ highlighted } </code>
0 commit comments