# Hide Details applies separately to each paragraph

**URL:** https://meta.discourse.org/t/hide-details-applies-separately-to-each-paragraph/51510
**Category:** Bug
**Tags:** hide-details
**Created:** [Octobre 13, 2016, 6:11 UTC](https://meta.discourse.org/t/hide-details-applies-separately-to-each-paragraph/51510 "2016-10-13T18:11:22Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Silvanus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/silvanus/32/62831_2.png) [@Silvanus](https://meta.discourse.org/u/Silvanus)
#### Post date: [Octobre 13, 2016, 6:11 UTC](https://meta.discourse.org/t/hide-details-applies-separately-to-each-paragraph/51510/1 "2016-10-13T18:11:22Z")

</div>

# Description

Hi, there’s a bug with details-plugin: when selecting a big chunk of text separated in paragraphs, clicking the Hide Details -button causes the `[details...]` to be prefixed to each separate paragraph, not just the beginning (and end) of the selection.

The same bug applies to spoiler-plugin.

# Location of bug

As far as I know, the problem is here (no idea how to fix):

[https://github.com/discourse/discourse/blob/master/plugins/discourse-details/assets/javascripts/initializers/apply-details.js.es6#L14-L22](https://github.com/discourse/discourse/blob/master/plugins/discourse-details/assets/javascripts/initializers/apply-details.js.es6#L14-L22)

So likely the culprit is `applySurround` and how it functions…

# Reproduction

1. Write several lines of text (separate with linebreak)
2. Choose all the lines.
3. Click Hide Details.
4. PROFIT

# Result

> **Summary**
>
> Lines with text

> **Summary**
>
> Lines with text

> **Summary**
>
> Lines with text

> **Summary**
>
> Lines with text

> **Summary**
>
> Lines with text

```
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]

```

# Should result in:

[details=Summary]Lines with text  
Lines with text  
Lines with text  
Lines with text  
Lines with text[/details]

```
[details=Summary]Lines with text
Lines with text
Lines with text
Lines with text
Lines with text[/details]

```

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [Octobre 13, 2016, 6:14 UTC](https://meta.discourse.org/t/hide-details-applies-separately-to-each-paragraph/51510/2 "2016-10-13T18:14:04Z")

</div>

For reference, this is the markdown that selecting multiple lines and clicking hide details generates.

```plaintext
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]
[details=Summary]Lines with text[/details]

```

---

<div class="post-metadata">

### Author: ![Silvanus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/silvanus/32/62831_2.png) [@Silvanus](https://meta.discourse.org/u/Silvanus)
#### Post date: [Octobre 13, 2016, 6:17 UTC](https://meta.discourse.org/t/hide-details-applies-separately-to-each-paragraph/51510/3 "2016-10-13T18:17:30Z")

</div>

Thanks, I edited this into the first message!

---

<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: [Octobre 13, 2016, 7:22 UTC](https://meta.discourse.org/t/hide-details-applies-separately-to-each-paragraph/51510/4 "2016-10-13T19:22:30Z")

</div>

Aha we should fix this @tgxworld

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [Octobre 14, 2016, 7:00 UTC](https://meta.discourse.org/t/hide-details-applies-separately-to-each-paragraph/51510/5 "2016-10-14T07:00:42Z")

</div>

PR in

[https://github.com/discourse/discourse/pull/4499](https://github.com/discourse/discourse/pull/4499)

Would love to get @eviltrout’s thoughts first before merging 🙂

---

<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: [Octobre 17, 2016, 2:08 UTC](https://meta.discourse.org/t/hide-details-applies-separately-to-each-paragraph/51510/6 "2016-10-17T14:08:11Z")

</div>

I said it was cool via chat, and it looks like the PR was merged. Thanks @tgxworld!

---

<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: [Octobre 17, 2016, 2:08 UTC](https://meta.discourse.org/t/hide-details-applies-separately-to-each-paragraph/51510/7 "2016-10-17T14:08:14Z")

</div>


