Specifying the background color of some text with back over multiple lines

0 votes
asked May 12 in Question / help by Filippo

I would like to write 

@startuml

class Foo {

    <back:#F29526>
    Lorem ipsum dolor sit amet, consectetur
    adipiscing elit, sed do eiusmod tempor
    incididunt ut labore et dolore magna aliqua.
    Ut enim ad minim veniam, quis nostrud
    exercitation ullamco laboris nisi ut
    aliquip ex ea commodo consequat. Duis
    aute irure dolor in reprehenderit in
    voluptate velit esse cillum dolore eu
    fugiat nulla pariatur. Excepteur sint
    occaecat cupidatat non proident, sunt
    in culpa qui officia deserunt mollit
    anim id est laborum.
    </back>

}

@enduml

but I am forced to write :

@startuml

class Foo {

    <back:#F29526>Lorem ipsum dolor sit amet, consectetur </back>
    <back:#F29526>adipiscing elit, sed do eiusmod tempor </back>
    <back:#F29526>incididunt ut labore et dolore magna aliqua. </back>
    <back:#F29526>Ut enim ad minim veniam, quis nostrud </back>
    <back:#F29526>exercitation ullamco laboris nisi ut </back>
    <back:#F29526>aliquip ex ea commodo consequat. Duis </back>
    <back:#F29526>aute irure dolor in reprehenderit in </back>
    <back:#F29526>voluptate velit esse cillum dolore eu </back>
    <back:#F29526>fugiat nulla pariatur. Excepteur sint </back>
    <back:#F29526>occaecat cupidatat non proident, sunt </back>
    <back:#F29526>in culpa qui officia deserunt mollit </back>
    <back:#F29526>anim id est laborum.</back>

}

@enduml

to get the background color on all lines, thus having to wrap all lines with back tags.
Do you have a syntax to apply background color over multiple lines ?

1 Answer

0 votes
answered May 12 by kirchsth (2,890 points)

My workaround is not perfect (you have to write the text in one line with \n as line break),
but if the text is not too long you could defined a function like StyledMultiLine($text, $styleStart, $styleEnd) and use it in the class body itself

@startuml
' function could be stored in a different file and included
!function StyledMultiLine($text, $styleStart, $styleEnd)
  !$multiLine = $styleStart

  !while (%strpos($text, "\n") >= 0)
    !$brPos = %strpos($text, "\n")
    !$multiLine = $multiLine + %substr($text, 0, $brPos) + $styleEnd + "\n" + $styleStart
    !$text = %substr($text, $brPos +2 )
  !endwhile

  !if (%strlen($text)>0)
    !$multiLine = $multiLine + $text
  !endif

  !$multiLine = $multiLine + $styleEnd

  !return $multiLine
!endfunction

class FooNew {
  StyledMultiLine("Lorem ipsum dolor sit amet, consectetur\nadipiscing elit, sed do eiusmod tempor\nincididunt ut labore et dolore magna aliqua", "<back:#F29526>", "</back>")

}


class Foo {
    <back:#F29526>Lorem ipsum dolor sit amet, consectetur
    adipiscing elit, sed do eiusmod tempor
    incididunt ut labore et dolore magna aliqua.
    Ut enim ad minim veniam, quis nostrud
    exercitation ullamco laboris nisi ut
    aliquip ex ea commodo consequat. Duis
    aute irure dolor in reprehenderit in
    voluptate velit esse cillum dolore eu
    fugiat nulla pariatur. Excepteur sint
    occaecat cupidatat non proident, sunt
    in culpa qui officia deserunt mollit
    anim id est laborum.
    </back>
}
@enduml

...