19

There is an issue where code blocks contain single backticks around every single line, rather than triple fences around the entire code block. This destroys the formatting. An example can be seen in this post. I believe this to be a bug in or misguided use of the Ask-Question wizard, since adding single backticks manually to a hundred lines of code isn't something one would normally do.

From the example:

`from modules.prompt import create_conversation_prompt`
`from langchain.chains import ConversationChain`
`from langchain_core.output_parsers import StrOutputParser`
`from langchain_core.runnables import RunnablePassthrough`

renders as:

from modules.prompt import create_conversation_prompt from langchain.chains import ConversationChain from langchain_core.output_parsers import StrOutputParser from langchain_core.runnables import RunnablePassthrough

Whereas

```lang-python
from modules.prompt import create_conversation_prompt
from langchain.chains import ConversationChain
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough
```

renders correctly:

from modules.prompt import create_conversation_prompt
from langchain.chains import ConversationChain
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough

How does this phenomenon arise and can it be prevented, e.g. by changing the question wizard?

Two semi-related posts:

2
  • 3
    The first comment on your second related post seems to address this: "The new editor (the wizard uses it) has an inline code button and a code block button both of which look very similar. Using it in the markdown mode might trick users not familiar with markdown." Commented Jul 15 at 9:48
  • 2
    "since adding single backticks manually to a hundred lines of code isn't something one would normally do." Before this thread, I was perfectly willing to assume that a subset of new users actually would do exactly that, due to not understanding the explanation of inline vs block code formatting. Commented Jul 15 at 15:52

2 Answers 2

17

Reproduction steps (for a variation), tested on Chrome 126 on macOS:

  1. Copy some code to the clipboard (I used the code in this question).
  2. Ensure that the editor is in WYSIWYG mode.
  3. Right click in the editor and select "Paste and Match Style".
    • Observe that this results in one paragraph per line of code.
  4. Select all the pasted code and click the "Inline code" button in the editor.

Note: this isn't exactly the same result as the linked question, but it's one I've seen many times.

Demonstration: Animation of the above

This animation is hosted on Imgur because I can't upload it to Stack Overflow.

2
  • 1
    This corresponds to what MisterMiyagi says in their comment. In my opinion should the wizard check/notice that multiple lines are selected and either give a warning or render it as a code block directly. Additionally, a way for reviewers to easily revert this would be great (and probably difficult, sadly), because removing those hundreds of ticks by hand is asking a tad much.
    – Adriaan
    Commented Jul 15 at 10:15
  • 3
    @Adriaan Ironically, removing the backticks is pretty easy (just select the offending text and remove the inline code formatting)...in the Stacks Editor, which you don't have when editing a question that's already been posted. Removing the paragraph breaks is another matter; I haven't found an easy way to do that.
    – Ryan M Mod
    Commented Jul 15 at 10:33
13

Reproduction steps (for code in inline blocks run together on one line), tested on Chrome 126 on macOS:

  1. Copy some code to the clipboard (I used the code in this question).
  2. Ensure that the editor is in Markdown mode.
  3. Paste the code into the editor.
  4. Switch to WYSIWYG mode.
    • Observe that all the code appears on one line.
  5. Select all the pasted code and click the "Inline code" button in the editor.
    • Though the rendering at this step is erroneous, this is all that's necessary. Posting at this point results in code blocks strung together as seen in the question.

At this point, switching to Markdown mode shows what happened: each line of code is surrounded by backticks.

Demonstration: Animation of the above

This animation is hosted on Imgur because I can't upload it to Stack Overflow.


These reproduction steps essentially require that the user sees a very visibly wrong result and decides to proceed. It's possible there is another way to end up with this result that is less visibly wrong.

3
  • 2
    I don't think that "the user sees a very visibly wrong result and decided to proceed" necessarily counts against the likelihood of users doing this. Perhaps they proceed because they "see a very visibly wrong result", and expect that proceeding (with the code button) will fix it. Commented Jul 15 at 15:51
  • "These reproduction steps essentially require that the user sees a very visibly wrong result and decides to proceed" - ... not exactly an uncommon occurrence. How often does it happen that posts have code in text and text in code.
    – Gimby
    Commented Jul 16 at 8:14
  • @Gimby at least with those, they don't necessarily have to see it if they never look at the preview and just scroll past it. But upon further reflection in this case, once they switch back to Markdown mode, everything looks "fine" again. And evidence does strongly suggest that some people really don't care if the post is completely unreadable, or at least make no attempt to solve the problem - in all cases of bad formatting, they're shown the question once it's posted, and completely unreadable ones go unfixed pretty often. So...yeah, that's probably not a significant barrier to posting it.
    – Ryan M Mod
    Commented Jul 16 at 8:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .