Repository: pylint-dev/pylint

Issue:
pyreverse: colored classes and packages in HTML generated diagrams
### Current problem

In pyreverse, assuming we use `--colorized` and increase `--max-color-depth`, the .png generated diagrams use different colors. But the .html generated diagrams *do not* use multiple colors, they only use a single color.

### Desired solution

When using use `--colorized` and increasing `--max-color-depth` with `--output html`, the generated `packages.html` and `classes.html` should have different colors.

More precisely,  the `node` elements in CSS should have different `stroke` and `fill` colors, according to the `--max-color-depth` and the `--color-palette`.

### Additional context

_No response_


Discussion:
The HTML files are generated via `MermaidJS`, and the `MermaidJSPrinter` printer implementation currently does not support the colored output.  
Looking at [the documentation](https://mermaid.js.org/syntax/classDiagram.html#styling-a-node) it should be possible to also implement colored output for Mermaid and therefore also for HTML. 



Patch:
diff --git a/doc/whatsnew/fragments/10242.feature b/doc/whatsnew/fragments/10242.feature
new file mode 100644
index 0000000000..9be0bd25c7
--- /dev/null
+++ b/doc/whatsnew/fragments/10242.feature
@@ -0,0 +1,3 @@
+`pyreverse`: add support for colorized output when using output format `mmd` (MermaidJS) and `html`.
+
+Closes #10242
diff --git a/pylint/pyreverse/mermaidjs_printer.py b/pylint/pyreverse/mermaidjs_printer.py
index 24fa927761..22a8f768b1 100644
--- a/pylint/pyreverse/mermaidjs_printer.py
+++ b/pylint/pyreverse/mermaidjs_printer.py
@@ -64,6 +64,9 @@ def emit_node(
             self.emit(line)
         self._dec_indent()
         self.emit("}")
+        # apply style for colored output
+        if properties.color and properties.color != self.DEFAULT_COLOR:
+            self.emit(f"style {name} fill:{properties.color}")
 
     def emit_edge(
         self,


Test patch:
diff --git a/tests/pyreverse/functional/class_diagrams/colorized_output/colorized.mmd b/tests/pyreverse/functional/class_diagrams/colorized_output/colorized.mmd
new file mode 100644
index 0000000000..bf90bd708d
--- /dev/null
+++ b/tests/pyreverse/functional/class_diagrams/colorized_output/colorized.mmd
@@ -0,0 +1,46 @@
+classDiagram
+  class CheckerCollector {
+    checker1
+    checker2
+    checker3
+  }
+  style CheckerCollector fill:#77AADD
+  class ElseifUsedChecker {
+    msgs : dict
+    name : str
+    leave_module(_: nodes.Module) None
+    process_tokens(tokens: list[TokenInfo]) None
+    visit_if(node: nodes.If) None
+  }
+  style ElseifUsedChecker fill:#99DDFF
+  class ExceptionsChecker {
+    msgs : dict
+    name : str
+    options : tuple
+    open() None
+    visit_binop(node: nodes.BinOp) None
+    visit_compare(node: nodes.Compare) None
+    visit_raise(node: nodes.Raise) None
+    visit_try(node: nodes.Try) None
+    visit_trystar(node: nodes.TryStar) None
+  }
+  style ExceptionsChecker fill:#44BB99
+  class StdlibChecker {
+    msgs : dict[str, MessageDefinitionTuple]
+    name : str
+    deprecated_arguments(method: str) tuple[tuple[int | None, str], ...]
+    deprecated_attributes() Iterable[str]
+    deprecated_classes(module: str) Iterable[str]
+    deprecated_decorators() Iterable[str]
+    deprecated_methods() set[str]
+    visit_boolop(node: nodes.BoolOp) None
+    visit_call(node: nodes.Call) None
+    visit_functiondef(node: nodes.FunctionDef) None
+    visit_if(node: nodes.If) None
+    visit_ifexp(node: nodes.IfExp) None
+    visit_unaryop(node: nodes.UnaryOp) None
+  }
+  style StdlibChecker fill:#44BB99
+  ExceptionsChecker --* CheckerCollector : checker1
+  StdlibChecker --* CheckerCollector : checker3
+  ElseifUsedChecker --* CheckerCollector : checker2
diff --git a/tests/pyreverse/functional/class_diagrams/colorized_output/colorized.rc b/tests/pyreverse/functional/class_diagrams/colorized_output/colorized.rc
index 1d0560a4d2..0796a1b611 100644
--- a/tests/pyreverse/functional/class_diagrams/colorized_output/colorized.rc
+++ b/tests/pyreverse/functional/class_diagrams/colorized_output/colorized.rc
@@ -1,3 +1,3 @@
 [testoptions]
-output_formats=puml
+output_formats=puml,mmd
 command_line_args=-S --colorized --max-color-depth=2