50

Let's say I want to quote this shell code in a post:

foo=bar
echo $foo

First I put it in code fences so it shows up as code:

```sh
foo=bar
echo $foo
```

Then to quote it, I select it and either press the Blockquote button or Ctrl+Q, but the newlines get converted to spaces, destroying it:

> ```sh foo=bar echo $foo ```

I would expect it to output this:

> ```sh
> foo=bar
> echo $foo
> ```

Which renders as:

foo=bar
echo $foo

This issue does not affect text indented by four spaces.

Workaround

Use <blockquote>, though the start tag requires an extra newline, like this:

<blockquote>

```sh
foo=bar
echo $foo
```
</blockquote>

Which renders as:

foo=bar
echo $foo

As an added bonus, this usually results in a smaller diff when editing, since the quote button rewraps text, but this doesn't of course.

Also affects

Quoting text in HTML tags

For example, <pre>:

<pre>
foo
bar
</pre>

becomes:

> <pre> foo bar </pre>

Putting code fences into a list (bulleted or numbered)

List this

```
foo
bar
```

becomes:

 - List this
   
   ``` foo bar ```

or

 3. List this
    
    ``` foo bar ```

Context

I noticed this while adding content to this answer and experienced the same problem while quoting the code in this question.

5
  • 9
    You can use indentation instead of code fences as a workaround. I mean Ctrl+K and then Ctrl+Q.
    – L. F.
    Jul 1, 2019 at 2:23
  • 12
    But please dont ise a code fence on an already indented post.
    – Luuklag
    Jul 1, 2019 at 5:31
  • 2
    Can I quote you on your code snippet demonstrating a quoted code snippet?
    – Dave
    Jul 2, 2019 at 17:39
  • @Dave Sure but you'll have to put it in a quoted code snippet :P
    – wjandrea
    Jul 2, 2019 at 17:42
  • 4
    This is still broken.
    – mkrieger1
    Jan 5, 2021 at 18:18

0

You must log in to answer this question.

Browse other questions tagged .