6

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.

Kiran Mohan
  • 2,696
  • 6
  • 36
  • 62

2 Answers2

4

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.

Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111
0

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.

albert
  • 8,285
  • 3
  • 19
  • 32
  • That would set backgound color for the whole note. I would like to highlight only the "code" part of the note in the example. – Kiran Mohan Jan 16 '21 at 05:14