Skip to content
Advertisement

In Javascript, make the content wrap, and some of them wrap an extra line

This is the instruction I did not use to add newlines.The picture shows what it looks like now.

console.log(path2gcode(svg));

enter image description here

This is the instruction I use to add newlines.The picture shows what it looks like now.

console.log(path2gcode(svg).join("n"));

enter image description here

I actually made the text look the same as Figure 2, but Figure 2 somehow skipped one more line. All, my question is why this problem occurs and how should I change it.

Advertisement

Answer

When you use .join('n') you are essentially adding a newline to the end of each string, even ones that already have a new line. The answer depends on what you want to do, but to make it not print blank lines, you could do something like:

console.log(path2gcode(svg).map(v => v.replace(/n$/, '')).join("n"));

^All that does, is checks each entry and removes a trailing n if it has one.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement