How to define long strings in multiple lines?

0 votes
asked Apr 30, 2020 in Question / help by Lucas Lima

I have a very long text to insert in my legend. It can get written on a single line alright, but the readability gets terrible. If I try to use the default escape character at the end of the line ("\") and continue the text on the following, plantuml complains about an error. Writing the string in a separate variable doesn't work either. How can I define a string function parameter in multiple line, in order to avoid a super long line?

The code is as follows:

@startuml
!global $legendText = "Notes"
!global $legendIndex = 0

!unquoted function $insertNote(position, element, text)
    !global $legendIndex = $legendIndex + 1
    !global $legendText = $legendText + "\n" + $legendIndex + ". " + text
    note position of element #white
        $legendIndex
    end note
!endfunction

component a
component b

a -> b

$insertNote(left, a, "somewhat long text to be inserted here")

$insertNote(right, b, "A REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY LLONG NOTE THAT CANNOT BE WRRITEN IN 2 LINES")

component notes as "$legendText" #white
a -[#hidden]down-> notes

@enduml

1 Answer

0 votes
answered May 1, 2020 by The-Lu (63,920 points)

Hello Lucas,

From dec 2019 - jan 2020, see :

you can use '\' on a function call as:

$insertNote(right, b, "A REALLY REALLY REALLY REALLY\
 REALLY REALLY REALLY REALLY REALLY REALLY REALLY \
REALLY LLONG NOTE THAT CANNOT BE WRRITEN IN 2 LINES")

[Click on the image to view the code on PlantUML Web Server]


If it can help,
Regards,
Th.

commented May 4, 2020 by lp-lima (140 points)
Thanks for your answer!

That is weird. I have a plugin for IntelliJ that recognizes this code as valid, but, when I try to actually generate the image, it fails. I'm suspecting that the fact that I have installed plantuml from brew on MacOS, which is downloading the file from https://downloads.sourceforge.net/project/plantuml/1.2019.11/plantuml.1.2019.11.jar - I probably don't have the latest version, then. Going to see if I  can get that fixed.
commented May 4, 2020 by lp-lima (140 points)
So, I have update my plantuml version to PlantUML Version 1.2020.08, and now it works. Had to replace the "function" for "procedure", though - it is not optional.
...