0

I'm trying to format some text with newlines using the backtick syntax like so:

text: `Foo
        Bar` 
  },

https://codepen.io/nz2198/pen/eYpoRdw?editable=true%3Dhttps%3A%2F%2Fsweetalert2.github.io%2F

The text isn't getting delimitited by a newline. How do I fix this?

nz_21
  • 6,140
  • 7
  • 34
  • 80
  • 1
    It actually is indented; check the innerHTML of `#swal2-content` element. But whitespace is collapsed by default when displaying non-preformatted element. – raina77ow May 25 '20 at 15:16
  • Check this thread for details: https://stackoverflow.com/questions/39325414/line-break-in-html-with-n – raina77ow May 25 '20 at 15:17

2 Answers2

1

You need to pass your text as HTML, as the doc says : https://sweetalert2.github.io/#configuration

Following your current codepen link, you just have to replace "text" with "html" :

{
    title: 'Question 1',
    html: 'Foo <br\>Bar'
}
Sylvain
  • 46
  • 5
0

add a property to the css class. it should make the whitespace render as you want.

.swal2-html-container {
    white-space: pre;
}
Argee
  • 1,216
  • 1
  • 12
  • 22