plantuml background color for text blocks within note
Asked Answered
M

2

7

I am trying set background color for specific blocks of multiline text within Plantuml sequence diagram "note".

For example, in the below snippet for Plantuml Sequence diagram, how to apply a specific background color for <code> part of the note?

participant Alice
note left of Alice
    This text with default color.
    <code>
    println("Hello Alice")
    println("Welcome to Wonderland!")
    </code>
end note

So far I could only find <back:color> but it doesn't seem to work on multiline text.

Monnet answered 13/1, 2021 at 16:3 Comment(0)
A
5

There may be a cleaner way with the new <style> features, but here's a somewhat kludgy solution using a preprocessor function

@startuml
!function $my_code($fgcolor, $bgcolor)
!return "<color:"+$fgcolor+"><back:"+$bgcolor+"><size:14><b><font:monospaced>"
!endfunction
participant Alice
note left of Alice
    This text with default color.
    $my_code(white, black)println("Hello Alice")
    $my_code(yellow, blue)println("Welcome to Wonderland!")
end note
@enduml

enter image description here

Note that since PlantUML doesn't require closing ending tags (new line turns them all off) this works.

Arpeggio answered 24/8, 2022 at 3:11 Comment(1)
thanks for bright me up many useful.Rabia
S
1

I think the solution for your problem might be a skin parameter:

@startuml
skinparam NoteBackgroundColor red
participant Alice
note left of Alice
    This text with default color.
    <code>
    println("Hello Alice")
    println("Welcome to Wonderland!")
    </code>
end note
@enduml

see for a full list e.g java -Djava.awt.headless=true -jar plantuml.jar -language and the available documentation about skinparameters.

Note: OP only wants to have the code part in another color and this solution gives the complete note a background color.

Spleenwort answered 15/1, 2021 at 9:50 Comment(1)
That would set backgound color for the whole note. I would like to highlight only the "code" part of the note in the example.Monnet

© 2022 - 2024 — McMap. All rights reserved.