gollum / gollum

A simple, Git-powered wiki with a local frontend and support for many kinds of markup and content.
MIT License
13.83k stars 1.57k forks source link

details tag does not work as expected #1825

Closed abhangs closed 2 years ago

abhangs commented 2 years ago

Describe the bug

  1. Collapsible section with <details> tag does not work or not rendered as expected.
  2. Gollum does not show a collapsible section but instead it ignores the tag. I tried various iterations but could not get it to work.
  3. E.g. https://gist.github.com/joyrexus/16041f2426450e73f5df9391f7f7ae5f

To Reproduce I put the following in one of my markdown files for testing purposes

<details>
    <summary>click here</summary>

1. this
1. should
    1. be
    1. a folded
    1. list

</details>

Expected behavior The tag should be rendered as a collapsible section, just like on this Github website:

click here 1. this 1. should 1. be 1. a folded 1. list

Screenshots

The input:

goll-2

How it is rendered:

goll-1

Environment Info

  1. Gollum 5.2.3
  2. commonmarker (0.23.4)
  3. github-markup (4.0.1, 3.0.5)
  4. gollum-lib (5.1.3)
  5. gollum-rugged_adapter (1.1.2)
  6. kramdown (2.4.0)
  7. kramdown-parser-gfm (1.1.0)
dometto commented 2 years ago

You are using commonmarker, which turns out not to support HTML tags in Markdown by default, for safety reasons. You can change this by overriding the settings for commonmarker in gollum's config.rb by adding:

GitHub::Markup::Markdown::MARKDOWN_GEMS['commonmarker'] = proc { |content, options: {}|
  CommonMarker.render_html(content, [:UNSAFE, :GITHUB_PRE_LANG], [:tagfilter, :autolink, :table, :strikethrough])
}

This should be ok from a safety perspective as gollum implements its own sanitization.

Annoyingly, when using the default kramdown renderer (which in @abhangs's setup can be achieved by simply gem uninstall commonmarker), the <default> tag is present, but the markdown it contains is not rendered. That is, kramdown seems to ignore Markdown in HTML tags.

dometto commented 2 years ago

The workaround for kramdown is to do this:

<details markdown="1">
<summary>click here</summary>

Test

1. this
1. should
    1. be
    1. a folded
    1. list

</details>

Notice the markdown="1" in the <details> tag. Also note that the summary tag should not be indented.

Since we can support this feature with this minimal workaround on kramdown, I propose we close this issue. @abhangs would you perhaps have a moment to type something about this in the wiki?

abhangs commented 2 years ago

Thank you @dometto Your instructions worked. I have edited the wiki as well: https://github.com/gollum/gollum/wiki#HTML-Elements

avoidik commented 8 months ago

if you're looking for up-to-date config.rb

require 'commonmarker'
GitHub::Markup::Markdown::MARKDOWN_GEMS['commonmarker'] = proc { |content, options: {}|
  Commonmarker.to_html(content, options: {
    render: { unsafe: true }
  })
}