creating tables actually working reliably
This commit is contained in:
@@ -297,61 +297,3 @@ def validate_operation(operation: Dict[str, Any]) -> tuple[bool, str]:
|
||||
|
||||
return True, ""
|
||||
|
||||
def extract_document_text_simple(doc_data: Dict[str, Any]) -> str:
|
||||
"""
|
||||
Extract plain text from a Google Docs document structure.
|
||||
Simplified version that handles basic text extraction.
|
||||
|
||||
Args:
|
||||
doc_data: Document data from Google Docs API
|
||||
|
||||
Returns:
|
||||
Plain text content of the document
|
||||
"""
|
||||
def extract_from_elements(elements):
|
||||
text_parts = []
|
||||
for element in elements:
|
||||
if 'paragraph' in element:
|
||||
paragraph = element['paragraph']
|
||||
para_elements = paragraph.get('elements', [])
|
||||
for pe in para_elements:
|
||||
text_run = pe.get('textRun', {})
|
||||
if 'content' in text_run:
|
||||
text_parts.append(text_run['content'])
|
||||
elif 'table' in element:
|
||||
table = element['table']
|
||||
for row in table.get('tableRows', []):
|
||||
for cell in row.get('tableCells', []):
|
||||
cell_content = cell.get('content', [])
|
||||
text_parts.append(extract_from_elements(cell_content))
|
||||
return ''.join(text_parts)
|
||||
|
||||
# Extract from main document body
|
||||
body_elements = doc_data.get('body', {}).get('content', [])
|
||||
return extract_from_elements(body_elements)
|
||||
|
||||
def calculate_text_indices(text: str, target_text: str, occurrence: int = 1) -> tuple[int, int]:
|
||||
"""
|
||||
Calculate start and end indices for a text occurrence in a document.
|
||||
|
||||
Args:
|
||||
text: Full document text
|
||||
target_text: Text to find indices for
|
||||
occurrence: Which occurrence to find (1-based)
|
||||
|
||||
Returns:
|
||||
Tuple of (start_index, end_index) or (-1, -1) if not found
|
||||
"""
|
||||
if occurrence < 1:
|
||||
return -1, -1
|
||||
|
||||
start_pos = 0
|
||||
for i in range(occurrence):
|
||||
pos = text.find(target_text, start_pos)
|
||||
if pos == -1:
|
||||
return -1, -1
|
||||
start_pos = pos + 1
|
||||
if i == occurrence - 1: # Found the target occurrence
|
||||
return pos, pos + len(target_text)
|
||||
|
||||
return -1, -1
|
||||
Reference in New Issue
Block a user