Activity diagram: multi-line and \n management

0 votes
asked Apr 27, 2020 in Bug by The-Lu (63,920 points)

Hello,
When testing multi-line and \n management, on Activity-diagram-beta, we observe that:

1/ on one line that OK

@startuml
:Here is the result: 1a\n2b\n3c\nzz;
@enduml

2/ on two lines that KO: the '\n' is not evaluate!

@startuml
:Here is the result: 1a\n2b\n3c\n
zz;
@enduml

Why?

3/ Why the '\n' is not evalute directly after the preprocessing?

AS:

@startuml
:Here is the result: 1a
2b
3c
zz;
@enduml

And can perhaps corrected this case:


Regards,
Th.

1 Answer

0 votes
answered Apr 28, 2020 by plantuml (294,960 points)
It's not well documented, but here is the logic :

1/ When you use multi-line, there is theorically no need to change \n to newline, because you can actually use a real newline if you need. Furthermore, since PlantUML is used in software management, it could be useful that PlantUML does not interpret \n in that case:

@startuml
:Here is the line executed:
fprintf("hello\n", %s);
@enduml

2/ In a single line, since there are no other way, we interpret \n as a real newline

Now I understand that this may sound confusing, and that may be an issue, especially for preprocessing.

Maybe you can tell us more about what you are trying to do with the preprocessor.

I also think that we should have ignore \n in all cases and we should propose a non-standard way for newline (something like <u+newline> for example) so that the PlantUML syntax would not interfere with all other syntaxes. What do you think about it ?
commented Apr 28, 2020 by The-Lu (63,920 points)

Thanks for your answer. I understand now this behavior.

“that may be an issue, especially for preprocessing.
Maybe you can tell us more about what you are trying to do with the preprocessor.”

However, the main goal is also: how we manage that with preprocessing and variables?

Like this:

1/ One Line

@startuml
!$r="1a\n2b\n3c\n"
:Here is the result: $r zz;
@enduml

unfortunately with a space before 'zz'!  no

2/ Multiline

@startuml
!$r="1a\n2b\n3c\n"
:Here is the result:
$r
zz;
@enduml

Thanks for your actions, and for a global management of the multiline (perhaps adding just a rule on the doc. that preprocessing and variables must be used on one-line (not on multi-line), just to avoid to make a lot of dev. in order to manage all the cases).

Thanks again,
Th.

commented May 1, 2020 by plantuml (294,960 points)

Many thanks for your comments and your tries.

(ps: About the "space" issue, you can use ## - see this example )

All this \n management is confusing and even us are completely lost now :-)

The real issue is that multiline can be managed :

We really need to move toward something more consistent now...

We need to think about it, any comment welcome :-)

commented May 4, 2020 by Lucas Pereira Lima
I just got pointed to this thread by a question of mine regarding this. A suggestion that comes to my mind is simply adding another escape character when one wants it displayed explicitly, and, without that, \n always should get interpreted, everywhere, as a new line. It is kind of what happens in most programming languages when you want to write \n on a string - you have to escape it in order to get it taken literally.
commented May 4, 2020 by plantuml (294,960 points)

\n always should get interpreted, everywhere, as a new line. It is kind of what happens in most programming languages

Well, it was really our first idea at the very begin.

Now, we are not so sure : PlantUML is used to document more than to program. The main issue is that you have sometimes some code example inside text description. And it become complex then : of course, you can escape the backslash. But sometime, you have escaped backslash into source code. So now you have to double-escape backslash in PlantUML...

So I am wondering if using a non-standard way is finally a better idea. Something like <u+newline> or <u+nl>. This way, backslash would be treated as a regular char.

Nothing is final yet, we are still thinking about pro and cons :-)

...