Skip to content

Commit ea97a5f

Browse files
fix(CodeBlock): Temporarily drop syntax highlighting (#605)
Syntax highlighter has a sub-dependency with a vulnerability. It has not yet been fixed. I would like to drop this for now and we can investigate a more PatternFly solution. This dependency was brought in by Rohit during early development.
1 parent a5544b0 commit ea97a5f

File tree

5 files changed

+21
-353
lines changed

5 files changed

+21
-353
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
collectCoverage: true,
88
// most of these are to fix https://github.com/remarkjs/react-markdown/issues/635
99
transformIgnorePatterns: [
10-
'node_modules/(?!@patternfly|@data-driven-forms|react-syntax-highlighter|remark-gfm|react-markdown|remark-parse|devlop|hast-util-to-jsx-runtime|comma-separated-tokens|estree-util-is-identifier-name|hast-util-whitespace|property-information|space-separated-tokens|unist-util-position|vfile-message|unist-util-stringify-position|html-url-attributes|mdast-util-from-markdown|mdast-util-to-string|micromark|decode-named-character-reference|remark-rehype|mdast-util-to-hast|trim-lines|unist-util-visit|unist-util-is|unified|bail|is-plain-obj|trough|vfile|mdast-util-gfm|ccount|mdast-util-find-and-replace|escape-string-regexp|markdown-table|mdast-util-to-markdown|zwitch|longest-streak|mdast-util-phrasing)'
10+
'node_modules/(?!@patternfly|@data-driven-forms|remark-gfm|react-markdown|remark-parse|devlop|hast-util-to-jsx-runtime|comma-separated-tokens|estree-util-is-identifier-name|hast-util-whitespace|property-information|space-separated-tokens|unist-util-position|vfile-message|unist-util-stringify-position|html-url-attributes|mdast-util-from-markdown|mdast-util-to-string|micromark|decode-named-character-reference|remark-rehype|mdast-util-to-hast|trim-lines|unist-util-visit|unist-util-is|unified|bail|is-plain-obj|trough|vfile|mdast-util-gfm|ccount|mdast-util-find-and-replace|escape-string-regexp|markdown-table|mdast-util-to-markdown|zwitch|longest-streak|mdast-util-phrasing)'
1111
// Uncomment the below line if you face any errors with jest
1212
// '/node_modules/(?!@redhat-cloud-services)',
1313
],

package-lock.json

Lines changed: 17 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/module/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"clsx": "^2.1.0",
4141
"framer-motion": "^11.3.28",
4242
"react-markdown": "^9.0.1",
43-
"react-syntax-highlighter": "^15.5.0",
4443
"remark-gfm": "^4.0.0",
4544
"rehype-unwrap-images": "^1.0.0",
4645
"rehype-external-links": "^3.0.0",

packages/module/src/Message/CodeBlockMessage/CodeBlockMessage.tsx

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Chatbot Main - Message - Content - Code Block
33
// ============================================================================
44
import { useState, useRef, useId, useCallback, useEffect } from 'react';
5-
import SyntaxHighlighter from 'react-syntax-highlighter';
6-
import { obsidian } from 'react-syntax-highlighter/dist/esm/styles/hljs';
75
// Import PatternFly components
86
import {
97
CodeBlock,
@@ -20,7 +18,6 @@ import {
2018

2119
import { CheckIcon } from '@patternfly/react-icons/dist/esm/icons/check-icon';
2220
import { CopyIcon } from '@patternfly/react-icons/dist/esm/icons/copy-icon';
23-
import { ExpandableSectionForSyntaxHighlighter } from './ExpandableSectionForSyntaxHighlighter';
2421

2522
export interface CodeBlockMessageProps {
2623
/** Content rendered in code block */
@@ -137,30 +134,7 @@ const CodeBlockMessage = ({
137134
<CodeBlock actions={actions}>
138135
<CodeBlockCode>
139136
<>
140-
{language ? (
141-
// SyntaxHighlighter doesn't work with ExpandableSection because it targets the direct child
142-
// Forked for now and adjusted to match what we need
143-
<ExpandableSectionForSyntaxHighlighter
144-
variant={ExpandableSectionVariant.truncate}
145-
isExpanded={isExpanded}
146-
isDetached
147-
toggleId={toggleId}
148-
contentId={contentId}
149-
language={language}
150-
{...expandableSectionProps}
151-
>
152-
<SyntaxHighlighter
153-
{...props}
154-
language={language}
155-
style={obsidian}
156-
PreTag="div"
157-
CodeTag="div"
158-
wrapLongLines
159-
>
160-
{String(children).replace(/\n$/, '')}
161-
</SyntaxHighlighter>
162-
</ExpandableSectionForSyntaxHighlighter>
163-
) : (
137+
{isExpandable ? (
164138
<ExpandableSection
165139
variant={ExpandableSectionVariant.truncate}
166140
isExpanded={isExpanded}
@@ -171,6 +145,8 @@ const CodeBlockMessage = ({
171145
>
172146
{children}
173147
</ExpandableSection>
148+
) : (
149+
children
174150
)}
175151
</>
176152
</CodeBlockCode>

0 commit comments

Comments
 (0)