# Editor toolbar generates invalid multi-paragraph spoilers

**URL:** https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475
**Category:** Bug
**Created:** [July 19, 2017, 11:02pm UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475 "2017-07-19T23:02:31Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![dfabulich](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dfabulich/32/108716_2.png) [@dfabulich](https://meta.discourse.org/u/dfabulich)
#### Post date: [July 19, 2017, 11:02pm UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/1 "2017-07-19T23:02:31Z")

</div>

Continuing the discussion from [HTML \<b\> across paragraph breaks differs between preview and result](https://meta.discourse.org/t/html-b-across-paragraph-breaks-differs-between-preview-and-result/66458/8):

> [@codinghorror](#):
>
> Good point, we should fix the editor toolbar generating this broken output @eviltrout – but @sam says it is already fixed / working.

The editor bug is still there as far as I can see.

To reproduce: on [meta.discourse.org](http://meta.discourse.org) or [try.discourse.org](http://try.discourse.org), type two paragraphs with double line breaks separating them like this:

```markdown
foo

bar

```

Select the paragraphs, click the gear, and click “Blur Spoiler.”

Actual: The editor inserts spoiler tags inline at the start/end of the selection, which used to work, but which no longer makes a multi-paragraph spoiler.

```plaintext
[spoiler]foo

bar[/spoiler]

```

It renders like this:

[spoiler]foo

bar[/spoiler]

Expected:

```plaintext
[spoiler]
foo

bar
[/spoiler]

```

foo

bar

---

<div class="post-metadata">

### Author: ![dfabulich](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dfabulich/32/108716_2.png) [@dfabulich](https://meta.discourse.org/u/dfabulich)
#### Post date: [July 19, 2017, 11:16pm UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/2 "2017-07-19T23:16:27Z")

</div>

Note that it should also do the right thing if you select the spoilers in this example:

```markdown
foo Rosebud is a sled

Bruce Willis died in Act 1

It was Kevin Spacey the whole time

Darth is Anakin bar 

```

Currently it does this:

foo [spoiler]Rosebud is a sled

Bruce Willis died in Act 1

It was Kevin Spacey the whole time

Darth is Anakin[/spoiler] bar

I’m not 100% sure what it should do in this case. One thing it might do is convert the inline spoilers into a spoiler block like this.

```markdown
foo
[spoiler]
Rosebud is a sled

Bruce Willis died in Act 1

It was Kevin Spacey the whole time

Darth is Anakin
[/spoiler]
bar

```

foo

Rosebud is a sled

Bruce Willis died in Act 1

It was Kevin Spacey the whole time

Darth is Anakin

bar

But perhaps instead it should wrap each inline section with its own [spoiler] tag and embed all of the paragraphs in a spoiler block.

```markdown
foo [spoiler]Rosebud is a sled[/spoiler]

[spoiler]
Bruce Willis died in Act 1

It was Kevin Spacey the whole time
[/spoiler]

[spoiler]Darth is Anakin[/spoiler] bar 

```

foo Rosebud is a sled

Bruce Willis died in Act 1

It was Kevin Spacey the whole time

Darth is Anakin bar

But that introduces three spoilers; you have to click on each spoiler one at a time to reveal it. 😕

---

<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: [July 19, 2017, 11:53pm UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/3 "2017-07-19T23:53:04Z")

</div>

> [@dfabulich](#):
>
> But instead it should wrap each inline section with its own [spoiler] tag and embed all of the paragraphs in a spoiler block.

Incorrect, it should simply add spoiler BBCode tags at the top and bottom. And if it does not, we should definitely fix that @eviltrout

```
[spoiler]
foo Rosebud is a sled

Bruce Willis died in Act 1

It was Kevin Spacey the whole time

Darth is Anakin bar 
[/spoiler]

```

---

<div class="post-metadata">

### Author: ![dfabulich](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dfabulich/32/108716_2.png) [@dfabulich](https://meta.discourse.org/u/dfabulich)
#### Post date: [July 20, 2017, 12:21am UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/4 "2017-07-20T00:21:39Z")

</div>

I guess that’s OK, too. (A bit weird that non-spoiler text “foo” and “bar” sneaks in.)

I just want to make sure inline spoilers will still work.

So if you select the spoiler here:

```plaintext
foo Rosebud is a sled bar

```

it should continue to generate an inline spoiler

```plaintext
foo [spoiler]Rosebud is a sled[/spoiler] bar

```

foo Rosebud is a sled bar

---

<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: [July 20, 2017, 12:22am UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/5 "2017-07-20T00:22:30Z")

</div>

Yes, that is more or less how the code toolbar button already works – try it – so I think @eviltrout can just adopt that exact behavior.

---

<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: [July 25, 2017, 7:23pm UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/6 "2017-07-25T19:23:29Z")

</div>

@eviltrout I recall fixing this a few weeks back with the details plugin.

Current behavior:

```plaintext
test []test

test[] test

```

Hit spoiler

```plaintext
test [spoiler]test

test[/spoiler] test

```

Desired

```plaintext
test
[spoiler]
test

test
[/spoiler]
test

```

Since spoiler is also inline, this needs to work as well

```plaintext
text spoil text

```

```plaintext
text [spoiler]spoil[/spoiler] text

```

---

<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: [July 2, 2019, 7:32am UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/7 "2019-07-02T07:32:32Z")

</div>

Can you assign someone to this @eviltrout if it is still an issue?

---

<div class="post-metadata">

### Author: ![dfabulich](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dfabulich/32/108716_2.png) [@dfabulich](https://meta.discourse.org/u/dfabulich)
#### Post date: [July 2, 2019, 7:47am UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/8 "2019-07-02T07:47:37Z")

</div>

[spoiler]It is still

an issue[/spoiler]

---

<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: [July 2, 2019, 10:23am UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/9 "2019-07-02T10:23:12Z")

</div>

This is going to be hard to fix since we only support either [block or inline BBCode](https://meta.discourse.org/t/developers-guide-to-markdown-extensions/66023)

```plaintext
[spoiler]
block
[/spoiler]

```

```plaintext
[spoiler]inline[/spoiler]

```

---

<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: [July 2, 2019, 10:27am UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/10 "2019-07-02T10:27:28Z")

</div>

It does not seem hard, simply use the correct form for multiple line selections?

---

<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: [July 2, 2019, 10:31am UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/11 "2019-07-02T10:31:41Z")

</div>

Yeah it’s not a markdown fix, simply an adjustment to the way the toolbar operates, toolbar introduces bad markdown, it needs to be smarter about adding new lines

---

<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: [July 2, 2019, 10:34am UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/12 "2019-07-02T10:34:32Z")

</div>

Right, fixing the toolbar to use “block mode” when there are new lines in the selection is easy.

Supporting

```plaintext
[spoiler]mixed
formatting
[/spoiler]

```

is not.

---

<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: [July 2, 2019, 10:49am UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/13 "2019-07-02T10:49:21Z")

</div>

> [@zogstrip](#):
>
> fixing the toolbar to use “block mode” when there are new lines in the selection is easy.

Yes but that is the only thing being requested here

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [July 2, 2019, 6:34pm UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/14 "2019-07-02T18:34:02Z")

</div>

@pmusaraj can you take a look? The selection and buttons in the editor are very well tested so it should be fairly obvious how to create a test for this situation.

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [July 2, 2019, 10:28pm UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/16 "2019-07-02T22:28:54Z")

</div>

This should be fixed via these two commits ([core](https://github.com/discourse/discourse/commit/6e3e0685fb2171fc6917313ec1296ffc3a63cf52), [discourse-spoiler-alert](https://github.com/discourse/discourse-spoiler-alert/commit/2cac1b13fbd30117835b750404e6f2af2efcf25d)), the toolbar button will use “block mode” if the selected string is multiline.

---

<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: [July 4, 2019, 10:00pm UTC](https://meta.discourse.org/t/editor-toolbar-generates-invalid-multi-paragraph-spoilers/66475/17 "2019-07-04T22:00:18Z")

</div>

This topic was automatically closed after 47 hours. New replies are no longer allowed.
