@@ -367,6 +367,7 @@ async def modify_doc_text(
367367 font_family : str = None ,
368368 text_color : str = None ,
369369 background_color : str = None ,
370+ link_url : str = None ,
370371) -> str :
371372 """
372373 Modifies text in a Google Doc - can insert/replace text and/or apply formatting in a single operation.
@@ -384,13 +385,14 @@ async def modify_doc_text(
384385 font_family: Font family name (e.g., "Arial", "Times New Roman")
385386 text_color: Foreground text color (#RRGGBB)
386387 background_color: Background/highlight color (#RRGGBB)
388+ link_url: Hyperlink URL (http/https)
387389
388390 Returns:
389391 str: Confirmation message with operation details
390392 """
391393 logger .info (
392394 f"[modify_doc_text] Doc={ document_id } , start={ start_index } , end={ end_index } , text={ text is not None } , "
393- f"formatting={ any ([bold , italic , underline , font_size , font_family , text_color , background_color ])} "
395+ f"formatting={ any (p is not None for p in [bold , italic , underline , font_size , font_family , text_color , background_color , link_url ])} "
394396 )
395397
396398 # Input validation
@@ -401,31 +403,21 @@ async def modify_doc_text(
401403 return f"Error: { error_msg } "
402404
403405 # Validate that we have something to do
404- if text is None and not any (
405- [
406- bold is not None ,
407- italic is not None ,
408- underline is not None ,
409- font_size ,
410- font_family ,
411- text_color ,
412- background_color ,
413- ]
414- ):
415- return "Error: Must provide either 'text' to insert/replace, or formatting parameters (bold, italic, underline, font_size, font_family, text_color, background_color)."
406+ formatting_params = [
407+ bold ,
408+ italic ,
409+ underline ,
410+ font_size ,
411+ font_family ,
412+ text_color ,
413+ background_color ,
414+ link_url ,
415+ ]
416+ if text is None and not any ( p is not None for p in formatting_params ):
417+ return "Error: Must provide either 'text' to insert/replace, or formatting parameters (bold, italic, underline, font_size, font_family, text_color, background_color, link_url )."
416418
417419 # Validate text formatting params if provided
418- if any (
419- [
420- bold is not None ,
421- italic is not None ,
422- underline is not None ,
423- font_size ,
424- font_family ,
425- text_color ,
426- background_color ,
427- ]
428- ):
420+ if any (p is not None for p in formatting_params ):
429421 is_valid , error_msg = validator .validate_text_formatting_params (
430422 bold ,
431423 italic ,
@@ -434,6 +426,7 @@ async def modify_doc_text(
434426 font_family ,
435427 text_color ,
436428 background_color ,
429+ link_url ,
437430 )
438431 if not is_valid :
439432 return f"Error: { error_msg } "
@@ -482,17 +475,7 @@ async def modify_doc_text(
482475 operations .append (f"Inserted text at index { start_index } " )
483476
484477 # Handle formatting
485- if any (
486- [
487- bold is not None ,
488- italic is not None ,
489- underline is not None ,
490- font_size ,
491- font_family ,
492- text_color ,
493- background_color ,
494- ]
495- ):
478+ if any (p is not None for p in formatting_params ):
496479 # Adjust range for formatting based on text operations
497480 format_start = start_index
498481 format_end = end_index
@@ -524,24 +507,24 @@ async def modify_doc_text(
524507 font_family ,
525508 text_color ,
526509 background_color ,
510+ link_url ,
527511 )
528512 )
529513
530- format_details = []
531- if bold is not None :
532- format_details .append (f"bold={ bold } " )
533- if italic is not None :
534- format_details .append (f"italic={ italic } " )
535- if underline is not None :
536- format_details .append (f"underline={ underline } " )
537- if font_size :
538- format_details .append (f"font_size={ font_size } " )
539- if font_family :
540- format_details .append (f"font_family={ font_family } " )
541- if text_color :
542- format_details .append (f"text_color={ text_color } " )
543- if background_color :
544- format_details .append (f"background_color={ background_color } " )
514+ format_details = [
515+ f"{ name } ={ value } "
516+ for name , value in [
517+ ("bold" , bold ),
518+ ("italic" , italic ),
519+ ("underline" , underline ),
520+ ("font_size" , font_size ),
521+ ("font_family" , font_family ),
522+ ("text_color" , text_color ),
523+ ("background_color" , background_color ),
524+ ("link_url" , link_url ),
525+ ]
526+ if value is not None
527+ ]
545528
546529 operations .append (
547530 f"Applied formatting ({ ', ' .join (format_details )} ) to range { format_start } -{ format_end } "
0 commit comments