question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Newlines in description fields are converted to <br>

See original GitHub issue

Q&A (please complete the following information)

  • OS: Linux
  • Browser: Chrome
  • Version: 67
  • Method of installation: npm
  • Swagger-UI version: 3.17.0
  • Swagger/OpenAPI version: Swagger 2.0

Content & configuration

Example Swagger/OpenAPI definition: https://his-dev.mmprototype.net/api/v1/api-docs

swagger: '2.0'
paths: {}
basePath: '/'
info:
  title: 'Health Insurance System API'
  version: '1.0.0'
  description: |
    System for storing beneficiaries' health insurance information for the
    Third-Party Liability group. Update active coverage or query the Carrier
    Code Master File.

Describe the bug you’re encountering

Newlines in the description fields are being converted to <br>. Since these fields should be treated as markdown, single newlines should be converted to an empty space. Double newlines would be converted to <p>.

For example:

System for storing beneficiaries' health insurance information for the\nThird-Party Liability group. is being converted to System for storing beneficiaries' health insurance information for the <br> Third-Party Liability group.

To reproduce…

Steps to reproduce the behavior:

  1. Enter a description with a linebreak.
  2. Render with SwaggerUI

Expected behavior

Linebreaks are converted to spaces. Contiguous lines are combined in a single <p>.

Screenshots

screenshot from 2018-06-15 16-23-55

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
DavidBiesackcommented, Jul 10, 2018

Thanks for the details, @shockey Note that multiple Markdown paragraphs (when using >- ) are rendered by Swagger UI with <br>; I think this is incorrect behavior (though not exactly what the OP cited when using | instead of >- ):

This is
paragraph 1.

This is paragraph 2.

is converted to

<p>This is paragraph 1. <br>This is paragraph 2.</p>

not as the expected

<p>This is paragraph 1.</p>
<p>This is paragraph 2.</p>
2reactions
shockeycommented, Apr 23, 2019

Changing this over to a bug 😄

We’ve opted into this behavior:

https://github.com/swagger-api/swagger-ui/blob/b9b4ab20af9d369e02baec3585412fd11ce4bf27/src/core/components/providers/markdown.jsx#L21

Per Remarkable’s docs:

breaks: Convert ‘\n’ in paragraphs into <br>.

Disabling this does get rid of the breaks seen in the test definition provided by @adborden.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Convert Line Breaks to HTML <br>
Solved: Hello All. I am building a block schedule request form that uses Power Automate to send the Approval request then replies to...
Read more >
Rails: Converting a text field's linebreaks into <br />
I have a text field in my model called 'about', which I'm trying to display on a show page, but none of the...
Read more >
How to add a line break to the description field o... - ServiceNow
For this catalog item I am working on, for the description they want essentially multiple sentences to be showing on their own with...
Read more >
Line breaks in the message are converted to <br ... - Drupal
I would expect the module to either A) convert newlines to br tags and allow them in the HTML, or B) leave the...
Read more >
Text (plain, long) automatically has line break converted to <br>
Since you are using a custom template, the quicker way is just to use the replace() filter. {{ content.field_testing|replace({'<br>': '' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found