# Quotes containing code block must start with newline

**URL:** https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369
**Category:** Bug
**Created:** [18.Февраль.2015 18:42:13 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369 "2015-02-18T18:42:13Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![anon25879736](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@anon25879736](https://meta.discourse.org/u/anon25879736)
#### Post date: [18.Февраль.2015 18:42:14 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/1 "2015-02-18T18:42:14Z")

</div>

When including a quote with a code block, it will not render correctly unless the quote starts with an extra newline character. For example, the following will display correctly:

```
[quote="abarker"]
Sample quote 1, without any code.
[/quote]

```

> [@abarker](#):
>
> Sample quote 1, without any code.

* * *

However, insert a code block into the quote, and things will become problemeatic.

````
[quote="abarker"]
Sample quote 2, with a small code block.
```
n = 2;
```
This will not work
[/quote]

````

> [@abarker](#):
>
> Sample quote 2, with a small code block.
> 
> ```plaintext
> n = 2;
> 
> ```
> 
> This will not work

* * *

Then again, if you add an extra line break to the beginning of the quote, it starts working again:

````
[quote="abarker"]

Sample quote 3, with a small code block.
```
n = 2;
```
This will work
[/quote]

````

> [@abarker](#):
>
> Sample quote 3, with a small code block.
> 
> ```plaintext
> n = 2;
> 
> ```
> 
> This will work

---

<div class="post-metadata">

### Author: ![TechnoBear](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/technobear/32/40546_2.png) [@TechnoBear](https://meta.discourse.org/u/TechnoBear)
#### Post date: [18.Февраль.2015 19:15:59 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/2 "2015-02-18T19:15:59Z")

</div>

If the quote _only_ consists of code, I’ve found adding an extra line has no effect to fix formatting. But inserting two backticks before the code block, and none after it, works.

A single backtick will fix the #, but shows up in the code.

> [@TechnoBear](#):
>
> #container-columns {  
> display: table;  
> width: 100%;  
> margin-bottom: 30px;  
> }  
> #select-text {  
> display: table-cell;  
> max-width: 800px;  
> padding: 15px 0;  
> border-top: 2px solid #999;  
> border-bottom: 1px solid #CCC;  
> vertical-align: top;  
> }

Becomes

> [@TechnoBear](#):
>
> ``  
> #container-columns {  
> display: table;  
> width: 100%;  
> margin-bottom: 30px;  
> }  
> #select-text {  
> display: table-cell;  
> max-width: 800px;  
> padding: 15px 0;  
> border-top: 2px solid #999;  
> border-bottom: 1px solid #CCC;  
> vertical-align: top;  
> }

---

<div class="post-metadata">

### Author: ![cipher1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cipher1/32/42613_2.png) [@cipher1](https://meta.discourse.org/u/cipher1)
#### Post date: [02.Июнь.2015 14:27:49 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/3 "2015-06-02T14:27:49Z")

</div>

Testing fail condition for current status:

> [@abarker](#):
>
> Sample quote 2, with a small code block.
> 
> ```plaintext
> n = 2;
> 
> ```
> 
> This will not work

Appears to still be an issue.

---

<div class="post-metadata">

### Author: ![anon25879736](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@anon25879736](https://meta.discourse.org/u/anon25879736)
#### Post date: [29.Июнь.2015 20:59:01 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/4 "2015-06-29T20:59:01Z")

</div>

Status check:

> [@abarker](#):
>
> Sample quote 2, with a small code block.
> 
> ```plaintext
> n = 2;
> 
> ```
> 
> This will not work

\<hidden comment to get around the absurdly long 20 character limit that meta.d imposes.

---

<div class="post-metadata">

### Author: ![gwwar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gwwar/32/116586_2.png) [@gwwar](https://meta.discourse.org/u/gwwar)
#### Post date: [31.Август.2015 18:21:45 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/5 "2015-08-31T18:21:45Z")

</div>

This one was a pain to debug. I’ve included a workaround, but this is a core markdown parser bug and it should be revisited.

PR is ready here:  
[https://github.com/discourse/discourse/pull/3715](https://github.com/discourse/discourse/pull/3715)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [22.Сентябрь.2015 02:14:28 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/6 "2015-09-22T02:14:28Z")

</div>



---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [04.Май.2020 18:57:09 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/7 "2020-05-04T18:57:09Z")

</div>



---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [04.Май.2020 18:59:35 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/8 "2020-05-04T18:59:35Z")

</div>

Похоже, это регрессия. Если цитата содержит блок кода и одну строку текста, не являющегося кодом, форматирование блока кода сохраняется. Если же цитируется только блок кода, форматирование не сохраняется.

Я привел пример этой проблемы здесь: [https://try.discourse.org/t/testing-issue-with-quoted-code-blocks/1401/2](https://try.discourse.org/t/testing-issue-with-quoted-code-blocks/1401/2).

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [04.Май.2020 19:21:08 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/9 "2020-05-04T19:21:08Z")

</div>

Конечно, можете назначить это @eviltrout?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [04.Май.2020 20:19:44 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/12 "2020-05-04T20:19:44Z")

</div>

Понадобилось немного времени, чтобы найти правильное место для исправления, но вот оно!

> <https://github.com/discourse/discourse/pull/9632>
>
> https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newlin…e/25369/8?u=riking
> 
> Using jQuery all over to match the surrounding code.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [05.Май.2020 21:25:35 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/13 "2020-05-05T21:25:35Z")

</div>



---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [12.Май.2020 19:15:13 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/14 "2020-05-12T19:15:13Z")

</div>



---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [12.Май.2020 19:15:31 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/15 "2020-05-12T19:15:31Z")

</div>

Здесь что-то не так: поведение на Meta не соответствует тому, что я наблюдал во время разработки.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [14.Май.2020 19:11:03 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/17 "2020-05-14T19:11:03Z")

</div>

Разобрался, jQuery меня обманул.

> <https://github.com/discourse/discourse/pull/9784>
>
> 'parent' -\> 'parents'

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [15.Май.2020 01:47:43 UTC](https://meta.discourse.org/t/quotes-containing-code-block-must-start-with-newline/25369/18 "2020-05-15T01:47:43Z")

</div>


