Skip to content

Commit 82630b3

Browse files
committed
adjust marked
1 parent b5bee96 commit 82630b3

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

src/components/KymaCompanion/components/Chat/messages/CodePanel.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Text, Panel, Title, Icon, FlexBox } from '@ui5/webcomponents-react';
2-
import { formatCodeSegment } from 'components/KymaCompanion/utils/formatMarkdown';
32
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
43
import { useRecoilValue } from 'recoil';
54
import {
@@ -50,6 +49,16 @@ function getCustomTheme(theme: Theme) {
5049
};
5150
}
5251

52+
function formatCodeSegment(
53+
text: string,
54+
): { language: string | undefined; code: string } {
55+
const lines = text.split('\n');
56+
const language = lines.shift();
57+
const nonEmptyLines = lines.filter(line => line.trim() !== '');
58+
const code = nonEmptyLines.join('\n');
59+
return { language, code };
60+
}
61+
5362
interface CodePanelProps {
5463
text: string;
5564
}

src/components/KymaCompanion/components/Chat/messages/Message.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export default function Message({
4545
segmentedText = formatMessage(text);
4646
}
4747

48-
console.log(messageChunks.slice(-1)[0]?.data?.answer?.content);
4948
return (
5049
<div className={'message ' + className}>
5150
<Text className="text">{segmentedText}</Text>

src/components/KymaCompanion/components/Chat/messages/markedExtension.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,41 @@ export const UI5Renderer = {
77
return <CodePanel text={tokens} />;
88
},
99

10+
blockquote(tokens: string) {
11+
return (
12+
<blockquote
13+
style={{
14+
fontStyle: 'italic',
15+
borderLeft: '1px dashed black',
16+
margin: '1em 0',
17+
paddingLeft: '1em',
18+
}}
19+
>
20+
{tokens}
21+
</blockquote>
22+
);
23+
},
24+
25+
text(tokens: string) {
26+
return <Text className="text">{tokens}</Text>;
27+
},
28+
29+
list(items: any[]) {
30+
return (
31+
<>
32+
<ul
33+
className="sap-margin-begin-tiny sap-padding-x-tiny"
34+
style={{
35+
lineHeight: 1.5,
36+
listStyleType: 'disc',
37+
}}
38+
>
39+
{items}
40+
</ul>
41+
</>
42+
);
43+
},
44+
1045
codespan(tokens: string) {
1146
return <Text className="text highlighted">{tokens}</Text>;
1247
},
@@ -23,6 +58,7 @@ export const UI5Renderer = {
2358
</Title>
2459
);
2560
},
61+
2662
link(href: string, title: string) {
2763
return (
2864
<Link href={href} target="_blank">

src/components/KymaCompanion/utils/formatMarkdown.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
import Markdown from 'marked-react';
21
import { UI5Renderer } from 'components/KymaCompanion/components/Chat/messages/markedExtension';
32

4-
export function formatCodeSegment(
5-
text: string,
6-
): { language: string | undefined; code: string } {
7-
const lines = text.split('\n');
8-
const language = lines.shift();
9-
const nonEmptyLines = lines.filter(line => line.trim() !== '');
10-
const code = nonEmptyLines.join('\n');
11-
return { language, code };
12-
}
3+
import Markdown from 'marked-react';
134

145
export function formatMessage(text: string): JSX.Element[] {
156
const elements: JSX.Element[] = [];

0 commit comments

Comments
 (0)