# 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:** [2016 年10 月 13 日 18:11 UTC](https://meta.discourse.org/t/hide-details-applies-separately-to-each-paragraph/51510 "2016-10-13T18:11:22Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![Silvanus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/silvanus/32/62831_2.png) [@Silvanus](https://meta.discourse.org/u/Silvanus)\
发布日期： [2016 年10 月 13 日 18: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]

```

---

_[View the full topic](https://meta.discourse.org/t/hide-details-applies-separately-to-each-paragraph/51510)._
