fixed linter
This commit is contained in:
parent
df3f03e669
commit
3ef87cd083
3 changed files with 38 additions and 6 deletions
|
|
@ -655,10 +655,12 @@ class RendererDocx(BaseRenderer):
|
|||
content = image_data.get("content", {})
|
||||
base64_data = ""
|
||||
alt_text = "Image"
|
||||
caption = ""
|
||||
|
||||
if isinstance(content, dict):
|
||||
base64_data = content.get("base64Data", "")
|
||||
alt_text = content.get("altText", "Image")
|
||||
caption = content.get("caption", "")
|
||||
elif isinstance(content, str):
|
||||
# Content might be base64 string directly (shouldn't happen, but handle it)
|
||||
self.logger.warning("Image content is a string, not a dict. This should not happen.")
|
||||
|
|
@ -669,6 +671,8 @@ class RendererDocx(BaseRenderer):
|
|||
base64_data = image_data.get("base64Data", "")
|
||||
if not alt_text or alt_text == "Image":
|
||||
alt_text = image_data.get("altText", "Image")
|
||||
if not caption:
|
||||
caption = image_data.get("caption", "")
|
||||
|
||||
# CRITICAL: Ensure we don't render base64 data as text
|
||||
# If base64_data looks like it might be rendered elsewhere, skip it
|
||||
|
|
@ -712,8 +716,26 @@ class RendererDocx(BaseRenderer):
|
|||
image_stream.seek(0)
|
||||
doc.add_picture(image_stream, width=Inches(6.0))
|
||||
|
||||
if alt_text and alt_text != "Image":
|
||||
caption_para = doc.add_paragraph(f"Figure: {alt_text}")
|
||||
# Use caption from section if available, otherwise use alt_text
|
||||
if caption:
|
||||
caption_text = caption
|
||||
elif alt_text and alt_text != "Image":
|
||||
# Only use alt_text if it doesn't look like a usageHint
|
||||
if "Render as visual element:" in alt_text:
|
||||
# Extract filename from usageHint if possible
|
||||
parts = alt_text.split("Render as visual element:")
|
||||
if len(parts) > 1:
|
||||
filename = parts[1].strip()
|
||||
caption_text = f"Figure: {filename}"
|
||||
else:
|
||||
caption_text = alt_text
|
||||
else:
|
||||
caption_text = f"Figure: {alt_text}"
|
||||
else:
|
||||
caption_text = None
|
||||
|
||||
if caption_text:
|
||||
caption_para = doc.add_paragraph(caption_text)
|
||||
caption_para.runs[0].italic = True
|
||||
except Exception as embedError:
|
||||
# Image decoding or embedding failed
|
||||
|
|
|
|||
|
|
@ -895,11 +895,21 @@ class RendererPdf(BaseRenderer):
|
|||
captionStyle.textColor = self._hexToColor(styles.get("paragraph", {}).get("color", "#666666"))
|
||||
elements.append(Paragraph(f"<i>{caption}</i>", captionStyle))
|
||||
elif alt_text and alt_text != "Image":
|
||||
# Use alt text as caption if no caption provided
|
||||
# Use alt text as caption if no caption provided, but avoid usageHint format
|
||||
if "Render as visual element:" in alt_text:
|
||||
# Extract filename from usageHint if possible
|
||||
parts = alt_text.split("Render as visual element:")
|
||||
if len(parts) > 1:
|
||||
filename = parts[1].strip()
|
||||
caption_text = f"Figure: {filename}"
|
||||
else:
|
||||
caption_text = alt_text
|
||||
else:
|
||||
caption_text = f"Figure: {alt_text}"
|
||||
captionStyle = self._createNormalStyle(styles)
|
||||
captionStyle.fontSize = 10
|
||||
captionStyle.textColor = self._hexToColor(styles.get("paragraph", {}).get("color", "#666666"))
|
||||
elements.append(Paragraph(f"<i>Figure: {alt_text}</i>", captionStyle))
|
||||
elements.append(Paragraph(f"<i>{caption_text}</i>", captionStyle))
|
||||
|
||||
return elements
|
||||
|
||||
|
|
|
|||
|
|
@ -628,7 +628,7 @@ class ContentGenerator:
|
|||
"base64Data": imageDoc.get("base64Data"),
|
||||
"altText": altText,
|
||||
"mimeType": mimeType,
|
||||
"caption": section.get("metadata", {}).get("caption")
|
||||
"caption": section.get("caption") or section.get("metadata", {}).get("caption")
|
||||
}]
|
||||
|
||||
logger.info(f"Successfully integrated image {imageRefId} for section {section.get('id')} (source={imageSource})")
|
||||
|
|
@ -702,7 +702,7 @@ class ContentGenerator:
|
|||
# Use image_prompt as alt text if generation_hint is generic
|
||||
altText = section.get("image_prompt", "Image")[:100] # Limit length
|
||||
|
||||
caption = section.get("metadata", {}).get("caption")
|
||||
caption = section.get("caption") or section.get("metadata", {}).get("caption")
|
||||
|
||||
section["elements"] = [{
|
||||
"url": f"data:image/png;base64,{base64Data}",
|
||||
|
|
|
|||
Loading…
Reference in a new issue