feat(docs): add update_paragraph_style to batch_update_doc operations
Enable paragraph-level styling (headings, alignment, spacing, indentation) within atomic batch operations, complementing the existing format_text support.
This commit is contained in:
@@ -13,6 +13,7 @@ from gdocs.docs_helpers import (
|
||||
create_insert_text_request,
|
||||
create_delete_range_request,
|
||||
create_format_text_request,
|
||||
create_update_paragraph_style_request,
|
||||
create_find_replace_request,
|
||||
create_insert_table_request,
|
||||
create_insert_page_break_request,
|
||||
@@ -211,6 +212,55 @@ class BatchOperationManager:
|
||||
|
||||
description = f"format text {op['start_index']}-{op['end_index']} ({', '.join(format_changes)})"
|
||||
|
||||
elif op_type == "update_paragraph_style":
|
||||
request = create_update_paragraph_style_request(
|
||||
op["start_index"],
|
||||
op["end_index"],
|
||||
op.get("heading_level"),
|
||||
op.get("alignment"),
|
||||
op.get("line_spacing"),
|
||||
op.get("indent_first_line"),
|
||||
op.get("indent_start"),
|
||||
op.get("indent_end"),
|
||||
op.get("space_above"),
|
||||
op.get("space_below"),
|
||||
)
|
||||
|
||||
if not request:
|
||||
raise ValueError("No paragraph style options provided")
|
||||
|
||||
style_changes = []
|
||||
for param, name in [
|
||||
("heading_level", "heading"),
|
||||
("alignment", "alignment"),
|
||||
("line_spacing", "line spacing"),
|
||||
("indent_first_line", "first line indent"),
|
||||
("indent_start", "start indent"),
|
||||
("indent_end", "end indent"),
|
||||
("space_above", "space above"),
|
||||
("space_below", "space below"),
|
||||
]:
|
||||
if op.get(param) is not None:
|
||||
value = (
|
||||
f"H{op[param]}"
|
||||
if param == "heading_level"
|
||||
else f"{op[param]}x"
|
||||
if param == "line_spacing"
|
||||
else f"{op[param]}pt"
|
||||
if param
|
||||
in (
|
||||
"indent_first_line",
|
||||
"indent_start",
|
||||
"indent_end",
|
||||
"space_above",
|
||||
"space_below",
|
||||
)
|
||||
else op[param]
|
||||
)
|
||||
style_changes.append(f"{name}: {value}")
|
||||
|
||||
description = f"paragraph style {op['start_index']}-{op['end_index']} ({', '.join(style_changes)})"
|
||||
|
||||
elif op_type == "insert_table":
|
||||
request = create_insert_table_request(
|
||||
op["index"], op["rows"], op["columns"]
|
||||
@@ -233,6 +283,7 @@ class BatchOperationManager:
|
||||
"delete_text",
|
||||
"replace_text",
|
||||
"format_text",
|
||||
"update_paragraph_style",
|
||||
"insert_table",
|
||||
"insert_page_break",
|
||||
"find_replace",
|
||||
@@ -318,6 +369,20 @@ class BatchOperationManager:
|
||||
],
|
||||
"description": "Apply formatting to text range",
|
||||
},
|
||||
"update_paragraph_style": {
|
||||
"required": ["start_index", "end_index"],
|
||||
"optional": [
|
||||
"heading_level",
|
||||
"alignment",
|
||||
"line_spacing",
|
||||
"indent_first_line",
|
||||
"indent_start",
|
||||
"indent_end",
|
||||
"space_above",
|
||||
"space_below",
|
||||
],
|
||||
"description": "Apply paragraph-level styling (headings, alignment, spacing, indentation)",
|
||||
},
|
||||
"insert_table": {
|
||||
"required": ["index", "rows", "columns"],
|
||||
"description": "Insert table at specified index",
|
||||
@@ -341,5 +406,12 @@ class BatchOperationManager:
|
||||
"bold": True,
|
||||
},
|
||||
{"type": "insert_table", "index": 20, "rows": 2, "columns": 3},
|
||||
{
|
||||
"type": "update_paragraph_style",
|
||||
"start_index": 1,
|
||||
"end_index": 20,
|
||||
"heading_level": 1,
|
||||
"alignment": "CENTER",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user