Unable to use collapsible/expand markdown

collapsible markdown?

CLICK ME

This text will be hidden #### yes, even hidden code blocks! (seems like bold title dont work here too)

print("hello world!")

^ I am unable to do this with Hugo in .MD files, am I missing something?

Edit: I followed "detail" html tag and it worked (after fixing it abit), but it only works for single line content, not a chunk of markdown code as above.

Edit2: this is what I tried:

layouts/shortcodes/detail-tag.html

<details>
  <summary>{{ (.Get 0) | markdownify }}</summary>
  {{ .Inner | markdownify }}
</details>

Markdown:

{{< detail-tag "CLICK ME" >}}
This text will be hidden

#### yes, even hidden code blocks! (seems like bold title dont work here too)

```python
print("hello world!")
```
{{< /detail-tag >}}
2 Likes

Hey thanks a lot for the fast reply, unfortunately it couldn’t get it to work and it isn’t displaying. Upon further investigation it seems like it is considered a raw html and hence marked as unsafe.

I have enabled it by setting the config.toml from this (ii.com: Hugo Tips, Shortcodes, and Fragments):

[markup]
  [markup.goldmark]
    [markup.goldmark.renderer]
      unsafe = true

Works fine now, appreciate it!

With the example content you provided (markdown only), it works without changing the default configuration.

git clone --single-branch -b hugo-forum-topic-32810 https://github.com/jmooring/hugo-testing hugo-forum-topic-32810
cd hugo-forum-topic-32810
hugo server

Perhaps you are including HTML between the opening and closing shortcode tags?

No html inside (I copied and pasted the example you gave), so I thought it’s because of the html or the shortcode html-like tags… I am using the theme GitHub - formspree/blogophonic-hugo: Blogophonic – a Hugo blog theme by Formspree though, not sure if that affects anything…?

Can you share the repository for your project? I cannot understand why you need the unsafe flag for this to work.

You are right, it is working fine without the flag. Hmm not sure what happened, I might have did something wrong earlier or some cache issue. Will report back if something happens again. All is fine now, I appreciate your help very much!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.