# Bug with \[code\]anything\[/code\] on a single line by itself

**URL:** https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634
**Category:** Bug
**Created:** [January 22, 2018, 9:18am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634 "2018-01-22T09:18:49Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![Bertrand\_Bellenot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bertrand_bellenot/32/91890_2.png) [@Bertrand\_Bellenot](https://meta.discourse.org/u/Bertrand_Bellenot)
#### Post date: [January 22, 2018, 9:18am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/1 "2018-01-22T09:18:49Z")

</div>

Hi,

Our forum has a lot of `[code][/code]` in its topics, imported from our old phpbb3 forum. One of our user reported a couple of bugs with `[code][/code]`. For example, this:

```plaintext
A single line of code without newline looks as a grey thick line:
[code]TString option = GetOption();[/code]

```

Gives:  
A single line of code without newline looks as a grey thick line:

```plaintext
TString option = GetOption();
```

And in this other example, the `-- -----------------------------------------------------------` line gives another issue:

[code]hatiden@ubuntu:~$ gedit ~/.bashrc  
hatiden@ubuntu:~$ cd /home/hatiden/garfield/

* * *

hatiden@ubuntu:~/garfield$ ls  
[/code]

Cheers, Bertrand.

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [January 22, 2018, 9:23am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/2 "2018-01-22T09:23:51Z")

</div>

Discourse supports the BBcode but You need a line break after [code] block for it to work.  
eg:

> [code]  
> hatiden@ubuntu:~$ gedit ~/.bashrc

```plaintext
hatiden@ubuntu:~$ gedit ~/.bashrc
hatiden@ubuntu:~$ cd /home/hatiden/garfield/

hatiden@ubuntu:~/garfield$ ls
```

---

<div class="post-metadata">

### Author: ![Bertrand\_Bellenot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bertrand_bellenot/32/91890_2.png) [@Bertrand\_Bellenot](https://meta.discourse.org/u/Bertrand_Bellenot)
#### Post date: [January 22, 2018, 9:27am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/3 "2018-01-22T09:27:17Z")

</div>

Well, not really, for example a line with embedded `TString option = GetOption();` works just fine…

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 22, 2018, 9:36am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/4 "2018-01-22T09:36:08Z")

</div>

see:

> [@Discourse CommonMark migration plans confetti\_ball balloon](https://meta.discourse.org/t/discourse-commonmark-migration-plans-confetti-ball-balloon/64234/6):
>
> I may pull this out to another topic, but I feel that I need to hammer_and_wrench hamster some stuff. Inline multiline quote[quote]that spans lines and blocks [/quote]Is a terrible format should not be supported Instead joy_catman_in_tuxedo:t4 Inline multiline quote [quote] that spans lines and blocks [/quote] Is a terrible format should not be supported At least the new format can not be as unreadable.

---

<div class="post-metadata">

### Author: ![Bertrand\_Bellenot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bertrand_bellenot/32/91890_2.png) [@Bertrand\_Bellenot](https://meta.discourse.org/u/Bertrand_Bellenot)
#### Post date: [January 22, 2018, 9:40am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/5 "2018-01-22T09:40:13Z")

</div>

Thanks!  
Does that mean that our (old) imported code will stay unreadable with

```plaintext
single line examples code not having newline
```

?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 22, 2018, 9:49am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/6 "2018-01-22T09:49:47Z")

</div>

It means you are going to need to apply some sort of processor on the old imported code if you want multiline bbcode to be converted from:

```plaintext
some text [code]

test
[/code] test

```

to:

```plaintext
some text 

[code]

test
[/code] 

test

```

It is quite a fiddly transform and I did not want it included in core.

If I were to attack this on an old imported corpus I would apply a transform to the `posts` `raw` column that inserts the missing newlines and then run a full rebake.

---

<div class="post-metadata">

### Author: ![Bertrand\_Bellenot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bertrand_bellenot/32/91890_2.png) [@Bertrand\_Bellenot](https://meta.discourse.org/u/Bertrand_Bellenot)
#### Post date: [January 22, 2018, 9:55am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/7 "2018-01-22T09:55:39Z")

</div>

Thanks for the info, even if this is not exactly the issue we have… (multiline works quite well)

