Add hyperlink support to modify_doc_text

This commit is contained in:
Gigi Sayfan
2026-02-07 13:44:09 -08:00
parent 79a578eda9
commit 34957de2e4
6 changed files with 54 additions and 6 deletions

View File

@@ -46,6 +46,7 @@ def build_text_style(
font_family: str = None,
text_color: str = None,
background_color: str = None,
link_url: str = None,
) -> tuple[Dict[str, Any], list[str]]:
"""
Build text style object for Google Docs API requests.
@@ -58,6 +59,7 @@ def build_text_style(
font_family: Font family name
text_color: Text color as hex string "#RRGGBB"
background_color: Background (highlight) color as hex string "#RRGGBB"
link_url: Hyperlink URL (http/https)
Returns:
Tuple of (text_style_dict, list_of_field_names)
@@ -95,6 +97,10 @@ def build_text_style(
text_style["backgroundColor"] = {"color": {"rgbColor": rgb}}
fields.append("backgroundColor")
if link_url is not None:
text_style["link"] = {"url": link_url}
fields.append("link")
return text_style, fields
@@ -162,6 +168,7 @@ def create_format_text_request(
font_family: str = None,
text_color: str = None,
background_color: str = None,
link_url: str = None,
) -> Optional[Dict[str, Any]]:
"""
Create an updateTextStyle request for Google Docs API.
@@ -176,12 +183,20 @@ def create_format_text_request(
font_family: Font family name
text_color: Text color as hex string "#RRGGBB"
background_color: Background (highlight) color as hex string "#RRGGBB"
link_url: Hyperlink URL (http/https)
Returns:
Dictionary representing the updateTextStyle request, or None if no styles provided
"""
text_style, fields = build_text_style(
bold, italic, underline, font_size, font_family, text_color, background_color
bold,
italic,
underline,
font_size,
font_family,
text_color,
background_color,
link_url,
)
if not text_style: