Preformatted text in textarea

If I have a textarea input;

viewof text = Inputs.textarea({value: "hello"})

How do I set the value to be a preformatted text with line breaks? Say, I want to input and display this chunk of code?

if (result > 5 && x <= 3 | !is.na(x)) {
  print("Condition met")
} else {
  print("Condition not met")
}

Use template strings:

viewof text = Inputs.textarea({value: `
if (result > 5 && x <= 3 | !is.na(x)) {
  print("Condition met")
} else {
  print("Condition not met")
}
`.trim()})
1 Like

Thanks! Is there some way to preserve the formatting when printing the output. I usually just use $text which doesn’t preserve formatting.

If by formatting you mean line breaks and indentation, then you can preserve those in HTML output by setting the desired white-space behavior:

1 Like

Ah right! I had forgotten about that! :slightly_smiling_face: