0

I am using the dojo createText function to programmatically create a text object in Javascript. This functionality has been working well except for newline characters within the string. I would like for this functionality to be able to handle multiline text as well as single line text. For example:

var content = “Mercury\nVenus\nEarth\nMars”;
console.log(content);
surface.createText({x: 0, y: 0, text: content, align: “start”});

console.log shows this:
Mercury
Venus
Earth
Mars

Whereas createText draws this:
Mercury Venus Earth Mars

The behavior appears to be as if createText is replacing the newline character with a space character. Is there a syntax to get createText to draw the text visually as console.log does for multiline content? Or is the only option to split the string and use a separate createText for each?

Rick
  • 1
  • 1

1 Answers1

0

It is not the issue with dojo, but HTML. linebreaks are not recognized in HTML you need to replace \n with <br/> or you need to force HTML to recognize it as mentioned in this post New line in text inside div

Community
  • 1
  • 1
T Kambi
  • 1,389
  • 2
  • 9
  • 16