From 4e4aefff3eacab511cacbaf68c8ce2a3181a5087 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 16 Dec 2025 17:38:23 +0000 Subject: [PATCH] Fix Docs `utils.plotting.Colors()` previews (#22973) --- docs/build_reference.py | 7 ++++++- ultralytics/utils/plotting.py | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/docs/build_reference.py b/docs/build_reference.py index f520d294..48b6a89f 100644 --- a/docs/build_reference.py +++ b/docs/build_reference.py @@ -409,9 +409,14 @@ SECTION_ALIASES = { def _normalize_text(text: str) -> str: - """Collapse single newlines within paragraphs while preserving paragraph breaks.""" + """Normalize text while preserving markdown structures like tables, admonitions, and code blocks.""" if not text: return "" + # Check if text contains markdown structures that need line preservation + if any(marker in text for marker in ("|", "!!!", "```", "\n#", "\n- ", "\n* ", "\n1. ", "\n ")): + # Preserve markdown formatting - just strip trailing whitespace from lines + return "\n".join(line.rstrip() for line in text.splitlines()).strip() + # Simple text - collapse single newlines within paragraphs paragraphs: list[str] = [] current: list[str] = [] for line in text.splitlines(): diff --git a/ultralytics/utils/plotting.py b/ultralytics/utils/plotting.py index a564b069..8186ae04 100644 --- a/ultralytics/utils/plotting.py +++ b/ultralytics/utils/plotting.py @@ -24,17 +24,6 @@ class Colors: This class provides methods to work with the Ultralytics color palette, including converting hex color codes to RGB values and accessing predefined color schemes for object detection and pose estimation. - Attributes: - palette (list[tuple]): List of RGB color tuples for general use. - n (int): The number of colors in the palette. - pose_palette (np.ndarray): A specific color palette array for pose estimation with dtype np.uint8. - - Examples: - >>> from ultralytics.utils.plotting import Colors - >>> colors = Colors() - >>> colors(5, True) # Returns BGR format: (221, 111, 255) - >>> colors(5, False) # Returns RGB format: (255, 111, 221) - ## Ultralytics Color Palette | Index | Color | HEX | RGB | @@ -89,6 +78,17 @@ class Colors: For Ultralytics brand colors see [https://www.ultralytics.com/brand](https://www.ultralytics.com/brand). Please use the official Ultralytics colors for all marketing materials. + + Attributes: + palette (list[tuple]): List of RGB color tuples for general use. + n (int): The number of colors in the palette. + pose_palette (np.ndarray): A specific color palette array for pose estimation with dtype np.uint8. + + Examples: + >>> from ultralytics.utils.plotting import Colors + >>> colors = Colors() + >>> colors(5, True) # Returns BGR format: (221, 111, 255) + >>> colors(5, False) # Returns RGB format: (255, 111, 221) """ def __init__(self):