> [@sam](#):
>
> If I were to attack this on an old imported corpus I would apply a transform to the posts raw column that inserts the missing newlines and then run a full rebake.

I have no idea what you’re talking about, but thanks anyway for the tips

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 22, 2018, 9:58am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/8 "2018-01-22T09:58:50Z")

</div>

> [@Bertrand\_Bellenot](#):
>
> (multiline works quite well)

Multiline works well as long it is not mixed!

This works:

```plaintext
[code]
test

test
[/code]

```

This does not:

```plaintext
a [code]
test

test
[/code]

```

This does not:

```plaintext
[code]
test

test
[/code]a

```

This does not:

```plaintext
[code]a
test

test
a[/code]
```

---

<div class="post-metadata">

### Author: ![Bertrand\_Bellenot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bertrand_bellenot/32/91890_2.png) [@Bertrand\_Bellenot](https://meta.discourse.org/u/Bertrand_Bellenot)
#### Post date: [January 22, 2018, 10:01am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/9 "2018-01-22T10:01:20Z")

</div>

Oh, OK, I see. Well, I think our main issue now is the single line one (as in my first post)  
I wasn’t even aware of the one you describe, so I suppose there should not be many…

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 22, 2018, 10:02am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/10 "2018-01-22T10:02:25Z")

</div>

> [@Bertrand\_Bellenot](#):
>
> so I suppose there should not be many…

If there are not many, I would recommend installing the [Discourse Data Explorer](https://meta.discourse.org/t/data-explorer-plugin/32566). Then you can find them and fix by hand. You just need to figure out the magic regex.

---

<div class="post-metadata">

### Author: ![Bertrand\_Bellenot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bertrand_bellenot/32/91890_2.png) [@Bertrand\_Bellenot](https://meta.discourse.org/u/Bertrand_Bellenot)
#### Post date: [January 22, 2018, 10:06am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/11 "2018-01-22T10:06:03Z")

</div>

I will try (maybe), thanks. But the single line ones are many… would that tool be a solution?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 22, 2018, 10:07am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/12 "2018-01-22T10:07:50Z")

</div>

Single line should `work fine`!

```plaintext
Single line should [code]work fine[/code]!

```

It only gets complicated when you start mixing.

---

<div class="post-metadata">

### Author: ![Bertrand\_Bellenot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bertrand_bellenot/32/91890_2.png) [@Bertrand\_Bellenot](https://meta.discourse.org/u/Bertrand_Bellenot)
#### Post date: [January 22, 2018, 10:09am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/13 "2018-01-22T10:09:11Z")

</div>

Is this example considered as

```plaintext
mixing?
```

```plaintext
Is this example considered as 
[code]mixing?[/code]

```

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 22, 2018, 10:10am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/14 "2018-01-22T10:10:30Z")

</div>

I would say this snippet not being handled correctly is a **bug**

```plaintext
Is this example considered as 
[code]mixing?[/code]

```

It happens due to complications with optional newline handling in CommonMark

---

<div class="post-metadata">

### Author: ![Bertrand\_Bellenot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bertrand_bellenot/32/91890_2.png) [@Bertrand\_Bellenot](https://meta.discourse.org/u/Bertrand_Bellenot)
#### Post date: [January 22, 2018, 10:11am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/15 "2018-01-22T10:11:11Z")

</div>

OK, so this was my original question, thanks! 🙂

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 22, 2018, 10:13am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/16 "2018-01-22T10:13:32Z")

</div>

Sure, be sure to edit the OP to talk about the specific example. I can have a look at it.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 26, 2018, 5:18am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/21 "2018-04-26T05:18:53Z")

</div>

This is fixed now per:

[https://github.com/discourse/discourse/commit/a0cd54750cca2866dfa978858c21c1a88a09899b](https://github.com/discourse/discourse/commit/a0cd54750cca2866dfa978858c21c1a88a09899b)

---

<div class="post-metadata">

### Author: ![Bertrand\_Bellenot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bertrand_bellenot/32/91890_2.png) [@Bertrand\_Bellenot](https://meta.discourse.org/u/Bertrand_Bellenot)
#### Post date: [April 26, 2018, 9:06am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/22 "2018-04-26T09:06:30Z")

</div>

Cool! Thank you very much!

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [April 26, 2018, 9:28am UTC](https://meta.discourse.org/t/bug-with-code-anything-code-on-a-single-line-by-itself/78634/23 "2018-04-26T09:28:54Z")

</div>


