revised ai core set ready for cross tests
This commit is contained in:
parent
1aecec9d61
commit
87dec2c4a2
1 changed files with 38 additions and 6 deletions
|
|
@ -481,12 +481,27 @@ class DocxRenderer(BaseRenderer):
|
|||
self._process_table_row(doc, line)
|
||||
|
||||
else:
|
||||
# Regular text - add to current paragraph
|
||||
# Regular text - finalize any open table first
|
||||
if hasattr(self, '_current_table') and self._current_table is not None:
|
||||
self._finalize_current_table(doc)
|
||||
|
||||
# Add to current paragraph
|
||||
current_paragraph.append(line)
|
||||
|
||||
# Flush any remaining paragraph
|
||||
if current_paragraph:
|
||||
self._add_paragraph_to_doc(doc, '\n'.join(current_paragraph))
|
||||
|
||||
# Finalize any open table
|
||||
self._finalize_current_table(doc)
|
||||
|
||||
def _finalize_current_table(self, doc):
|
||||
"""Finalize the current table if one exists."""
|
||||
if hasattr(self, '_current_table') and self._current_table is not None:
|
||||
# Apply final styling to the table
|
||||
self._style_table(self._current_table)
|
||||
# Clear the current table reference
|
||||
self._current_table = None
|
||||
|
||||
def _add_paragraph_to_doc(self, doc, text: str):
|
||||
"""Add a paragraph to the document with proper formatting."""
|
||||
|
|
@ -513,8 +528,21 @@ class DocxRenderer(BaseRenderer):
|
|||
if not line.strip():
|
||||
return
|
||||
|
||||
# Clean the line - remove bullet point markers and bold markers
|
||||
clean_line = line.strip()
|
||||
if clean_line.startswith('- **'):
|
||||
clean_line = clean_line[4:] # Remove "- **"
|
||||
elif clean_line.startswith('- '):
|
||||
clean_line = clean_line[2:] # Remove "- "
|
||||
elif clean_line.startswith('**'):
|
||||
clean_line = clean_line[2:] # Remove "**"
|
||||
|
||||
# Remove trailing ** if present
|
||||
if clean_line.endswith('**'):
|
||||
clean_line = clean_line[:-2]
|
||||
|
||||
# Split by pipe separator
|
||||
parts = [part.strip() for part in line.split('|')]
|
||||
parts = [part.strip() for part in clean_line.split('|')]
|
||||
|
||||
if len(parts) >= 2:
|
||||
# This is a table row - create a table if it doesn't exist
|
||||
|
|
@ -523,15 +551,19 @@ class DocxRenderer(BaseRenderer):
|
|||
self._current_table = doc.add_table(rows=1, cols=len(parts))
|
||||
self._current_table.style = 'Table Grid'
|
||||
|
||||
# Check if this looks like a header row (contains common header words)
|
||||
is_header = any(word.lower() in clean_line.lower() for word in ['name', 'quantity', 'part', 'number', 'description', 'tag', 'item', 'status'])
|
||||
|
||||
# Add header row
|
||||
for i, part in enumerate(parts):
|
||||
if i < len(self._current_table.rows[0].cells):
|
||||
cell = self._current_table.rows[0].cells[i]
|
||||
cell.text = part
|
||||
# Make header bold
|
||||
for paragraph in cell.paragraphs:
|
||||
for run in paragraph.runs:
|
||||
run.bold = True
|
||||
# Make header bold if it looks like a header
|
||||
if is_header:
|
||||
for paragraph in cell.paragraphs:
|
||||
for run in paragraph.runs:
|
||||
run.bold = True
|
||||
else:
|
||||
# Add data row to existing table
|
||||
row = self._current_table.add_row()
|
||||
|
|
|
|||
Loading…
Reference in a new issue