swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Collapsible markdown in descriptions?

Open michalrus opened this issue 7 years ago • 9 comments

Content & configuration

n/a

Is your feature request related to a problem?

Some of our endpoints have very large descriptions. It would help a lot if we could use collapsible blocks in Markdown, like you can do on GitHub, e.g.:

CLICK ME

yes, even hidden code blocks!

print("hello world!")

Describe the solution you'd like

Swagger-UI’s Markdown parser accepting collapsibles, like the CLICK ME one above.

Describe alternatives you've considered

We’re using sections, but, say, 10 screen heights of text, images etc. is… bad UX.

michalrus avatar Oct 30 '18 00:10 michalrus

Hmm.. since the functionality is provided by the browser (most browsers, anyway), this should simply be a matter of adding the <details> and <summary> tags to our element whitelist.

I'm prioritizing this, as it's widely helpful and likely easy to implement.

Edit: it's <details> not <detail>

shockey avatar Oct 31 '18 17:10 shockey

I'm prioritizing this

Thank you very much! :sparkles:

michalrus avatar Oct 31 '18 18:10 michalrus

@michalrus, it appears to me that this is already working:

swagger: "2.0"

info:
  description: "<details><summary>wow</summary> look at this!</details>"
  
paths:
  /:
    get:
      description: >
        <details>
          <summary>wow</summary>
          me too!
        </details>

though, to be fair, the multiline value has some weird newlines (cc #3867, haven't forgotten about it 😄). Even if this is working on your end, happy to keep this open as a request to polish that detail.

let me know what you're seeing on your end!

shockey avatar Nov 01 '18 01:11 shockey

Wonderful! Thanks. =)

I only had to add this style to make it look sensible:

        details                 { margin:        2em 3em; }
        details       > summary { margin-left:   -1em; font-size: 1.5em; font-weight: bold; }
        details[open] > summary { margin-bottom: 0.667em; }

(Forgive me if it’s rubbish, I’m no frontend dev.)

michalrus avatar Nov 01 '18 17:11 michalrus

markdown inside the details is not supported ? its just rendered verbatim

bingunginter avatar Apr 09 '20 19:04 bingunginter

markdown inside the details is not supported ? its just rendered verbatim

@bingunginter works for me on https://editor.swagger.io:

openapi: 3.0.0
info:
  title: test
  version: 1.0.0
  description: >-
    <details>

    **Bold** text

    </details>
paths: {}

OpenAPI uses CommonMark[1] which allows Markdown formatting inside HTML tags in certain cases. Refer to the CommonMark specification, "HTML blocks" section, examples 122 and 138.


[1] OpenAPI 3.0 uses CommonMark. OpenAPI 2.0 uses GitHub-Flavored Markdown (GFM), but GFM is also based on CommonMark.

hkosova avatar Apr 20 '20 08:04 hkosova

👋🏼 This is really handy! But... there is a bit of an awkward UX when using this at the tag level. When you to expand the description, the click also registers for the collapsible list of paths and opens/closes that at the same time. Is there a simple fix/workaround for this? Peek 2021-12-07 14-50

brad avatar Dec 07 '21 21:12 brad

I worked around this by injecting this javascript

// It takes the document a sec to load the swagger stuff, loop until we find it
let swaggerLoaded = setInterval(() => {
  if (document.getElementById("swagger-ui")) {
    clearInterval(swaggerLoaded);
    // Disable event bubbling for summary elements
    for(let summary of document.getElementsByTagName("summary")) {
      summary.addEventListener("click", e => e.stopPropagation());
    }
  }
}, 300); // check every 300ms

brad avatar Dec 08 '21 19:12 brad

here is some bug about this:

    description: "<details><summary>title</summary>\r\n```\r\nmycode```\r\n</details>"

the text ```</details> will display into code block

image

But this is fine:

    description: "<details><summary>title</summary>\r\n```\r\nmycode\r\n```\r\n</details>"

image

And this is break again:

    description: "<details><summary>title</summary>\r\n```\r\nmycode\r\n        ```\r\n</details>"

image

Flithor avatar Sep 12 '24 11:09 Flithor