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?

2
  • 1
    It actually is indented; check the innerHTML of #swal2-content element. But whitespace is collapsed by default when displaying non-preformatted element. Commented May 25, 2020 at 15:16
  • Check this thread for details: stackoverflow.com/questions/39325414/line-break-in-html-with-n Commented May 25, 2020 at 15:17

2 Answers 2

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'
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

.swal2-html-container {
    white-space: pre;
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.