You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
Currently, when the chatbot provides a response that includes code examples enclosed within triple backticks ( ), the code appears as normal text instead of being rendered within a code block. This makes it difficult to distinguish code from regular text and hampers readability.
Steps to Reproduce:
Initiate a conversation with the chatbot.
Ask a question that prompts the chatbot to provide a code example in its response.
Observe that the code example is not formatted as a code block and appears as plain text.
Expected Behavior:
When the chatbot's response contains code examples enclosed within triple backticks ( ), the code should be rendered within a code block, preserving its formatting and improving readability.
Alternative solution:
Find or build code block UI library(in here it is react-code-block
constconvertNewLines=(text: string)=>{constlines=text.split('\n');constresult=[];letcodeBlock=false;letcodeLines=[];for(letlineoflines){if(line.trim().startsWith('```')){if(codeBlock){// Close the code blockresult.push(<divkey={result.length}className="codebox"><CodeBlocktext={codeLines.join('\n')}language={'ts'}showLineNumbers={false}wrapLines/></div>);codeLines=[];codeBlock=false;}else{// Start a new code blockcodeBlock=true;}}elseif(codeBlock){// Inside a code block, just collect the linescodeLines.push(line);}else{// Regular text linesresult.push(<spankey={result.length}>{line}<br/></span>);}}// Check if there's an unclosed code blockif(codeBlock&&codeLines.length>0){result.push(<divkey={result.length}className="codebox"><CodeBlocktext={codeLines.join('\n')}language={'ts'}showLineNumbers={false}wrapLines/></div>);}returnresult;};
The text was updated successfully, but these errors were encountered:
berkingurcan
changed the title
AI ChatGPT Template Code Examples Not Rendered in Code Blocks in Chatbot Responses
AI ChatGPT Template Code Snippets Not Rendered in Code Blocks in Chatbot Responses
Aug 11, 2023
Description:
Currently, when the chatbot provides a response that includes code examples enclosed within triple backticks ( ), the code appears as normal text instead of being rendered within a code block. This makes it difficult to distinguish code from regular text and hampers readability.
Steps to Reproduce:
Expected Behavior:
When the chatbot's response contains code examples enclosed within triple backticks ( ), the code should be rendered within a code block, preserving its formatting and improving readability.
Alternative solution:
The text was updated successfully, but these errors were encountered: