Add hyperlink support to modify_doc_text
This commit is contained in:
@@ -157,6 +157,7 @@ class ValidationManager:
|
||||
font_family: Optional[str] = None,
|
||||
text_color: Optional[str] = None,
|
||||
background_color: Optional[str] = None,
|
||||
link_url: Optional[str] = None,
|
||||
) -> Tuple[bool, str]:
|
||||
"""
|
||||
Validate text formatting parameters.
|
||||
@@ -169,6 +170,7 @@ class ValidationManager:
|
||||
font_family: Font family name
|
||||
text_color: Text color in "#RRGGBB" format
|
||||
background_color: Background color in "#RRGGBB" format
|
||||
link_url: Hyperlink URL (http/https)
|
||||
|
||||
Returns:
|
||||
Tuple of (is_valid, error_message)
|
||||
@@ -182,11 +184,12 @@ class ValidationManager:
|
||||
font_family,
|
||||
text_color,
|
||||
background_color,
|
||||
link_url,
|
||||
]
|
||||
if all(param is None for param in formatting_params):
|
||||
return (
|
||||
False,
|
||||
"At least one formatting parameter must be provided (bold, italic, underline, font_size, font_family, text_color, or background_color)",
|
||||
"At least one formatting parameter must be provided (bold, italic, underline, font_size, font_family, text_color, background_color, or link_url)",
|
||||
)
|
||||
|
||||
# Validate boolean parameters
|
||||
@@ -238,8 +241,27 @@ class ValidationManager:
|
||||
if not is_valid:
|
||||
return False, error_msg
|
||||
|
||||
is_valid, error_msg = self.validate_link_url(link_url)
|
||||
if not is_valid:
|
||||
return False, error_msg
|
||||
|
||||
return True, ""
|
||||
|
||||
def validate_link_url(self, link_url: Optional[str]) -> Tuple[bool, str]:
|
||||
"""Validate hyperlink URL parameters."""
|
||||
if link_url is None:
|
||||
return True, ""
|
||||
|
||||
if not isinstance(link_url, str):
|
||||
return False, f"link_url must be a string, got {type(link_url).__name__}"
|
||||
|
||||
if not link_url.strip():
|
||||
return False, "link_url cannot be empty"
|
||||
|
||||
if not (link_url.startswith("http://") or link_url.startswith("https://")):
|
||||
return False, "link_url must start with http:// or https://"
|
||||
|
||||
return True, ""
|
||||
def validate_color_param(
|
||||
self, color: Optional[str], param_name: str
|
||||
) -> Tuple[bool, str]:
|
||||
@@ -479,6 +501,7 @@ class ValidationManager:
|
||||
op.get("font_family"),
|
||||
op.get("text_color"),
|
||||
op.get("background_color"),
|
||||
op.get("link_url"),
|
||||
)
|
||||
if not is_valid:
|
||||
return False, f"Operation {i + 1} (format_text): {error_msg}"
|
||||
|
||||
Reference in New Issue
Block a user