Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code block in spoiler with markdown

Is there any way in markdown to combine the code (inside ```) with the spoiler (after !>) syntax in order to obtain some code inside a spoiler ?

I'm using the markdown implemented in GitLab.

like image 498
Ellone Avatar asked Aug 24 '15 11:08

Ellone


3 Answers

https://docs.gitlab.com/ee/user/markdown.html#details-and-summary

You can use raw HTML

<p>
<details>
<summary>Click this to collapse/fold.</summary>

These details <em>remain</em> <strong>hidden</strong> until expanded.

<pre><code>PASTE LOGS HERE</code></pre>

</details>
</p>

or now GitLab supports Markdown within <details> blocks

<details>
<summary>Click this to collapse/fold.</summary>

These details _remain_ **hidden** until expanded.

```
PASTE LOGS HERE
```

</details>
like image 84
leb4r Avatar answered Oct 14 '22 13:10

leb4r


The following should do the trick:

<details>
  <summary>Click to expand</summary>
  Whatever
</details>
like image 11
Woworks Avatar answered Oct 14 '22 13:10

Woworks


As @Chris mentions in a comment, GitLab Flavored Markdown doesn't appear to mention anything about supporting "spoiler" syntax (after !>). Additionally, "spoiler" syntax is not an "official" syntax (neither are fenced code blocks as @Chris points out) and is not very common. Personally, I'm not aware of any particular Markdown implementation which supports it. That said, as I understand the syntax, it is basically an extension of the blockquote syntax. So, whatever works for blockquotes should work for spoilers if the implementation you are using supports spoilers.

Another issue to be aware of is that not all Markdown implementations support Fenced Code Blocks, and not all that do support them equally. For example, some of the earliest implementations do not support the fenced code blocks being nested. Therefore, depending on which Markdown implementation you are using, you may get different results (I have no idea which implementation GitLab uses). That is the price you pay for using non-standard features.

In any event, assuming the implementation you are using has full support, the following would presumably work:

!> ```javascript
!> alert("42");
!> ```

Note that I authored my code block as normal. Then I simply inserted the three characters at the beginning of each line (exclamation point, greater than symbol, and a space). If that doesn't work, then a safe assumption is that the implementation does not support one or more of the non-standard features required.

like image 3
Waylan Avatar answered Oct 14 '22 15:10

Waylan