Skip to content

Commit 54ed1d9

Browse files
committed
1 parent 99a6ba8 commit 54ed1d9

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

frontend/src/components/Chat.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,29 @@ function Message(props: {
4646
</div>
4747
) : (
4848
isMarkdown(text) ?
49-
<ReactMarkdown
50-
children={text}
51-
remarkPlugins={[remarkGfm]}
52-
/> :
49+
<ReactMarkdown
50+
children={text}
51+
remarkPlugins={[remarkGfm]}
52+
components={{
53+
code({node, inline, className, children, style, ...props}) {
54+
const match = /language-(\w+)/.exec(className || '')
55+
return !inline ? (
56+
<SyntaxHighlighter
57+
{...props}
58+
children={String(children).replace(/\n$/, '')}
59+
wrapLongLines={true}
60+
language={match ? match[1] : "python"}
61+
PreTag="div"
62+
/>
63+
) : (
64+
<code {...props} className={className}>
65+
{children}
66+
</code>
67+
)
68+
}
69+
}}
70+
/>
71+
:
5372
<div className="cell-output" dangerouslySetInnerHTML={{ __html: text }}></div>
5473
))}
5574

gpt_code_ui/webapp/main.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,7 @@ def extract_code(text):
171171
if single_match:
172172
return single_match.group(1).strip()
173173

174-
def extract_non_code(text):
175-
# Replace triple backtick blocks
176-
text = re.sub(r'```(?:\w+\n)?(.+?)```', '', text, flags=re.DOTALL)
177-
# Replace single backtick blocks
178-
text = re.sub(r'`(.+?)`', '', text, flags=re.DOTALL)
179-
return text.strip()
180-
181-
return extract_code(content), extract_non_code(content), 200
174+
return extract_code(content), content.strip(), 200
182175

183176
# We know this Flask app is for local use. So we can disable the verbose Werkzeug logger
184177
log = logging.getLogger('werkzeug')

0 commit comments

Comments
 (0)