Can use line brake in note generated from variable?

0 votes
asked Apr 27, 2021 in Question / help by Wojtek

Hi, 

I try to use note in sequence diagram created from variable. I have problem with line breaks.

I'm trying:


@startuml
start

!$note_text = "line1\nline2"

:aaa;
note right 
 $note_text
end note

stop
@enduml

but then I see:

PlantUML diagram

Is any method for break lines in that case?

Regards

commented Apr 27, 2021 by Wojtek

I tried also: 

!$note_text = "line1<br/>line2"

but not working too :(

2 Answers

0 votes
answered Apr 27, 2021 by Martin (8,360 points)
 
Best answer

The way I picture it - you're mixing Plantuml's single-line syntax (using \n) where everything should fit on one line, with Plantuml's multi-line syntax (using note/end note) where you use real carriage returns.

So Plantuml's answer is to continue with using note/end note but turn all the \n into real carriage returns using %newline().

I'll give the opposite answer:  Keep the \n, but change the note into a single-line format note:

note right: $note_text

0 votes
answered Apr 27, 2021 by Wojtek

OK.... I answer myself ;)

Solution not comfortable but works close enough :)

http://www.plantuml.com/plantuml/uml/TP51ImCn48NlxrTCmmekzb3hJR5Ky58G5NiGeR14ExM1DBiaMVJdcyoQMhJcCZEyxxs1oJn4xME_iv0667M-VUDrxvcgsyNoyUxcfLdSDqyFpylJohMHGmrAR_InDPRf94HlsHLfDX5HWAfh0rqBaRflOgnMJjK_aDcGS3Cgpk9sUiTYxrzJGh7JP2o6-XSjwbyyesVJWtri0nzVD3Z-YLNg8CAjpMO_YXr5aACWT_ip0aDC4_apvYXh79-lN2xJeLmeu59hVOKCaZVlsqWuVdw9gP4sK1w14DiEypIdJ_m2

@startuml
start

!procedure $DISPLAY_IN_ROWS($notes)
    !while %strlen($notes)>0
        !$pos = %strpos($notes,"\n")
        !if $pos > 0
            !$name = %substr($notes, 0, $pos)
            !$notes = %substr($notes,$pos+2)
        !else
            !$name = $notes
            !$notes = ""
        !endif
        $name
    !endwhile
!endprocedure

!$note_text = "line1\nline2\nline3"

:aaa;
note right 
$DISPLAY_IN_ROWS($note_text)
end note

stop
@enduml

PlantUML diagram

If anyone knows  solution without writing 20 lines of code I'm still very curious :D

commented Apr 27, 2021 by plantuml (294,960 points)

Not perfect, but you can have:

@startuml
start

!$note_text = "line1" + %newline() + "line2" + %newline() + "line3"

:aaa;
note right 
$note_text
end note

stop
@enduml

http://www.plantuml.com/plantuml/umla/SoWkIImgAStDuG8pkBWKLVBoIrBZIr8hIXHi5PHoClDI3PKKj1LKyrBBGHmDJI07B6o4NTXOYOlBAZ4nqPeBP912KMPwHea25y9KhjIy50KGZmjePNu1bmEG3xGV0000

We need to improve all this \n management...

commented Apr 27, 2021 by Wojtek
Much better !!!

Thank  you very much !!! :)
...