Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put code chunks in details, summary?

Tags:

markdown

I want to put code chunks 'inside' the 'details' section.

Just like the one link. If you click 'Click to expand!' there comes a code.

At first I just did as usual,

<details>
<summary>BlahBlah</summary>
blahblah2

Tried to put code chunks here starts with '```'

blahblah3
</details>

And it fails. Code chunks are not inside the 'details' section.

Parts starting from code chunks to 'blahblah3' all pop up.

Any help will be appreciated. Thanks in advance.

like image 360
HyeonPhil Youn Avatar asked Oct 28 '25 12:10

HyeonPhil Youn


2 Answers

The Python markdown lib has an extension for this, md_in_html:

<details markdown="1"><summary>code</summary>
```python
print('Hello World!')
```
</details>

https://github.com/Python-Markdown/markdown/blob/master/docs/extensions/md_in_html.md

like image 150
Sam Watkins Avatar answered Oct 31 '25 11:10

Sam Watkins


This worked for me on Kramdown:

{::options parse_block_html="true" /}

<details><summary markdown="span">code</summary>
```python
print('Hello World!')
```
</details>

{::options parse_block_html="false" /}

Source

like image 24
Macaulay Avatar answered Oct 31 '25 12:10

Macaulay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!