New line in table built with variables broken [from 1.2020.20]

0 votes
asked Nov 23, 2020 in Bug by The-Lu (33,360 points)

Hello PlantUML team,

Here is an issue reported (by Jesper) on:

with a broken example from 1.2020.20:


[See on PlantUML server]

Thanks for your support,
Regards,
Th.

commented Jan 20 by nolisanjose@gmail.com
Not good. It destroyed a lot of existing code.

1 Answer

0 votes
answered Nov 26, 2020 by plantuml (259,840 points)

We have added a function %newline() that output a new line :-)

So now you should use :

@startuml
!global $table = "|= Field1 |= Field 2 |"
!procedure $row($value1, $value2)
%set_variable_value("$table", %get_variable_value("$table") + %newline() + "| " + $value1 + " | " + $value2 + " |")
!endfunction

$row("1", "2")
$row("3", "4")

rectangle r [
<i>on rectangle:
$table
]
@enduml

commented Nov 26, 2020 by The-Lu (33,360 points)

yes

That is good.... but this new feature is not so so good...

That broke also all the new line on multi-line label!

Here are some other similar issue:

1/ Minimal example

@startuml
node n [
aaa\n
bbb
]
@enduml

2/ Example with procedure...

Where for example, we does not manage the argument value directly... and the presence of newline on the argument...

@startuml
!procedure $foo($as, $label)
  node $as [
    ----
    The label is:
    <b>$label
    ----
    other data
  ]
!endprocedure

$foo("a", "<color:red>aaa\nbbb")
$foo("b", "label without newline")
@enduml


See also other broken examples:

I understand the difficulty about newline management... between inline and multi-line... but...

→ What are changes since last version ?

Thanks for your support...
Regards,
Th.

commented Nov 28, 2020 by plantuml (259,840 points)

I understand the difficulty about newline management... between inline and multi-line... but...

Yes, it's a mess :-)

In hindsight, it was a bad idea to interpret "\n" as "newline". We did so because it was the usual way but it has become an issue when users want to actually print \n.

So, as advice, do not use it too much : it's probably going to be removed in the future.

We are still looking for a replacement for "\n" as "newline". What about <+newline> or <U+newline> or <U+NL> ? This is completely non standard, but this way, there will be not confusion between PlantUML language and all other programming language.

We are also thinking about implementing triple quote string.Do you thing it's a good idea ?

commented Dec 2, 2020 by The-Lu (33,360 points)

Hello PlantUML,

Thanks for your answer.

In fact, the main issue is that when we does not know on which context a string or a variable will be used, as:

@startuml
!$var=" aaa \n bbb \n <u:blue>ccc \n <color:green>ddd <U+000A> eee"

node "$var" as a

node b [
$var
on multi-line context
]

node c [
<code>
$var
</code>
]
@enduml


[See on PlantUML server]

For the question:

What about <+newline> or <U+newline> or <U+NL> ?

Why not use ... the normal Unicode  <U+000A> ('LINE FEED (LF)' (U+000A))
But on the example, the value is not evaluate. Why ?

Then implementing:

are perhaps a good news... in order to suppress the evaluation of  '\n'...
And I think that is similar question/issue on ‘JSON’ side (where ‘\n’ is an escaped value for newline, and must be evaluate [or not]...)!

See also discussion on the same subject:

If that can open an open discussion,
Regards,
Th.

commented Dec 9, 2020 by anonymous
Why not just saying that '\' is an escape character, so if you write '\n' the n is escaped and interpreted as a new line:

foo\nbar is always rendered as

foo

bar

and if you do not want it to be interpreted escape the backslash with a second backslash '\\n'

foo\\nbar is always rendered as

foo\nbar
...