8000 bug #49516 [Workflow] display label with new lines + colours properly… · symfony/symfony@5bc4d55 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5bc4d55

Browse files
bug #49516 [Workflow] display label with new lines + colours properly when rendering a PUML dump (alexislefebvre)
This PR was merged into the 5.4 branch. Discussion ---------- [Workflow] display label with new lines + colours properly when rendering a PUML dump | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #49311 | License | MIT | Doc PR | no In #49272 I removed the new lines instead of formatting them properly. The PUML format accept new lines in labels of transitions as long as the source file uses actual `\n` strings instead of line returns (like `PHP_EOL`). I propose a novel approach that will handle new lines with or without colours. Compare these outputs from plantuml.com, inputs are based on the [fixtures from Symfony](https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/Workflow/Tests/fixtures/puml/arrow/complex-state-machine-marking.puml): ### After #49272 New lines are ignored > ![image](https://user-images.githubusercontent.com/2071331/221030067-5d93b400-493d-4fb2-92d4-5c1490f6d1db.png) ([source](https://www.plantuml.com/plantuml/uml/TOx1IWCn48RlUOeXFHTfgxR8kfIjwCbB5Jo8I3OPsx2Jf2HPj8ZlRfAwKgJc5Bx_ctzc6QBmiJV4195xVpNwGziDYpeImeCsEy8RBJPU61OwRNSY_Q2aZVCA_ThrLgsSj-XXSd7QUTngsLaC0QP7GbeS4JuPfDS8sMtyeOgShofjTTI2wXf6YtaxFv-Srepm7QfipHQB-UgoM8UbnVY77qysb4fBVkji_9i-RNL4ziKEntB1uUYsWRPy-CcS3yC3L9pbmV6upkeLy3X9H2NoF5gZUldbrLkw06G-uVhEuxw-tuFiGtG6eXSsfBNE0eaM2MRLMRRhrDIMfePwB5Moh9Z-19ceGcQSBT6gtj0t)) ### Correct output from this PR With this patch → the second line is Grey and no tag is visible > ![image](https://user-images.githubusercontent.com/2071331/221025433-81033dfb-cc52-4087-bae8-7560a6c528ba.png) ([source](https://www.plantuml.com/plantuml/uml/TP9DImCn48Rl-HL3UYxILcsHTIbRqPENAdXGaMmojc7pKP8iMiJ_RfBjwg9rJ-6PP-Pz3xlqWRdGQaMOKlRjHSjtQJOaoA0GxgJUARoIREEO9hwHPiVY2_AqiawWMzlMY9Lr1XrCpeuxzrl96uFUmtGWnE20y44WVXNZpSPrfvHrHI6D39AfieJHObxFJoV7DSrSWo9PiyLYlZhFLXUQZN_uSBDIyMYUNriJVayVjZ8W-IHTMSee3BhrjARzYrFuMUwXe2GjZiTbKY-0Xaaa8fB7qHh5ypSlNcC3uAd2vOt3VNcx1zxwO3K4nuoFiTOK9yagdymVMx4Q5SmEGeoeSqIbMimPF6TF3uD4H2OpIfPeHFe7lW00)) --- ### Why close and open `<font>` tags? The output is broken if we use `\n` without taking into account the `<font>` tags → there is a second line but it is black and `</font>` is visible > ![image](https://user-images.githubusercontent.com/2071331/221025397-153357d1-6518-49db-8596-f8c680827afd.png) ([source](https://www.plantuml.com/plantuml/uml/TP5VI_Cm5CRlyoaEsVLusVRgYjGoEj4hRwRWXOgaoR4BpP-HfEWGlxj9QgN8x5NuFR_pd0FT-C1SwBKYJ2dxzgBbkpGj2J8eX3kf3mgl96iTqyHtqXnOV45EQ-i4kftjZTXQPz31ukoqSx-Nl3FeFImdGbmS43u8nAzcl6lTKAMiAqjfP91CLHNCYdMp_hyuhMdcEXJ9MXN5UdkUhM5fDlxWqybQnTASNriJVgSFUncGV9BXMCeeJ6uRQKF75q_vE3n2GKaQdC-hf5u03Oj8H2IFinsAvnzUliOBWASJBcyS7glR8_3U1wiXE6PyN6lDar6iGGMhyb_IgrZLvAfQzPYxUDwn_0uI4PciADcW4UbVVm40)) Commits ------- 361dce2 fix style of label containing new lines in PUML dump
2 parents e364f02 + 361dce2 commit 5bc4d55

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/Symfony/Component/Workflow/Dumper/PlantUmlDumper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,17 @@ private function getState(string $place, Definition $definition, Marking $markin
217217
private function getTransitionEscapedWithStyle(MetadataStoreInterface $workflowMetadata, Transition $transition, string $to): string
218218
{
219219
$to = $workflowMetadata->getMetadata('label', $transition) ?? $to;
220-
$to = str_replace("\n", ' ', $to);
220+
// Change new lines symbols to actual '\n' string,
221+
// PUML will render them as new lines
222+
$to = str_replace("\n", '\n', $to);
221223

222224
$color = $workflowMetadata->getMetadata('color', $transition) ?? null;
223225

224226
if (null !== $color) {
227+
// Close and open <font> before and after every '\n' string,
228+
// so that the style is applied properly on every line
229+
$to = str_replace('\n', sprintf('</font>\n<font color=%1$s>', $color), $to);
230+
225231
$to = sprintf(
226232
'<font color=%1$s>%2$s</font>',
227233
$color,

src/Symfony/Component/Workflow/Tests/fixtures/puml/arrow/complex-state-machine-marking.puml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ state "b"
1515
state "c" <<marked>>
1616
state "d"
1717
"a" --> "b": "t1"
18-
"d" -[#Red]-> "b": "<font color=Grey>My custom transition label 3</font>"
18+
"d" -[#Red]-> "b": "<font color=Grey>My custom transition</font>\n<font color=Grey>label 3</font>"
1919
"b" -[#Blue]-> "c": "t2"
2020
"b" --> "d": "t3"
2121
@enduml

src/Symfony/Component/Workflow/Tests/fixtures/puml/arrow/complex-state-machine-nomarking.puml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ state "b"
1515
state "c"
1616
state "d"
1717
"a" --> "b": "t1"
18-
"d" -[#Red]-> "b": "<font color=Grey>My custom transition label 3</font>"
18+
"d" -[#Red]-> "b": "<font color=Grey>My custom transition</font>\n<font color=Grey>label 3</font>"
1919
"b" -[#Blue]-> "c": "t2"
2020
"b" --> "d": "t3"
2121
@enduml

0 commit comments

Comments
 (0)
0