# Chat Stream alternating code /code fields from 3 backticks (HTML Javascript css)

**URL:** <https://community.openai.com/t/chat-stream-alternating-code-code-fields-from-3-backticks-html-javascript-css/512741>\
**Category:** API\
**Tags:** api\
**Created:** [November 19, 2023, 8:07am UTC](https://community.openai.com/t/chat-stream-alternating-code-code-fields-from-3-backticks-html-javascript-css/512741 "2023-11-19T08:07:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![l.dijkman](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/l.dijkman/32/239942_2.png) [@l.dijkman](https://community.openai.com/u/l.dijkman)\
**Post date:** [November 19, 2023, 8:07am UTC](https://community.openai.com/t/chat-stream-alternating-code-code-fields-from-3-backticks-html-javascript-css/512741/1 "2023-11-19T08:07:25Z")

</div>

Hello

Anyone maybe knows a working example  
Chat Stream alternating code /code fields from 3 backticks

struggling with innerText and innerHTML  
i can replace tripple backticks alternating  
but have problems with linebreaks and br

for example if i  
ask: javascript for loop examples

the response is text and code between 3 backticks

i would like them to be in a code field  
so that it can be pasted at cursor position in ace editor / html previewer

if any one maybe knows an example in python  
also ok

greet luberth

---

<div class="post-metadata">

**Author:** ![\_j](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/_j/32/766292_2.png) [@\_j](https://community.openai.com/u/_j)\
**Post date:** [November 19, 2023, 10:06am UTC](https://community.openai.com/t/chat-stream-alternating-code-code-fields-from-3-backticks-html-javascript-css/512741/2 "2023-11-19T10:06:50Z")

</div>

## ChatGPT uses a standard markdown to HTML library.

### Why do I need to know the word markdown?

It is a standard text formatting that allows one to type an entire post into a forum with a keyboard, and have it displayed in the manner desired.

- This Discourse-based forum uses a markdown renderer;
- ChatGPT uses a markdown renderer

### Code blocks in markdown

Single and triple backticks are markdown to represent preformatted text and a code block, and text within such a container format is rendered as monospace text.

Like the forum, you will need to use a library that understands the rules of markdown, and what sequences will break out of the containers.

````auto
this for example is a code block.

Using a code block, I can 
display `backticks` without 
breaking the container.

Triple-backticks (```) only represent 
a code block on their own line.

````

````plaintext
If you don't like the code block being interpreted 
and rendered incorrectly, you can specify the 
programming language by starting the code block as:

``` text 

then you get un-colored text. Also that ``` didn't break
out of the code block, you notice.

````

Because of the strict standardized rules, a library rather than your intuition is required. This will help you render the text produced by the AI that has similar understanding.

# Conclusion

Big text comes from # and a space on a new line, rendered as an HTML \<H1\>Conclusion\</H1\>. It does not need to be closed. Typing \<h1\> however needs to be escaped as \\<h1\>, and showing someone that requires \\\\<h1\> be typed out, and so on.

Understand what ChatGPT is doing, and you’ll have success.

---

<div class="post-metadata">

**Author:** ![l.dijkman](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/l.dijkman/32/239942_2.png) [@l.dijkman](https://community.openai.com/u/l.dijkman)\
**Post date:** [November 19, 2023, 10:45am UTC](https://community.openai.com/t/chat-stream-alternating-code-code-fields-from-3-backticks-html-javascript-css/512741/3 "2023-11-19T10:45:21Z")

</div>

Ok thank you for your explanation  
github uses readme.md

now i understand the idea a bit better

thanks  
luberth

trying to figure out how the response json works  
by printing things to the console

---

<div class="post-metadata">

**Author:** ![l.dijkman](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/l.dijkman/32/239942_2.png) [@l.dijkman](https://community.openai.com/u/l.dijkman)\
**Post date:** [November 19, 2023, 11:36am UTC](https://community.openai.com/t/chat-stream-alternating-code-code-fields-from-3-backticks-html-javascript-css/512741/4 "2023-11-19T11:36:22Z")

</div>

ok maybe  
i will search  
for a small  
md to html javascript that will convert the string for me

thanks

---

<div class="post-metadata">

**Author:** ![l.dijkman](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/l.dijkman/32/239942_2.png) [@l.dijkman](https://community.openai.com/u/l.dijkman)\
**Post date:** [November 20, 2023, 6:38pm UTC](https://community.openai.com/t/chat-stream-alternating-code-code-fields-from-3-backticks-html-javascript-css/512741/5 "2023-11-20T18:38:27Z")

</div>

a mechanic that screw things, proud to say ( with your help eye 😉 )  
ok md to html  
after chat stream is recieved

ask javascript for loop examples

 ![Screenshot from 2023-11-20 19-32-27](https://us1.discourse-cdn.com/openai1/original/3X/6/3/63a90fd731a69a72a8ac0c1ea92afcb674267227.png)
